From 5378c4918131ae2410840fe44e6290081be303b5 Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:29:59 +0200 Subject: [PATCH] urgent fix --- cognee/api/v1/cognify/cognify.py | 18 ++++++++++++++++++ .../databases/graph/get_graph_client.py | 1 + .../databases/graph/networkx/adapter.py | 7 ++++--- .../modules/cognify/graph/add_document_node.py | 4 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cognee/api/v1/cognify/cognify.py b/cognee/api/v1/cognify/cognify.py index 3cbc744c3..32fcd9285 100644 --- a/cognee/api/v1/cognify/cognify.py +++ b/cognee/api/v1/cognify/cognify.py @@ -166,3 +166,21 @@ async def process_text(chunk_collection: str, chunk_id: str, input_text: str, fi send_telemetry("cognee.cognify") print(f"Chunk ({chunk_id}) cognified.") + + +if __name__ == "__main__": + + async def test(): + + from cognee.api.v1.add import add + + await add(["A large language model (LLM) is a language model notable for its ability to achieve general-purpose language generation and other natural language processing tasks such as classification"], "test") + + graph = await cognify() + + from cognee.utils import render_graph + + await render_graph(graph, include_color=True, include_nodes=True, include_size=True) + + import asyncio + asyncio.run(test()) diff --git a/cognee/infrastructure/databases/graph/get_graph_client.py b/cognee/infrastructure/databases/graph/get_graph_client.py index 25ffa6db9..1a906927e 100644 --- a/cognee/infrastructure/databases/graph/get_graph_client.py +++ b/cognee/infrastructure/databases/graph/get_graph_client.py @@ -28,6 +28,7 @@ async def get_graph_client(graph_type: GraphDBType, graph_file_name: str = None) graph_client = NetworkXAdapter(filename = graph_file_path) + if (graph_client.graph is None): await graph_client.load_graph_from_file() diff --git a/cognee/infrastructure/databases/graph/networkx/adapter.py b/cognee/infrastructure/databases/graph/networkx/adapter.py index e4abb82de..fc01795d5 100644 --- a/cognee/infrastructure/databases/graph/networkx/adapter.py +++ b/cognee/infrastructure/databases/graph/networkx/adapter.py @@ -12,7 +12,8 @@ from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInte logger = logging.getLogger("NetworkXAdapter") class NetworkXAdapter(GraphDBInterface): - _instance = None # Class variable to store the singleton instance + _instance = None + graph = None # Class variable to store the singleton instance def __new__(cls, filename): if cls._instance is None: @@ -23,8 +24,7 @@ class NetworkXAdapter(GraphDBInterface): def __init__(self, filename = "cognee_graph.pkl"): self.filename = filename - async def graph(self): - return self.graph + async def add_node( self, @@ -95,6 +95,7 @@ class NetworkXAdapter(GraphDBInterface): async def extract_node(self, node_id: str) -> dict: if self.graph.has_node(node_id): + return self.graph.nodes[node_id] return None diff --git a/cognee/modules/cognify/graph/add_document_node.py b/cognee/modules/cognify/graph/add_document_node.py index e1a6f7d52..1e93ae60a 100644 --- a/cognee/modules/cognify/graph/add_document_node.py +++ b/cognee/modules/cognify/graph/add_document_node.py @@ -4,6 +4,10 @@ from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInte async def add_document_node(graph_client: GraphDBInterface, parent_node_id, document_metadata): document_id = f"DOCUMENT__{document_metadata['id']}" + + + + document = await graph_client.extract_node(document_id) if not document: