diff --git a/cognee/infrastructure/databases/graph/config.py b/cognee/infrastructure/databases/graph/config.py index 3575f7c07..cdc001863 100644 --- a/cognee/infrastructure/databases/graph/config.py +++ b/cognee/infrastructure/databases/graph/config.py @@ -36,6 +36,7 @@ class GraphConfig(BaseSettings): graph_database_provider: str = Field("kuzu", env="GRAPH_DATABASE_PROVIDER") graph_database_url: str = "" + graph_database_name: str = "" graph_database_username: str = "" graph_database_password: str = "" graph_database_port: int = 123 @@ -105,6 +106,7 @@ class GraphConfig(BaseSettings): return { "graph_database_provider": self.graph_database_provider, "graph_database_url": self.graph_database_url, + "graph_database_name": self.graph_database_name, "graph_database_username": self.graph_database_username, "graph_database_password": self.graph_database_password, "graph_database_port": self.graph_database_port, diff --git a/cognee/infrastructure/databases/graph/get_graph_engine.py b/cognee/infrastructure/databases/graph/get_graph_engine.py index cb438f9e3..37be4bc7b 100644 --- a/cognee/infrastructure/databases/graph/get_graph_engine.py +++ b/cognee/infrastructure/databases/graph/get_graph_engine.py @@ -33,6 +33,7 @@ def create_graph_engine( graph_database_provider, graph_file_path, graph_database_url="", + graph_database_name="", graph_database_username="", graph_database_password="", graph_database_port="", @@ -86,6 +87,7 @@ def create_graph_engine( graph_database_url=graph_database_url, graph_database_username=graph_database_username or None, graph_database_password=graph_database_password or None, + graph_database_name=graph_database_name or None, ) elif graph_database_provider == "falkordb": diff --git a/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py b/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py index 50cc88605..ee2e5b18e 100644 --- a/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +++ b/cognee/infrastructure/databases/graph/neo4j_driver/adapter.py @@ -50,6 +50,7 @@ class Neo4jAdapter(GraphDBInterface): graph_database_url: str, graph_database_username: Optional[str] = None, graph_database_password: Optional[str] = None, + graph_database_name: Optional[str] = None, driver: Optional[Any] = None, ): # Only use auth if both username and password are provided @@ -59,7 +60,7 @@ class Neo4jAdapter(GraphDBInterface): elif graph_database_username or graph_database_password: logger = get_logger(__name__) logger.warning("Neo4j credentials incomplete – falling back to anonymous connection.") - + self.graph_database_name = graph_database_name self.driver = driver or AsyncGraphDatabase.driver( graph_database_url, auth=auth, @@ -80,7 +81,7 @@ class Neo4jAdapter(GraphDBInterface): """ Get a session for database operations. """ - async with self.driver.session() as session: + async with self.driver.session(database=self.graph_database_name) as session: yield session @deadlock_retry()