graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

[Feature] Allow configuring Neo4j database name (multi-DB support)

Open MumuTW opened this issue 6 months ago • 4 comments

🗂️ Background

I’m trying to run graphiti_mcp_server.py with a custom database hosted in a Neo4j instance.
Currently, Neo4jConfig only reads NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD from environment variables.
There is no option to specify a target database, so the server always connects to the default neo4j database.

✅ Expectation

Users should be able to set NEO4J_DATABASE=my_custom_db in .env to configure which target database to use. All Neo4jDriver sessions should run Cypher queries against that specific database instead of silently defaulting to the built-in neo4j database.

⚡Actual Behavior

  • Neo4jConfig correctly reads NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD — but ignores NEO4J_DATABASE.
  • Neo4jDriver sets self._database to 'neo4j' by default at init, so all sessions fallback to the default DB.
  • No place in the current Graphiti or Neo4jDriver logic explicitly overrides the target DB for each session() or execute_query().
  • Even if you provide NEO4J_DATABASE in .env, it does nothing — causing unexpected cross-environment data mixing or permission errors if the user doesn’t have access to the default neo4j DB.

🔑 Why This Matters

  • Neo4j supports multiple isolated databases since 4.x.
  • Real-world teams rely on multi-tenancy: staging, production, test DBs, or even tenant-per-graph setups.
  • People expect full DB routing to be configured declaratively via .env, without patching Python code.
  • Fallback to 'neo4j' is fine if not set — but users must be able to explicitly override the DB safely.

🧩 Minimal repro

# .env
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=my-user
NEO4J_PASSWORD=my-pass
NEO4J_DATABASE=my-database

# run
uv run graphiti_mcp_server.py --model gpt-4.1-mini

✅ Connection to bolt://localhost:7687 works, ❌ But queries fail if the user doesn’t have access to the default neo4j DB.

🕵️‍♂️ Root Cause

  • Neo4jDriver currently pins self._database to 'neo4j' by default.
  • session() and execute_query() use this pinned value if no database is passed.
  • Graphiti does not propagate database=... per request, so it always falls back to the pinned value.
  • There is no config parsing for NEO4J_DATABASE.

📝Proposed solution

  • [ ] Add database: str to Neo4jConfig and parse NEO4J_DATABASE from the environment, with fallback to 'neo4j'.

  • [ ] Update Neo4jDriver:

def __init__(..., database: str = 'neo4j'):
    self._database = database
  • [ ] Pass database to all session() and execute_query() calls:
def session(self, database: str | None = None):
    return self.client.session(database=database or self._database)

async def execute_query(self, cypher_query_, database: str | None = None, ...):
    return await self.client.execute_query(..., database_=database or self._database)
  • [ ] Update Graphiti to store self.database and always pass it when opening sessions.
  • [ ] Document NEO4J_DATABASE usage in .env.example and README.
  • [ ] Consider adding an integration test for multi-DB routing.

🙏 Extra context

Happy to open a PR for this if you’d like — please confirm if there’s any design constraint I should know about! Reference: Neo4j Python Driver supports multi-database connections since 4.x: https://neo4j.com/docs/api/python-driver/current/api.html#session

Thanks for making Graphiti awesome! 🚀✨

MumuTW avatar Jul 14 '25 04:07 MumuTW

graphiti seems to have a bunch of possible drivers outside of Neo4j that would have to take the top level db param. Not sure what to do about KuzuDriver and NeptuneDriver.

jeanlucthumm avatar Sep 04 '25 18:09 jeanlucthumm

FYI: Neo4j community edition does not support multiple databases, it's always neo4j. This is an Enterprise feature.

https://neo4j.com/docs/upgrade-migration-guide/current/version-4/migration/drivers/multiple-db/

jeanlucthumm avatar Sep 04 '25 18:09 jeanlucthumm

@MumuTW Is this still an issue? Please confirm within 14 days or this issue will be closed.

claude[bot] avatar Oct 17 '25 00:10 claude[bot]

@MumuTW Is this still relevant? Please confirm within 14 days or this issue will be closed.

claude[bot] avatar Nov 17 '25 00:11 claude[bot]