Merge pull request #87 from topoteretes/urgent_fix
Fix networkx graph bug
This commit is contained in:
commit
c1c253491c
4 changed files with 27 additions and 3 deletions
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue