CortexDB · docs

Getting Started with CortexDB

CortexDB is a long-term memory layer for AI agents and applications. This guide gets you from zero to a running instance with stored, retrievable memories in under five minutes.

Run it (Docker — recommended)

docker run -d \
  --name cortexdb \
  -p 3141:3141 \
  -v cortexdb-data:/data \
  -e OPENAI_API_KEY=$OPENAI_API_KEY \
  -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
  cortexdb/cortexdb:latest

The server starts immediately in local no-auth mode: every request is served as user:local and, outside Docker, the server binds to loopback only. To require authentication, pass -e CORTEX_API_KEY=<your-chosen-key> — data routes then require Authorization: Bearer <your-chosen-key> (the key value itself is the credential), wrong or missing keys get 401, and anonymous signup is disabled. The web UI, bundled docs, and /v1/admin/health work without a key in both modes.

That's it. The server is listening on :3141, serving the v1 API and the built-in admin UI. Probe with:

curl http://localhost:3141/v1/admin/health
# {"status":"healthy","version":"..."}

First memories

# Capture an experience
curl -X POST http://localhost:3141/v1/experience \
  -H 'Content-Type: application/json' \
  -d '{
    "scope": "ws:demo",
    "modality": "observation",
    "content": { "kind": "text", "text": "Priya at Acme Corp signed for 200 seats. Q3 close." },
    "context": { "observed_at": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'" },
    "idempotency_key": "'"$(uuidgen)"'"
  }'

# Recall
curl -X POST http://localhost:3141/v1/recall \
  -H 'Content-Type: application/json' \
  -d '{
    "scope": "ws:demo",
    "query": "How many seats did Acme sign for?",
    "budgets": { "max_tokens": 1500 }
  }'

You should see the stored memory come back as part of the recall pack.

Episodes and beliefs (the five-layer claim)

Events go in immediately. Episodes (session clusters) and beliefs (aggregated fact statements) are derived layers — they don't materialize until a synthesis pass runs.

As of v0.4.0 the synthesis scheduler is on by default (audit BLK-1). As of v0.6.3 it is also event-driven: writes and completed enrichment batches wake it directly, so episodes/beliefs typically materialize within a couple of seconds of the enrichment LLM finishing — the 60s tick is only a fallback heartbeat. Store a few events and check /v1/episodes and /v1/beliefs a few seconds later.

Env varDefaultWhat it controls
CORTEX_V1_LAYERS_AUTOunset (scheduler on)Tri-state. Unset → scheduler runs, but its LLM stage (concept reflection) only runs when enrichment (CORTEX_ENRICHMENT_DELAY_SECONDS) is configured — enrichment unset means zero background LLM spend. 1/true → concept reflection runs even with enrichment off (reflects over raw events). 0/false → scheduler fully off.
CORTEX_V1_LAYERS_TICK_SECS60Seconds between fallback heartbeat ticks (min clamped to 5).
CORTEX_V1_LAYERS_WAKE1 (on as of v0.6.3)Event-driven wake on writes/enrichment. Set 0 for pure polling.
CORTEX_V1_LAYERS_WAKE_DEBOUNCE_MS1500How long a wake waits to coalesce a burst before rebuilding.
CORTEX_V1_LAYERS_CONCEPT_EVERYunsetLegacy override: tick-parity sampling (every Nth heartbeat tick). When unset, concept cadence is data-driven per scope: reflect after ≥25 new writes (CORTEX_V1_LAYERS_CONCEPT_MIN_WRITES) or ≥1h staleness (CORTEX_V1_LAYERS_CONCEPT_MAX_AGE_SECS), and only for scopes with fresh writes.
CORTEX_V1_LAYERS_AUTO_EXCLUDE_SCOPESemptyComma-list of scope-string prefixes opted out (e.g. internal/test).

LLM spend has two switches. CORTEX_ENRICHMENT_DELAY_SECONDS drives fact extraction (facts → beliefs); CORTEX_V1_LAYERS_AUTO drives the synthesis scheduler whose concept-reflection stage also calls the LLM. With both unset, nothing calls an LLM in the background: episodes still build (deterministic), facts/beliefs stay empty, and concept reflection is gated off — /v1/admin/layers/stats reports health.concepts_gated_by: "enrichment_unset".

Retrieval & answer knobs (v0.8.6)

Env varDefaultWhat it controls
CORTEX_RECENCY_ORDERonorder: "recency" recall mode — the events layer becomes the newest-K events by event time (timeline tail) instead of ranked top-K. Right for "recent / latest X" questions on repetitive histories. 0 disables.
CORTEX_RECENCY_TAIL_EVENTS100Tail size when the caller sends no budgets.per_layer_limits.events.
CORTEX_RECENCY_INFERENCEon/v1/answer infers order: "recency" from question phrasing (recent / latest / newest / current(ly) / next-step). Explicit order in the request always wins. 0 disables inference.
CORTEX_ANSWER_DEFAULT_INSTRUCTIONSunsetDeployment-wide standing prompt addendum for /v1/answer + /v1/compose (e.g. "always include entity identifiers"). Per-request answer_instructions refine it.

If you don't want to wait for the scheduler, trigger synthesis explicitly:

client.build_episodes(scope=SCOPE)   # → {"built": N, ...}
client.build_beliefs(scope=SCOPE)    # → {"built": N, ...}
client.synthesize(scope=SCOPE)       # → {"job_id": "...", "status": "running", "lifecycle_stream": "..."}

build_episodes and build_beliefs return synchronously. synthesize (concept reflection) is async — it returns a job id immediately and runs in the background; poll lifecycle_stream for completion before reading from /v1/understanding.

What you'll likely want next

Required environment

VariableRequired forWhat it does
OPENAI_API_KEYEmbeddings + fact extractionCalls text-embedding-3-small for vectors and gpt-4o-mini for entity/fact extraction during ingestion.
ANTHROPIC_API_KEY/v1/answerRenders the final answer (Claude is the recommended answer model).
COHERE_API_KEYOptional rerankerRequired by the Cohere reranker, but not sufficient alone: also set CORTEX_RERANKER_PROVIDER=cohere (and optionally CORTEX_RERANKER_MODEL, default rerank-v3.5).

Without OpenAI, writes still succeed but no embeddings or extracted facts are produced — recall will be markedly weaker. Without Anthropic, /v1/answer returns 503; everything else works.

See docs/PRODUCTION_DEPLOYMENT.md for the full env-var reference.

Default config (matches our published benchmarks)

The Docker image bakes in the same recall/answer configuration that scored 93.8% on LongMemEval-S and 85.5% on LoCoMo (cats 1-4). Specifically:

Override anything at runtime with -e VAR=value or --env-file your.env. The bench-reproducer doc (docs/REPRODUCE_LONGMEMEVAL_93_8.md in the repo) lists every load-bearing flag with a one-line explanation.

If you're running cortexdb continuously (not just for a benchmark), no extra config is needed. If you're reproducing the benchmark exactly, also set CORTEX_SCHEDULER_DISABLE=1 (skips background compaction during the run).

Run it (binary — for the Docker-haters)

Download the right tarball for your platform from https://github.com/cortexdb/cortexdb-releases/releases/latest and:

tar -xzf cortexdb-*-linux-amd64.tar.gz
cd cortexdb-*-linux-amd64
export OPENAI_API_KEY=...
export ANTHROPIC_API_KEY=...
./cortexdb 3141 ./data

The binary expects assets/wordnet_synonyms.json to live alongside it (included in the tarball).

Where data lives

Inside the container: /data (a Docker volume). Outside (binary install): the directory you pass as the second argument.

The directory contains:

Back this directory up with the server stopped (or use RocksDB's checkpoint APIs if you need hot backups).

Get help