Remove NetworkX from cognee core.
This commit is contained in:
parent
216ffd2706
commit
81a17580a6
9 changed files with 39 additions and 1044 deletions
|
|
@ -132,7 +132,7 @@ async def add(
|
||||||
- DEFAULT_USER_EMAIL: Custom default user email
|
- DEFAULT_USER_EMAIL: Custom default user email
|
||||||
- DEFAULT_USER_PASSWORD: Custom default user password
|
- DEFAULT_USER_PASSWORD: Custom default user password
|
||||||
- VECTOR_DB_PROVIDER: "lancedb" (default), "chromadb", "pgvector"
|
- VECTOR_DB_PROVIDER: "lancedb" (default), "chromadb", "pgvector"
|
||||||
- GRAPH_DATABASE_PROVIDER: "kuzu" (default), "neo4j", "networkx"
|
- GRAPH_DATABASE_PROVIDER: "kuzu" (default), "neo4j"
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
FileNotFoundError: If specified file paths don't exist
|
FileNotFoundError: If specified file paths don't exist
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,6 @@ async def get_graph_engine() -> GraphDBInterface:
|
||||||
if hasattr(graph_client, "initialize"):
|
if hasattr(graph_client, "initialize"):
|
||||||
await graph_client.initialize()
|
await graph_client.initialize()
|
||||||
|
|
||||||
# Handle loading of graph for NetworkX
|
|
||||||
if config["graph_database_provider"].lower() == "networkx" and graph_client.graph is None:
|
|
||||||
await graph_client.load_graph_from_file()
|
|
||||||
|
|
||||||
return graph_client
|
return graph_client
|
||||||
|
|
||||||
|
|
@ -181,8 +178,7 @@ def create_graph_engine(
|
||||||
graph_id=graph_identifier,
|
graph_id=graph_identifier,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .networkx.adapter import NetworkXAdapter
|
raise EnvironmentError(
|
||||||
|
f"Unsupported graph database provider: {graph_database_provider}. "
|
||||||
graph_client = NetworkXAdapter(filename=graph_file_path)
|
f"Supported providers are: {', '.join(list(supported_databases.keys()) + ['neo4j', 'falkordb', 'kuzu', 'kuzu-remote', 'memgraph', 'neptune', 'neptune_analytics'])}"
|
||||||
|
)
|
||||||
return graph_client
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,5 @@
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
from cognee.infrastructure.databases.graph import get_graph_engine
|
from cognee.infrastructure.databases.graph import get_graph_engine
|
||||||
from cognee.infrastructure.databases.graph.networkx.adapter import NetworkXAdapter
|
|
||||||
from cognee.modules.retrieval.base_retriever import BaseRetriever
|
from cognee.modules.retrieval.base_retriever import BaseRetriever
|
||||||
from cognee.modules.retrieval.utils.completion import generate_completion
|
from cognee.modules.retrieval.utils.completion import generate_completion
|
||||||
from cognee.modules.retrieval.exceptions import SearchTypeNotSupported, CypherSearchError
|
from cognee.modules.retrieval.exceptions import SearchTypeNotSupported, CypherSearchError
|
||||||
|
|
@ -31,8 +30,7 @@ class CypherSearchRetriever(BaseRetriever):
|
||||||
"""
|
"""
|
||||||
Retrieves relevant context using a cypher query.
|
Retrieves relevant context using a cypher query.
|
||||||
|
|
||||||
If the graph engine is an instance of NetworkXAdapter, raises SearchTypeNotSupported. If
|
If any error occurs during execution, logs the error and raises CypherSearchError.
|
||||||
any error occurs during execution, logs the error and raises CypherSearchError.
|
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
-----------
|
-----------
|
||||||
|
|
@ -46,12 +44,6 @@ class CypherSearchRetriever(BaseRetriever):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
graph_engine = await get_graph_engine()
|
graph_engine = await get_graph_engine()
|
||||||
|
|
||||||
if isinstance(graph_engine, NetworkXAdapter):
|
|
||||||
raise SearchTypeNotSupported(
|
|
||||||
"CYPHER search type not supported for NetworkXAdapter."
|
|
||||||
)
|
|
||||||
|
|
||||||
result = await graph_engine.query(query)
|
result = await graph_engine.query(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to execture cypher search retrieval: %s", str(e))
|
logger.error("Failed to execture cypher search retrieval: %s", str(e))
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
from cognee.shared.logging_utils import get_logger
|
from cognee.shared.logging_utils import get_logger
|
||||||
from cognee.infrastructure.databases.graph import get_graph_engine
|
from cognee.infrastructure.databases.graph import get_graph_engine
|
||||||
from cognee.infrastructure.databases.graph.networkx.adapter import NetworkXAdapter
|
from cognee.infrastructure.llm.get_llm_client import get_llm_client
|
||||||
from cognee.infrastructure.llm.LLMGateway import LLMGateway
|
from cognee.infrastructure.llm.prompts import render_prompt
|
||||||
from cognee.modules.retrieval.base_retriever import BaseRetriever
|
from cognee.modules.retrieval.base_retriever import BaseRetriever
|
||||||
from cognee.modules.retrieval.exceptions import SearchTypeNotSupported
|
from cognee.modules.retrieval.exceptions import SearchTypeNotSupported
|
||||||
from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInterface
|
from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInterface
|
||||||
|
|
@ -122,10 +122,6 @@ class NaturalLanguageRetriever(BaseRetriever):
|
||||||
query.
|
query.
|
||||||
"""
|
"""
|
||||||
graph_engine = await get_graph_engine()
|
graph_engine = await get_graph_engine()
|
||||||
|
|
||||||
if isinstance(graph_engine, (NetworkXAdapter)):
|
|
||||||
raise SearchTypeNotSupported("Natural language search type not supported.")
|
|
||||||
|
|
||||||
return await self._execute_cypher_query(query, graph_engine)
|
return await self._execute_cypher_query(query, graph_engine)
|
||||||
|
|
||||||
async def get_completion(self, query: str, context: Optional[Any] = None) -> Any:
|
async def get_completion(self, query: str, context: Optional[Any] = None) -> Any:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import networkx
|
|
||||||
|
|
||||||
from cognee.shared.logging_utils import get_logger
|
from cognee.shared.logging_utils import get_logger
|
||||||
from cognee.infrastructure.files.storage.LocalFileStorage import LocalFileStorage
|
from cognee.infrastructure.files.storage.LocalFileStorage import LocalFileStorage
|
||||||
|
|
@ -8,7 +7,37 @@ from cognee.infrastructure.files.storage.LocalFileStorage import LocalFileStorag
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
|
||||||
|
|
||||||
|
def _import_networkx():
|
||||||
|
"""Dynamically import networkx with helpful error message if not available."""
|
||||||
|
try:
|
||||||
|
import networkx
|
||||||
|
return networkx
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError(
|
||||||
|
"NetworkX is required for graph visualization but is not installed. "
|
||||||
|
"Please install it with: pip install 'cognee[visualization]' or pip install networkx"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def cognee_network_visualization(graph_data, destination_file_path: str = None):
|
async def cognee_network_visualization(graph_data, destination_file_path: str = None):
|
||||||
|
"""
|
||||||
|
Generate an interactive HTML visualization of the graph data.
|
||||||
|
|
||||||
|
This function requires NetworkX to be installed. If you don't have NetworkX installed,
|
||||||
|
you can install it with: pip install 'cognee[visualization]' or pip install networkx
|
||||||
|
|
||||||
|
Args:
|
||||||
|
graph_data: Tuple of (nodes_data, edges_data)
|
||||||
|
destination_file_path: Optional path to save the HTML file
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Path to the generated HTML file
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ImportError: If NetworkX is not installed
|
||||||
|
"""
|
||||||
|
networkx = _import_networkx()
|
||||||
|
|
||||||
nodes_data, edges_data = graph_data
|
nodes_data, edges_data = graph_data
|
||||||
|
|
||||||
G = networkx.DiGraph()
|
G = networkx.DiGraph()
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
import networkx as nx
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import http.server
|
import http.server
|
||||||
import socketserver
|
import socketserver
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ dependencies = [
|
||||||
"pypdf>=4.1.0,<6.0.0",
|
"pypdf>=4.1.0,<6.0.0",
|
||||||
"jinja2>=3.1.3,<4",
|
"jinja2>=3.1.3,<4",
|
||||||
"matplotlib>=3.8.3,<4",
|
"matplotlib>=3.8.3,<4",
|
||||||
"networkx>=3.4.2,<4",
|
|
||||||
"lancedb>=0.24.0,<1.0.0",
|
"lancedb>=0.24.0,<1.0.0",
|
||||||
"alembic>=1.13.3,<2",
|
"alembic>=1.13.3,<2",
|
||||||
"pre-commit>=4.0.1,<5",
|
"pre-commit>=4.0.1,<5",
|
||||||
|
|
@ -120,6 +119,7 @@ gui = [
|
||||||
"qasync>=0.27.1,<0.28",
|
"qasync>=0.27.1,<0.28",
|
||||||
]
|
]
|
||||||
graphiti = ["graphiti-core>=0.7.0,<0.8"]
|
graphiti = ["graphiti-core>=0.7.0,<0.8"]
|
||||||
|
visualization = ["networkx>=3.4.2,<4"]
|
||||||
# Note: New s3fs and boto3 versions don't work well together
|
# Note: New s3fs and boto3 versions don't work well together
|
||||||
# Always use comaptible fixed versions of these two dependencies
|
# Always use comaptible fixed versions of these two dependencies
|
||||||
aws = ["s3fs[boto3]==2025.3.2"]
|
aws = ["s3fs[boto3]==2025.3.2"]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue