diff --git a/cognee/api/v1/search/search.py b/cognee/api/v1/search/search.py index 32035e612..880a57b99 100644 --- a/cognee/api/v1/search/search.py +++ b/cognee/api/v1/search/search.py @@ -177,10 +177,9 @@ async def search( raise DatasetNotFoundError(message="No datasets found.") graph_engine = await get_graph_engine() - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - if nodes_count == 0 or edges_count == 0: + if nodes_count == 0: raise SearchOnEmptyGraphError( message="Knowledge graph is empty, please ensure data is added and cognified." ) diff --git a/cognee/infrastructure/databases/graph/graph_db_interface.py b/cognee/infrastructure/databases/graph/graph_db_interface.py index abfdff784..a4542cefe 100644 --- a/cognee/infrastructure/databases/graph/graph_db_interface.py +++ b/cognee/infrastructure/databases/graph/graph_db_interface.py @@ -163,10 +163,6 @@ class GraphDBInterface(ABC): async def count_nodes(self) -> int: raise NotImplementedError - @abstractmethod - async def count_edges(self) -> int: - raise NotImplementedError - @abstractmethod async def query(self, query: str, params: dict) -> List[Any]: """ diff --git a/cognee/infrastructure/databases/graph/kuzu/adapter.py b/cognee/infrastructure/databases/graph/kuzu/adapter.py index a31726c9a..04c163efa 100644 --- a/cognee/infrastructure/databases/graph/kuzu/adapter.py +++ b/cognee/infrastructure/databases/graph/kuzu/adapter.py @@ -185,14 +185,6 @@ class KuzuAdapter(GraphDBInterface): except FileNotFoundError: logger.warning(f"Kuzu S3 storage file not found: {self.db_path}") - async def count_edges(self) -> int: - query = """ - MATCH ()-[r]->() - RETURN COUNT(r); - """ - query_result = await self.query(query) - return query_result[0][0] - async def count_nodes(self) -> int: query = """ MATCH (n) diff --git a/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py b/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py index a61ab6f0b..ac19069f4 100644 --- a/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +++ b/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py @@ -87,14 +87,6 @@ class Neo4jAdapter(GraphDBInterface): async with self.driver.session(database=self.graph_database_name) as session: yield session - async def count_edges(self) -> int: - query = """ - MATCH ()-[r]->() - RETURN COUNT(r) as total_edges; - """ - query_result = await self.query(query) - return query_result[0]["total_edges"] - async def count_nodes(self) -> int: query = """ MATCH (n) diff --git a/cognee/tests/test_kuzu.py b/cognee/tests/test_kuzu.py index e39edd06a..c07a51104 100644 --- a/cognee/tests/test_kuzu.py +++ b/cognee/tests/test_kuzu.py @@ -51,26 +51,21 @@ async def main(): graph_engine = await get_graph_engine() - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert edges_count == 0 and nodes_count == 0, "Kuzu graph database is not empty" + assert nodes_count == 0, "Kuzu graph database is not empty" await cognee.add([explanation_file_path_quantum], dataset_name) - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert edges_count == 0 and nodes_count == 0, ( - "Kuzu graph database should be empty before cognify" - ) + assert nodes_count == 0, "Kuzu graph database should be empty before cognify" await cognee.cognify([dataset_name]) - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert edges_count != 0 and nodes_count != 0, "Kuzu graph database should not be empty" + assert nodes_count != 0, "Kuzu graph database should not be empty" from cognee.infrastructure.databases.vector import get_vector_engine @@ -136,10 +131,9 @@ async def main(): await cognee.prune.prune_system(metadata=True) - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert edges_count == 0 and nodes_count == 0, "Kuzu graph database is not empty" + assert nodes_count == 0, "Kuzu graph database is not empty" finally: # Ensure cleanup even if tests fail diff --git a/cognee/tests/test_neo4j.py b/cognee/tests/test_neo4j.py index 11f6156bd..6f1fcf975 100644 --- a/cognee/tests/test_neo4j.py +++ b/cognee/tests/test_neo4j.py @@ -39,10 +39,9 @@ async def main(): graph_engine = await get_graph_engine() - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert edges_count == 0 and nodes_count == 0, "Graph has to be empty" + assert nodes_count == 0, "Graph has to be empty" await cognee.add([explanation_file_path_nlp], dataset_name) @@ -51,18 +50,15 @@ async def main(): ) await cognee.add([explanation_file_path_quantum], dataset_name) - - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert edges_count == 0 and nodes_count == 0, "Graph has to be empty before cognify" + assert nodes_count == 0, "Graph has to be empty before cognify" await cognee.cognify([dataset_name]) - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert edges_count != 0 and nodes_count != 0, "Graph shouldn't be empty" + assert nodes_count != 0, "Graph shouldn't be empty" from cognee.infrastructure.databases.vector import get_vector_engine @@ -136,9 +132,8 @@ async def main(): assert not os.path.isdir(data_root_directory), "Local data files are not deleted" await cognee.prune.prune_system(metadata=True) - edges_count = await graph_engine.count_edges() nodes_count = await graph_engine.count_nodes() - assert nodes_count == 0 and edges_count == 0, "Neo4j graph database is not empty" + assert nodes_count == 0, "Neo4j graph database is not empty" if __name__ == "__main__": diff --git a/examples/python/dynamic_steps_example.py b/examples/python/dynamic_steps_example.py index bce2ea8be..5ff68cecc 100644 --- a/examples/python/dynamic_steps_example.py +++ b/examples/python/dynamic_steps_example.py @@ -199,7 +199,7 @@ if __name__ == "__main__": "prune_data": rebuild_kg, "prune_system": rebuild_kg, "add_text": rebuild_kg, - "cognify": rebuild_kg, + "cognify": False, "graph_metrics": rebuild_kg, "retriever": retrieve, }