Remove NetworkX from cognee core. (#1241)
<!-- .github/pull_request_template.md --> ## Description <!-- Provide a clear description of the changes in this PR --> Remove NetworkX from cognee core. ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.
This commit is contained in:
commit
9987e05ebe
10 changed files with 82 additions and 1049 deletions
67
.github/actions/setup_neo4j/action.yml
vendored
Normal file
67
.github/actions/setup_neo4j/action.yml
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
name: 'Setup Neo4j with Graph Data Science'
|
||||
description: 'Sets up a Neo4j instance with APOC and Graph Data Science plugins for testing'
|
||||
inputs:
|
||||
neo4j-version:
|
||||
description: 'Neo4j version to use'
|
||||
required: false
|
||||
default: '5.21'
|
||||
neo4j-password:
|
||||
description: 'Password for Neo4j'
|
||||
required: false
|
||||
default: 'cognee_test_password'
|
||||
outputs:
|
||||
neo4j-url:
|
||||
description: 'Neo4j connection URL'
|
||||
value: 'bolt://localhost:7687'
|
||||
neo4j-username:
|
||||
description: 'Neo4j username'
|
||||
value: 'neo4j'
|
||||
neo4j-password:
|
||||
description: 'Neo4j password'
|
||||
value: ${{ inputs.neo4j-password }}
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Start Neo4j with GDS
|
||||
shell: bash
|
||||
run: |
|
||||
docker run -d \
|
||||
--name neo4j-test \
|
||||
-p 7474:7474 -p 7687:7687 \
|
||||
-e NEO4J_AUTH="neo4j/${{ inputs.neo4j-password }}" \
|
||||
-e NEO4J_PLUGINS='["apoc", "graph-data-science"]' \
|
||||
-e NEO4J_dbms_security_procedures_unrestricted="apoc.*,gds.*" \
|
||||
-e NEO4J_apoc_export_file_enabled=true \
|
||||
-e NEO4J_apoc_import_file_enabled=true \
|
||||
neo4j:${{ inputs.neo4j-version }}
|
||||
|
||||
- name: Wait for Neo4j to be ready
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Waiting for Neo4j to start..."
|
||||
timeout=60
|
||||
counter=0
|
||||
|
||||
while [ $counter -lt $timeout ]; do
|
||||
if docker exec neo4j-test cypher-shell -u neo4j -p "${{ inputs.neo4j-password }}" "RETURN 1" > /dev/null 2>&1; then
|
||||
echo "Neo4j is ready!"
|
||||
break
|
||||
fi
|
||||
echo "Waiting... ($counter/$timeout)"
|
||||
sleep 2
|
||||
counter=$((counter + 2))
|
||||
done
|
||||
|
||||
if [ $counter -ge $timeout ]; then
|
||||
echo "Neo4j failed to start within $timeout seconds"
|
||||
docker logs neo4j-test
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Verify GDS is available
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Verifying Graph Data Science library is available..."
|
||||
docker exec neo4j-test cypher-shell -u neo4j -p "${{ inputs.neo4j-password }}" \
|
||||
"CALL gds.version() YIELD gdsVersion RETURN gdsVersion"
|
||||
echo "GDS verification complete!"
|
||||
10
.github/workflows/examples_tests.yml
vendored
10
.github/workflows/examples_tests.yml
vendored
|
|
@ -60,6 +60,10 @@ jobs:
|
|||
with:
|
||||
python-version: '3.11.x'
|
||||
|
||||
- name: Setup Neo4j with GDS
|
||||
uses: ./.github/actions/setup_neo4j
|
||||
id: neo4j
|
||||
|
||||
- name: Run Descriptive Graph Metrics Example
|
||||
env:
|
||||
LLM_MODEL: ${{ secrets.LLM_MODEL }}
|
||||
|
|
@ -71,7 +75,11 @@ jobs:
|
|||
EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }}
|
||||
EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }}
|
||||
EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }}
|
||||
run: uv run python ./cognee/tests/tasks/descriptive_metrics/networkx_metrics_test.py
|
||||
GRAPH_DATABASE_PROVIDER: "neo4j"
|
||||
GRAPH_DATABASE_URL: ${{ steps.neo4j.outputs.neo4j-url }}
|
||||
GRAPH_DATABASE_USERNAME: ${{ steps.neo4j.outputs.neo4j-username }}
|
||||
GRAPH_DATABASE_PASSWORD: ${{ steps.neo4j.outputs.neo4j-password }}
|
||||
run: uv run python ./cognee/tests/tasks/descriptive_metrics/neo4j_metrics_test.py
|
||||
|
||||
|
||||
test-dynamic-steps-metrics:
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ async def add(
|
|||
- DEFAULT_USER_EMAIL: Custom default user email
|
||||
- DEFAULT_USER_PASSWORD: Custom default user password
|
||||
- VECTOR_DB_PROVIDER: "lancedb" (default), "chromadb", "pgvector"
|
||||
- GRAPH_DATABASE_PROVIDER: "kuzu" (default), "neo4j", "networkx"
|
||||
- GRAPH_DATABASE_PROVIDER: "kuzu" (default), "neo4j"
|
||||
|
||||
"""
|
||||
tasks = [
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@ async def get_graph_engine() -> GraphDBInterface:
|
|||
if hasattr(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
|
||||
|
||||
|
||||
|
|
@ -181,8 +177,7 @@ def create_graph_engine(
|
|||
graph_id=graph_identifier,
|
||||
)
|
||||
|
||||
from .networkx.adapter import NetworkXAdapter
|
||||
|
||||
graph_client = NetworkXAdapter(filename=graph_file_path)
|
||||
|
||||
return graph_client
|
||||
raise EnvironmentError(
|
||||
f"Unsupported graph database provider: {graph_database_provider}. "
|
||||
f"Supported providers are: {', '.join(list(supported_databases.keys()) + ['neo4j', 'falkordb', 'kuzu', 'kuzu-remote', 'memgraph', 'neptune', 'neptune_analytics'])}"
|
||||
)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,5 @@
|
|||
from typing import Any, Optional
|
||||
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.utils.completion import generate_completion
|
||||
from cognee.modules.retrieval.exceptions import SearchTypeNotSupported, CypherSearchError
|
||||
|
|
@ -31,8 +30,7 @@ class CypherSearchRetriever(BaseRetriever):
|
|||
"""
|
||||
Retrieves relevant context using a cypher query.
|
||||
|
||||
If the graph engine is an instance of NetworkXAdapter, raises SearchTypeNotSupported. If
|
||||
any error occurs during execution, logs the error and raises CypherSearchError.
|
||||
If any error occurs during execution, logs the error and raises CypherSearchError.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
|
|
@ -46,12 +44,6 @@ class CypherSearchRetriever(BaseRetriever):
|
|||
"""
|
||||
try:
|
||||
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)
|
||||
except Exception as e:
|
||||
logger.error("Failed to execture cypher search retrieval: %s", str(e))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from typing import Any, Optional
|
||||
from cognee.shared.logging_utils import get_logger
|
||||
from cognee.infrastructure.databases.graph import get_graph_engine
|
||||
from cognee.infrastructure.databases.graph.networkx.adapter import NetworkXAdapter
|
||||
from cognee.infrastructure.llm.LLMGateway import LLMGateway
|
||||
from cognee.modules.retrieval.base_retriever import BaseRetriever
|
||||
from cognee.modules.retrieval.exceptions import SearchTypeNotSupported
|
||||
|
|
@ -123,9 +122,6 @@ class NaturalLanguageRetriever(BaseRetriever):
|
|||
"""
|
||||
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)
|
||||
|
||||
async def get_completion(self, query: str, context: Optional[Any] = None) -> Any:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
import os
|
||||
import requests
|
||||
from datetime import datetime, timezone
|
||||
import networkx as nx
|
||||
import matplotlib.pyplot as plt
|
||||
import http.server
|
||||
import socketserver
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
from cognee.tests.tasks.descriptive_metrics.metrics_test_utils import assert_metrics
|
||||
import asyncio
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(assert_metrics(provider="networkx", include_optional=False))
|
||||
asyncio.run(assert_metrics(provider="networkx", include_optional=True))
|
||||
Loading…
Add table
Reference in a new issue