Skip to main content
Version: latest

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.

  1. Raise ValueError with cannot create a graph in the home directory when the working directory is the home directory.
  2. Raise ValueError with cannot create a graph in a plugin directory when the working directory or one of its ancestors contains a .codex-plugin directory or a plugin.json file.
  3. Use the nearest existing .agrag directory in the working directory or an ancestor.
  4. Otherwise, create .agrag in the nearest ancestor that contains .git. A .git file or directory both count. When no ancestor has .git, create .agrag in the working directory.

Relate creates the directory and its parents when they are missing.

Files in the graph directory​

PathWritten byPurpose
relate/Relate, on every openThe Relate database. The graph and its indexes are stored here, and the engine manages its internal files.
relate.lockagrag, on every openAn exclusive lock held while the store is open. A second writer fails with GraphStoreBusyError.
relate-versionagrag, after each successful openThe Relate engine version that last opened the graph.
relate-backup-<version>/agrag, before an open with a newer engineA verified copy of relate/ and relate-version from the older version. agrag does not delete backups.
config.tomlYouOptional project settings. See config.toml keys.
.gitignoreagrag, when the directory is resolved and the file is missingContains * 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​

VariableDefaultMeaning
RELATE_GRAPH_DIRDiscovered from the working directoryThe graph directory that Relate uses. Setting it skips discovery. Set it in the process environment when you run the MCP server.
RELATE_DURABILITY_MODEUnsetMust 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.

KeyTypeDefault when omittedEnvironment variableEffect
[extraction] mode"gliner", "hybrid", or "llm"llmEXTRACTION_MODESets the extraction mode when Graph.open builds the extraction settings. This happens only when the call passes no extractor.
[embedding] modelStringibm-granite/granite-embedding-small-english-r2EMBEDDING_MODEL_NAMEChecked against the session value. The file does not select the embedder.
[embedding] cache_folderStringNone, which uses the model cache pathEMBEDDING_CACHE_FOLDERChecked against the session value. The file does not change the cache folder.
[retrieval] rerank_enabledBooleanfalseRETRIEVAL_RERANK_ENABLEDChecked against the session value. The file does not change reranking.
[retrieval] cross_encoder_modelStringawinml/ettin-reranker-17m-v1-ONNXRETRIEVAL_CROSS_ENCODER_MODELChecked 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.

  1. The value on the settings object you pass to Graph.open, such as extraction_settings, when that object sets the field.
  2. The value in config.toml.
  3. 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​

ExceptionCauseFix
tomllib.TOMLDecodeErrorThe file is not valid TOML.Fix the TOML syntax.
pydantic.ValidationErrorThe 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.
ProjectSettingsConflictErrorA 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.

NameStore classSettings classConnection
relateRelateGraphStoreRelateSettingsThe graph directory from RELATE_GRAPH_DIR, or the discovered directory
neo4jNeo4jGraphStoreNeo4jSettingsA Bolt server, configured with NEO4J_* variables
falkordbFalkorDBGraphStoreFalkorDBSettingsA 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 messageCauseFix
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 versionsrelate-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 fullThe 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 directoryDiscovery found a location that agrag does not use for graphs.Run from the project directory, or set RELATE_GRAPH_DIR.