Skip to main content
Version: 0.0.8 (stable)

Configure storage backends

Connect to Neo4j or FalkorDB to store the graph, embeddings, full-text indexes, and vector indexes. Both backends support ingestion, retrieval, conversation history, and decision traces. Choose by transaction and search behavior, then follow the setup for that server.

Vectors stay in the graph database by default. To store them exclusively in Qdrant, Milvus, or Weaviate instead, choose where vectors live. The graph database and its full-text indexes are required in either case.

Before you start​

You need Python 3.11 or newer and a running graph database. Install the Python driver extra for the backend you choose. The extra does not install the database server. Embedding and extraction models run separately from the database.

Set up a Neo4j graph store​

Use Neo4j 5.23 or later. The quickstart includes Docker and Aura setup.

  1. Install the driver.

    uv pip install "agentic-graphrag[neo4j]"
  2. Set the connection values in .env in the directory where you run Python. Replace the password with your database password.

    NEO4J_URI=bolt://localhost:7687
    NEO4J_USERNAME=neo4j
    NEO4J_PASSWORD=your-neo4j-password
    NEO4J_DATABASE=neo4j

    For a remote server, use neo4j+s:// or bolt+s://. A plaintext URI to a non-local host raises ValueError. For Aura, use the neo4j+s:// URI supplied by Aura.

  3. Verify the connection with a read query.

    import asyncio

    from agrag.graphdb import build_graph_store


    async def main() -> None:
    store = build_graph_store("neo4j")
    try:
    await store.connect()
    rows = await store.execute_read("RETURN 1 AS ready")
    print(rows[0]["ready"])
    finally:
    await store.close()


    asyncio.run(main())

    The script prints 1 when the database accepts the connection and query.

Set up a FalkorDB graph store​

Use FalkorDB 4.22.2 or later. The adapter requires RESULTSET_SIZE -1 so the server does not silently truncate query results. Multi-statement writes have no rollback.

  1. Install the driver.

    uv pip install "agentic-graphrag[falkordb]"

Start a FalkorDB server locally​

  1. Start a local server with persistent storage. The container has no password and binds only to the local machine. Use authentication and TLS for a remote deployment.

    docker run -d --name agrag-falkordb \
    -p 127.0.0.1:6379:6379 \
    -v agrag-falkordb-data:/var/lib/falkordb/data \
    -e BROWSER=0 \
    -e FALKORDB_ARGS="RESULTSET_SIZE -1 TIMEOUT_MAX 3600000 MAX_QUEUED_QUERIES 25" \
    falkordb/falkordb:v4.22.2

    The Redis-protocol endpoint listens on port 6379. The volume keeps data after the container is removed. BROWSER=0 disables the optional browser UI. To inspect the graph with that UI, set BROWSER=1 and also publish -p 127.0.0.1:3000:3000.

    Keep RESULTSET_SIZE -1 on every server the adapter connects to. The timeout and queue settings match the repository's development setup.

  2. Check server readiness.

    docker exec agrag-falkordb redis-cli ping

    Wait until the command prints PONG.

  3. Set the connection values in .env in the directory where you run Python.

    FALKORDB_URL=redis://localhost:6379
    FALKORDB_GRAPH=agrag

    Set FALKORDB_PASSWORD if the server requires one. Use rediss:// for TLS. A plaintext URL to a non-local host raises ValueError when FALKORDB_PASSWORD is set. The graph name is a Redis key, not a Neo4j database name.

  4. Verify the connection. connect checks the graph module version and RESULTSET_SIZE without creating the graph.

    import asyncio

    from agrag.graphdb import build_graph_store


    async def main() -> None:
    store = build_graph_store("falkordb")
    try:
    await store.connect()
    print("Connected to FalkorDB")
    finally:
    await store.close()


    asyncio.run(main())

    The script prints Connected to FalkorDB after the server checks pass. GraphStoreError reports an unsupported module version or result-size setting. The adapter creates the graph on its first write.

Connection defaults and pool settings are in the configuration reference.

Use the store for ingestion and retrieval​

Pass the store to Graph.open, retrieval functions, or build_agent. The backend choice changes the database adapter, not the schema or tool names. Graph.open connects the store and sets up the graph's constraints and indexes.

With extraction installed and a source file at your-document.md, ingest into FalkorDB as follows. The same code uses Neo4j if you change the store name and configure NEO4J_*.

uv pip install "agentic-graphrag[falkordb,extract]" --torch-backend=auto
import asyncio
from pathlib import Path

from agrag.embedding import build_embedder
from agrag.graphdb import build_graph_store
from agrag.ingestion import ExtractionSettings, Graph


async def main() -> None:
store = build_graph_store("falkordb")
embedder = build_embedder("ibm-granite/granite-embedding-small-english-r2")
try:
graph = await Graph.open(
schema="operations",
graph_store=store,
embedder=embedder,
extraction_settings=ExtractionSettings(mode="gliner"),
max_llm_pairs=0,
)
await graph.add(Path("your-document.md").resolve())
finally:
await store.close()


asyncio.run(main())

The call writes the document and its extracted graph to the selected backend. Use Find and cite evidence to query it, passing the same store and embedding model. Changing the store name does not copy data between databases. Ingest the source documents into the new backend before searching there.

Write records and search vectors directly​

For low-level writes without Graph, use upsert_nodes and upsert_relations. Each node needs an ID, labels, and a properties map. Labels accumulate on repeated upserts. Records with different label sets are grouped and written separately. Call setup_constraints after writing a new label.

The following example writes a note and searches its vector on Neo4j. Use build_graph_store("falkordb") with the FalkorDB connection settings to run the same operations there. The three-value vector is sample data, not an embedding model's output.

import asyncio
from uuid import uuid4

from agrag.common.data_models.graph_record import NodeRecord
from agrag.common.data_models.vector_record import Distance
from agrag.graphdb import build_graph_store


async def main() -> None:
store = build_graph_store("neo4j")
try:
await store.connect()
node = NodeRecord(
id=uuid4(),
labels=["BackendExampleNote"],
properties={"text": "first passage", "embedding": [1.0, 0.0, 0.0]},
)
result = await store.upsert_nodes("BackendExampleNote", [node])
for failure in result.failures:
print(f"{failure.id} failed: {failure.error_message}")
await store.setup_constraints()
await store.ensure_vector_index(
label="BackendExampleNote",
vector_property="embedding",
dimensions=3,
distance=Distance.COSINE,
)
async with asyncio.timeout(60):
while any(
index.state != "ONLINE" for index in await store.list_indexes()
):
await asyncio.sleep(0.1)
hits = await store.vector_search(
label="BackendExampleNote",
vector_property="embedding",
query_vector=[1.0, 0.0, 0.0],
limit=1,
)
print([hit.id for hit in hits])
finally:
await store.close()


asyncio.run(main())

The example leaves the note and index in the database. It waits up to 60 seconds for indexes to become online before searching. A successful search prints a list containing a stored note's UUID. Repeated runs can return an earlier note because all sample vectors are identical.

upsert_nodes and upsert_relations return an UpsertResult with successful-write counts and record-specific failures. A bad record does not prevent other valid records from being written. Connectivity and authentication failures raise instead of returning a partial result. The graph-store API describes the write and index methods.

Select the backend for MCP​

Install agentic-graphrag[neo4j,mcp] or agentic-graphrag[falkordb,mcp]. Set MCP_GRAPH_STORE in the environment used by your MCP client. Python callers still select the store explicitly with build_graph_store. If vectors live in an external store, also set MCP_VECTOR_STORE to qdrant, milvus, or weaviate, matching ingestion. Choose where vectors live covers the store setup.

For a FalkorDB graph already populated by ingestion, add these values to the MCP server's environment. Replace the document key with the resolved path used at ingestion.

MCP_GRAPH_STORE=falkordb
FALKORDB_URL=redis://localhost:6379
FALKORDB_GRAPH=agrag
MCP_SCOPE_DOCUMENT_KEYS=/full/path/to/your-document.md
EMBEDDING_MODEL=ibm-granite/granite-embedding-small-english-r2

For Neo4j, set MCP_GRAPH_STORE=neo4j and use NEO4J_* connection values. Neo4j is the MCP default if the selector is omitted. Keep the database, document keys, and embedding model consistent with ingestion. Run the MCP server to configure the client and enable history or decision writes when needed.

Configure the embedder​

The default FastEmbed model, ibm-granite/granite-embedding-small-english-r2, runs on the CPU with ONNX Runtime and needs no embedding extra. build_embedder accepts other supported FastEmbed model names. Both backends require vector dimensions that match the embedder, and Graph.open rejects mismatched indexes before writing vectors.

For a Sentence Transformers model or a different device, install agentic-graphrag[embed-local] and construct the embedder explicitly.

from agrag.embedding import EmbeddingSettings, SentenceTransformerEmbedder

embedder = SentenceTransformerEmbedder(
settings=EmbeddingSettings(model="BAAI/bge-small-en-v1.5", device="cuda"),
)

The embedding settings reference lists model, normalization, device, batching, and cache settings. Use the same model for writes and searches, not merely models with the same number of dimensions.

FalkorDB behavior to know​

Atomicity​

FalkorDB runs each query atomically, but has no transaction across several statements. run_in_transaction runs statements in order without rollback when a later statement fails. Earlier writes remain, and other readers can see them before the callback returns. Use Neo4j if your callback requires all-or-nothing writes. On FalkorDB, make each statement safe to repeat.

Vector metrics​

Use Distance.COSINE or Distance.EUCLID. ensure_vector_index raises ValueError for unsupported distances, including dot product.

Filters apply after the native index picks nearest candidates. The adapter requests more candidates when needed, up to an internal cap. A selective filter can still return fewer hits than the requested limit. Both backends use candidate expansion, and neither guarantees identical rankings.

Crash recovery of a commit​

A document change commits in several statements. If the process stops after the commit-started marker, a later Graph.open attempts to finish that commit after its lease expires instead of rolling it back. Recovery resumes persisted deferred writes after their recorded progress, folds relations, rebuilds the resolved-entity components the change touched, and completes the document status change. A crash between a replay step and its progress record can repeat that step. Entity, relation, match, and alias writes overwrite or MERGE their values, so a repeated write leaves the same state. On a repeat, the step writes its ID again, and the counters that record merges and review changes stay the same, as long as no other commit has written the same entity or decision since the first attempt. If another commit has, a repeat adds its change to that counter a second time.

On both backends, a commit that hits a constraint conflict with another job is retried under the same lease, for up to one lease TTL from the first failure. Set the TTL with CUTOVER_JOB_LEASE_TTL_SECONDS. After that, the error is raised. The TTL limits when a new attempt starts, not how long one database call runs. On Neo4j, a write conflict is retried the same way, because Neo4j rolls back the failed attempt. On FalkorDB, a write conflict is raised at once, and the job is left for a later Graph.open after its lease expires.

Retried history and decision writes​

A failed multi-statement history or decision write can leave partial effects. Retrying can repeat an effect because the earlier statements were not rolled back. Keep a stable request_id across retries, but do not treat the request ID as a guarantee of all-or-nothing execution on FalkorDB.

A query matches text containing any query word, ranked by FalkorDB's native TF-IDF score. The adapter adds 1.0 so matches with a native score of zero remain positive, without changing their order. Neo4j uses its native full-text scores, so lexical and hybrid rankings can differ. The adapter indexes internal copies of FalkorDB text properties with line breaks replaced by spaces to work around tokenization at line breaks. Those copies are hidden from returned properties.

Configure Milvus vectors​

Milvus stores external dense vectors and generates BM25 sparse vectors from text. A Neo4j or FalkorDB graph remains required for graph records, visibility checks, and property filters. Install agentic-graphrag[milvus] alongside the graph driver extra.

  1. Set MILVUS_URI to the server endpoint. For Zilliz Cloud, use its HTTPS endpoint and set MILVUS_TOKEN privately. Do not put credentials in the URI or commit the token.

  2. Set MILVUS_COLLECTION_PREFIX to a namespace unique to this graph. The prefix must start with a letter and contain at most 41 letters, digits or underscores.

  3. Pass the store to Graph.open when first creating the graph.

    from agrag.embedding import build_embedder
    from agrag.graphdb import build_graph_store
    from agrag.ingestion import Graph
    from agrag.vectordb.milvus import MilvusSettings, MilvusVectorStore

    vectors = MilvusVectorStore(MilvusSettings())
    graph_store = build_graph_store("neo4j")
    embedder = build_embedder("ibm-granite/granite-embedding-small-english-r2")
    graph = await Graph.open(
    schema="operations", graph_store=graph_store,
    embedder=embedder, vector_store=vectors,
    )

The graph creates four collections under that prefix and checks their dimensions and distance metric. Placement is fixed for the graph; changing the store, prefix, embedder dimensions or distance requires a new graph and re-ingestion. Keep the same store available to retrieval and evidence search. Only labels are filtered before the graph join.

For local development, start an isolated service with a project name and nondefault port:

MILVUS_PORT=29533 docker compose -p agrag-milvus -f docker/docker-compose.dev.yml up -d --wait milvus

Set MILVUS_URI=http://localhost:29533 for that service. The container runs embedded etcd and local storage with a project-scoped persistent volume. The Milvus settings define text and search limits. Use smaller search limits if a Zilliz gateway rejects a response for size.

Set up Weaviate for vectors​

Install agentic-graphrag[neo4j,weaviate], replacing neo4j with falkordb if needed. Weaviate stores embeddings and BM25 text while the graph database keeps graph records. External placement is exclusive and fixed for a graph.

  1. Set the deployment mode and endpoints. Both HTTP and gRPC must be reachable. HTTPS enables TLS on both transports. Keep server-side ASYNC_INDEXING=false for read-after-write consistency.

    WEAVIATE_MODE=custom
    WEAVIATE_URL=http://localhost:8080
    WEAVIATE_GRPC_PORT=50051
    WEAVIATE_API_KEY=your-api-key
    WEAVIATE_COLLECTION_PREFIX=my_graph

    For Weaviate Cloud, set WEAVIATE_MODE=cloud and use the cluster's HTTPS URL and API key. Cloud uses gRPC over TLS on port 443 and ignores WEAVIATE_GRPC_PORT.

  2. Construct WeaviateVectorStore(settings=WeaviateSettings()) from agrag.vectordb. Pass the same instance to ingestion and retrieval as in Choose where vectors live.

The adapter creates four collections with a capitalized first letter, such as My_graph_chunks. Prefixes must start with a lowercase letter so capitalization cannot make two prefixes select the same collections. Each prefix belongs to one graph. Keep the collection description unchanged because it records dimensions even before the first object is written.

Dense scores use the graph-native scale. Hybrid search combines the supplied vector with BM25 over the embedded text. Alpha one uses dense search; alpha zero uses BM25 and omits lexical nonmatches. Search requests are capped at 10,000 results. Weaviate settings define connection and collection limits.