Skip to content

Commit

Permalink
fix graph import
Browse files Browse the repository at this point in the history
  • Loading branch information
ILSparkle committed Dec 10, 2024
1 parent e6063a8 commit babdaf0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ jobs:
wget https://github.com/milvus-io/milvus/releases/download/v2.4.4/milvus-standalone-docker-compose.yml -O docker-compose.yml
sudo docker compose up -d
docker pull neo4j
docker run \
--name neo4j \
-d \
-p 7474:7474 \
-p 7687:7687 \
-e NEO4J_AUTH=none \
neo4j
docker run --name neo4j -d -p 7474:7474 -p 7687:7687 -e NEO4J_AUTH=none neo4j
- name: Test with pytest
run: |
Expand Down
16 changes: 11 additions & 5 deletions src/cardinal/graph/neo4j.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import json
from typing import Generic, Optional, Sequence, TypeVar
from typing import Optional, Sequence, TypeVar
from pydantic import BaseModel
from neo4j import GraphDatabase

from .schema import GraphStorage
from .config import settings
from ..utils.import_utils import is_neo4j_available


if is_neo4j_available():
from neo4j import GraphDatabase

T = TypeVar("T", bound=BaseModel)

class Neo4j(Generic[T]):
class Neo4j(GraphStorage[T]):
def __init__(self, name: str) -> None:
self.name = name
self.driver = GraphDatabase.driver("bolt://localhost:7687")
self.driver = GraphDatabase.driver(settings.neo4j_uri)

def insert_node(self, key: Sequence[str], node: Sequence[T]) -> None:
with self.driver.session() as session:
Expand Down
4 changes: 4 additions & 0 deletions src/cardinal/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def is_redis_available():
return _is_package_available("redis")


def is_neo4j_available():
return _is_package_available("neo4j")


def is_tiktoken_available():
return _is_package_available("tiktoken")

Expand Down

0 comments on commit babdaf0

Please sign in to comment.