Storage layout
Relate keeps a project's graph in a directory named .agrag. Relate is the default graph store for Python and MCP. The directory holds the Relate database, the lock and version files that agrag writes beside it, and an optional config.toml file. Neo4j and FalkorDB keep their data on their own servers, so they do not use this directory.
Graph directory
Relate resolves the graph directory when the store connects. When RELATE_GRAPH_DIR is set, Relate expands ~ in that path, resolves it to an absolute path, and uses it. The discovery steps below apply only when the variable is unset.
- Raise
ValueErrorwithcannot create a graph in the home directorywhen the working directory is the home directory. - Raise
ValueErrorwithcannot create a graph in a plugin directorywhen the working directory or one of its ancestors contains a.codex-plugindirectory or aplugin.jsonfile. - Use the nearest existing
.agragdirectory in the working directory or an ancestor. - Otherwise, create
.agragin the nearest ancestor that contains.git. A.gitfile or directory both count. When no ancestor has.git, create.agragin the working directory.
Relate creates the directory and its parents when they are missing.
Files in the graph directory
| Path | Written by | Purpose |
|---|---|---|
relate/ | Relate, on every open | The Relate database. The graph and its indexes are stored here, and the engine manages its internal files. |
relate.lock | agrag, on every open | An exclusive lock held while the store is open. A second writer fails with GraphStoreBusyError. |
relate-version | agrag, after each successful open | The Relate engine version that last opened the graph. |
relate-backup-<version>/ | agrag, before an open with a newer engine | A verified copy of relate/ and relate-version from the older version. agrag does not delete backups. |
config.toml | You | Optional project settings. See config.toml keys. |
.gitignore | agrag, when the directory is resolved and the file is missing | Contains * and !config.toml. Git ignores the database and tracks config.toml. |
When relate-version names an older stable version than the installed engine, agrag copies the database to relate-backup-<version>/ and checks every copied file before the open continues. A failed check stops the open, and no backup folder is left behind.
Environment variables
| Variable | Default | Meaning |
|---|---|---|
RELATE_GRAPH_DIR | Discovered from the working directory | The graph directory that Relate uses. Setting it skips discovery. Set it in the process environment when you run the MCP server. |
RELATE_DURABILITY_MODE | Unset | Must be unset or full. The store sets it to full while it opens the database and restores the previous value afterward. Any other value makes the open fail with GraphStoreError. |
config.toml
Relate reads config.toml from the graph directory when Graph.open runs. Neo4j and FalkorDB stores do not read the file. The file pins values for one graph, so every session that opens the graph uses them.
[extraction]
mode = "hybrid"
[embedding]
model = "ibm-granite/granite-embedding-small-english-r2"
cache_folder = "/data/agrag-models"
[retrieval]
rerank_enabled = true
cross_encoder_model = "awinml/ettin-reranker-17m-v1-ONNX"
Every key is optional. Unknown tables and keys are rejected.
| Key | Type | Default when omitted | Environment variable | Effect |
|---|---|---|---|---|
[extraction] mode | "gliner", "hybrid", or "llm" | llm | EXTRACTION_MODE | Sets the extraction mode when Graph.open builds the extraction settings. This happens only when the call passes no extractor. |
[embedding] model | String | ibm-granite/granite-embedding-small-english-r2 | EMBEDDING_MODEL_NAME | Checked against the session value. The file does not select the embedder. |
[embedding] cache_folder | String | None, which uses the model cache path | EMBEDDING_CACHE_FOLDER | Checked against the session value. The file does not change the cache folder. |
[retrieval] rerank_enabled | Boolean | false | RETRIEVAL_RERANK_ENABLED | Checked against the session value. The file does not change reranking. |
[retrieval] cross_encoder_model | String | awinml/ettin-reranker-17m-v1-ONNX | RETRIEVAL_CROSS_ENCODER_MODEL | Checked against the session value. The file does not select the reranker. |
The [embedding] and [retrieval] keys do not change behavior on their own. They only stop a session from using a different value for the same setting. The embedder and the search read their values from the environment or from the settings you pass in code. See Embeddings and Retrieval for those settings.
Precedence
For each key, the first value that applies wins.
- The value on the settings object you pass to
Graph.open, such asextraction_settings, when that object sets the field. - The value in
config.toml. - The class default.
An environment variable or .env value for the same key counts as a session value. When a session value is set and differs from the file, Graph.open raises ProjectSettingsConflictError before it connects to the store. This check runs even when you pass a settings object. The error names both values. Unset the environment variable or change the file.
Errors when reading config.toml
| Exception | Cause | Fix |
|---|---|---|
tomllib.TOMLDecodeError | The file is not valid TOML. | Fix the TOML syntax. |
pydantic.ValidationError | The file has an unknown table or key, a value of the wrong type, or a value outside the allowed choices, such as an unknown mode. | Use only the keys in the table above. |
ProjectSettingsConflictError | A session value differs from the file value. | Unset the environment variable or edit config.toml. |
Choose a graph store
Pass a backend name to Graph.open(graph_store=...) or to build_graph_store(). The names are relate, neo4j, and falkordb. Graph.open defaults to relate. You can also pass a constructed GraphStore instance. The MCP server reads the same names from MCP_GRAPH_STORE, which defaults to relate.
| Name | Store class | Settings class | Connection |
|---|---|---|---|
relate | RelateGraphStore | RelateSettings | The graph directory from RELATE_GRAPH_DIR, or the discovered directory |
neo4j | Neo4jGraphStore | Neo4jSettings | A Bolt server, configured with NEO4J_* variables |
falkordb | FalkorDBGraphStore | FalkorDBSettings | A Redis-protocol server, configured with FALKORDB_* variables |
Switching backends connects to a different database. It does not move a graph that already exists in another backend. Compare the backends in Graph storage, and set up a server in Configure storage backends. The variables for each backend are listed in Configuration.
Errors when opening Relate
| Exception and message | Cause | Fix |
|---|---|---|
GraphStoreBusyError, graph busy: <directory> | Another process holds relate.lock, or the engine reports that the storage is locked. | Close the process that has the graph open, then retry. |
GraphStoreError, graph at <directory> uses Relate <version> | relate-version names a newer engine than the installed one. | Install a relate-db version at least as new as the version in the message. |
GraphStoreError, Relate upgrades require stable engine versions | relate-version or the installed engine version is not in the X.Y.Z form. | Use a stable release of relate-db. |
GraphStoreError, could not verify backup of <path> | A copied file does not match the original during the pre-upgrade backup. | Retry the open after checking that the graph folder is writable and has free space. |
GraphStoreError, RELATE_DURABILITY_MODE must be full | The variable is set to a value other than full. | Unset the variable or set it to full. |
ValueError, cannot create a graph in the home directory or ... in a plugin directory | Discovery found a location that agrag does not use for graphs. | Run from the project directory, or set RELATE_GRAPH_DIR. |
Related
- Graph storage compares the three backends and explains vector placement.
- Configure storage backends shows how to open a Relate graph store and set up Neo4j or FalkorDB.
- Configuration lists every environment variable for each settings class.