From 5b29e760f0ce3caf023428bda891ec26f3902e00 Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 6 Mar 2025 14:29:48 +0800 Subject: [PATCH] Add dynamic parameter handling for storage --- lightrag/kg/networkx_impl.py | 1 - lightrag/lightrag.py | 24 +++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lightrag/kg/networkx_impl.py b/lightrag/kg/networkx_impl.py index 8a2789ca..1cfaaacd 100644 --- a/lightrag/kg/networkx_impl.py +++ b/lightrag/kg/networkx_impl.py @@ -247,7 +247,6 @@ class NetworkXStorage(BaseGraphStorage): 3. Followed by nodes directly connected to the matching nodes 4. Finally, the degree of the nodes - Args: node_label: Label of the starting node max_depth: Maximum depth of the subgraph diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 534e5536..f48982ba 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -515,18 +515,28 @@ class LightRAG: Args: node_label (str): Label to get knowledge graph for max_depth (int): Maximum depth of graph - search_mode (str, optional): Search mode, either "exact" or "inclusive". Defaults to "exact". min_degree (int, optional): Minimum degree of nodes to include. Defaults to 0. + inclusive (bool, optional): Whether to use inclusive search mode. Defaults to False. Returns: KnowledgeGraph: Knowledge graph containing nodes and edges """ - return await self.chunk_entity_relation_graph.get_knowledge_graph( - node_label=node_label, - max_depth=max_depth, - min_degree=min_degree, - inclusive=inclusive, - ) + # get params supported by get_knowledge_graph of specified storage + import inspect + storage_params = inspect.signature(self.chunk_entity_relation_graph.get_knowledge_graph).parameters + + kwargs = { + 'node_label': node_label, + 'max_depth': max_depth + } + + if 'min_degree' in storage_params and min_degree > 0: + kwargs['min_degree'] = min_degree + + if 'inclusive' in storage_params: + kwargs['inclusive'] = inclusive + + return await self.chunk_entity_relation_graph.get_knowledge_graph(**kwargs) def _get_storage_class(self, storage_name: str) -> Callable[..., Any]: import_path = STORAGES[storage_name]