CortexDB · docs

Getting Started with CortexDB

CortexDB is a durable, scoped memory layer for agents and applications. This guide starts an authenticated local instance, waits for a memory to become searchable, and recalls it.

Run with Docker

Download CortexDB from the customer portal, https://customer.cortexdb.ai (Releases), with your company's license: the image file for your platform, cortexdb-<version>-image-linux-<arch>.tar.gz (amd64 or arm64), and the .sha256 beside it. Check the file and load it; it loads as cortexdb/cortexdb:v<version>:

sha256sum -c cortexdb-0.16.1-image-linux-amd64.tar.gz.sha256
docker load -i cortexdb-0.16.1-image-linux-amd64.tar.gz

There is no public image to pull. For a host without Docker, the same page has the binary, cortexdb-<version>-linux-<arch>.tar.gz (Production deployment).

The image uses OpenAI embeddings by default. Set the embedding credential, an operator-chosen CortexDB bearer and your license before starting it (the server keeps the license in its data directory and renews it):

export OPENAI_API_KEY="..."
export CORTEX_API_KEY="$(openssl rand -hex 32)"
export CORTEX_LICENSE='...'

docker run -d \
  --name cortexdb \
  --restart unless-stopped \
  -p 127.0.0.1:3141:3141 \
  -v cortexdb-data:/data \
  -e OPENAI_API_KEY \
  -e CORTEX_API_KEY \
  -e CORTEX_LICENSE \
  cortexdb/cortexdb:v0.16.1

--restart unless-stopped lets Docker bring the server back after the admin console's Restart button (it exits so the supervisor can relaunch it with new settings) or a crash; without a restart policy the container stays stopped. See Restart policies. The loopback port binding keeps this instance local to the host. The explicit CORTEX_API_KEY is a stable bearer credential across restarts; data routes return 401 when it is absent or incorrect — including a request that supplies only an X-Cortex-Actor header. Leaving the key unset does not simply relax that; see Authentication postures for what a keyless boot actually does. Do not publish the port to other interfaces until authentication, TLS termination, and tenant policy are configured for that network.

The health and readiness probes are public:

curl --fail-with-body http://localhost:3141/v1/admin/health
curl --fail-with-body http://localhost:3141/v1/admin/ready

Store and recall a memory

Use wait=indexed on this first write. The normal write path is asynchronous; the indexed barrier prevents the immediately following recall from racing the indexer.

curl --fail-with-body -X POST \
  'http://localhost:3141/v1/experience?wait=indexed' \
  -H "Authorization: Bearer $CORTEX_API_KEY" \
  -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."
    },
    "idempotency_key": "getting-started-acme-q3"
  }'

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

The recall response contains an evidence-bearing context pack. Generating a final natural-language response is a separate /v1/answer operation and needs an answer-provider credential.

Correct a memory

When CortexDB holds something wrong, correct it rather than forget it. The default forget removes only what was derived, which a later re-derivation can learn again from the events it leaves; a correction stays through re-enrichment and re-derivation. It is kept against a claim (subject, predicate and value), not a fact id, so it holds when facts are derived again: a request names the claim, or a fact that the server resolves to its claim.

Corrections need CortexDB 0.15.0 or later: GET /v1/admin/version lists corrections_v1 in its capabilities, and an older server answers these routes 404. While an operator holds the data directory's upgrade back with CORTEX_FORMAT_CEILING, they answer 503 FORMAT_UPGRADE_PENDING. Their responses carry X-Cortex-Stability: experimental.

This example states a fact directly, as a typed triple (content.kind: "triple": stored exactly as sent, and no model reads it), reads it back, replaces its value and reads again:

H=http://localhost:3141
AUTH="Authorization: Bearer $CORTEX_API_KEY"
JSON='Content-Type: application/json'

# Priya lives in Boston, as a typed triple.
curl --fail-with-body -X POST "$H/v1/experience?wait=indexed" \
  -H "$AUTH" -H "$JSON" \
  -d '{
    "scope": "ws:demo/user:priya",
    "modality": "observation",
    "content": {
      "kind": "triple",
      "triple": {
        "subject": {"type": "literal", "datatype": "string", "value": "Priya"},
        "predicate": "lives_in",
        "object": {"type": "literal", "datatype": "string", "value": "Boston"}
      }
    },
    "idempotency_key": "getting-started-priya-home"
  }'

curl --fail-with-body "$H/v1/facts?scope=ws:demo/user:priya" -H "$AUTH"

# It is wrong: she lives in Denver. The claim is named as stated.
curl --fail-with-body -X POST "$H/v1/corrections" \
  -H "$AUTH" -H "$JSON" \
  -d '{
    "scope": "ws:demo/user:priya",
    "action": "replace",
    "target": {"claim": {"subject": "Priya", "predicate": "lives_in", "object": "Boston"}},
    "value": {"object": "Denver"},
    "idempotency_key": "getting-started-priya-moved"
  }'

curl --fail-with-body "$H/v1/facts?scope=ws:demo/user:priya" -H "$AUTH"
curl --fail-with-body -H "$AUTH" \
  "$H/v1/facts/timeline?scope=ws:demo/user:priya&subject=Priya&predicate=lives_in"

The first read lists the triple's fact (ids shortened, fields left out):

{"items": [{"id": "fact_0196f3b0…9e11", "scope": "ws:demo/user:priya",
            "subject": {"type": "entity", "id": "ent_Priya"}, "predicate": "lives_in",
            "object": {"type": "literal", "datatype": "string", "value": "Boston"},
            "supports": ["evt_0196f3b0…9e10"], "valid_from": "2026-11-08T10:00:00Z",
            "valid_to": null, "…": "…"}],
 "has_more": false}

The correction answers 201. It wrote the new value as a typed triple of its own (replacement), pinned the new claim so that no value enrichment extracts later replaces it, and suppressed the old claim, so that enrichment never learns it again from anything captured before the correction:

{"correction_id": "cor_0196f3b0…9e14", "action": "replace", "scope": "ws:demo/user:priya",
 "claim": {"subject": "Priya", "predicate": "lives_in", "object": "Boston"},
 "replacement": {"event_id": "evt_0196f3b0…9e12", "fact_id": "fact_0196f3b0…9e13",
                 "claim": {"subject": "Priya", "predicate": "lives_in", "object": "Denver"}},
 "effects": {"facts_deleted": 0, "facts_closed": 0, "pinned": true, "suppressed_sources": 1},
 "state": "applied", "record_kept": true, "consistency_token": "ct1.…"}

facts_closed counts the facts enrichment extracted for the old claim, which the correction closes itself; a typed triple, as here, is closed by the newer triple. The route answers once this server has applied the correction, so the next read needs no ?at_least=: the facts now list Denver alone, and the timeline keeps Boston, ended where Denver began:

{"items": [{"id": "fact_0196f3b0…9e13", "scope": "ws:demo/user:priya",
            "subject": {"type": "entity", "id": "ent_Priya"}, "predicate": "lives_in",
            "object": {"type": "literal", "datatype": "string", "value": "Denver"},
            "supports": ["evt_0196f3b0…9e12"], "valid_from": "2026-11-08T10:00:05Z",
            "valid_to": null, "…": "…"}],
 "has_more": false}

{"subject": {"id": "ent_Priya"}, "predicate": "lives_in",
 "timeline": [{"fact_id": "fact_0196f3b0…9e11", "value": "Boston",
               "valid_from": "2026-11-08T10:00:00Z", "valid_to": "2026-11-08T10:00:05Z"},
              {"fact_id": "fact_0196f3b0…9e13", "value": "Denver",
               "valid_from": "2026-11-08T10:00:05Z", "valid_to": null}]}

The other actions are reject (delete the claim's facts and keep enrichment from learning it again; rejecting a typed triple erases the event that stated it), pin and confirm. GET /v1/corrections?scope= lists a scope's corrections, DELETE /v1/corrections/{id}?scope= undoes one, and GET /v1/memory/about?scope= lists what is known about the scope's subject, with its sources. See the API Reference, §8.7.24 and §8.7.25.

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.9.0 the synthesis scheduler is off by default — a fresh install runs the vector-only benchmark shape, and layers are an explicit opt-in (CORTEX_V1_LAYERS_AUTO=1). Once enabled, the scheduler is event-driven (since v0.6.3): writes and completed enrichment batches wake it directly, so episodes/beliefs typically materialize within a couple of seconds — the 60s tick is only a fallback heartbeat. Enable it, store a few events, and check /v1/episodes and /v1/beliefs a few seconds later.

Env varDefaultWhat it controls
CORTEX_V1_LAYERS_AUTOunset (scheduler OFF — the vector-only default)Opt-in. Unset or 0/false → no background layer builds at all: a fresh install runs pure hybrid vector+BM25 retrieval, the same shape as the published benchmarks. 1/true → the scheduler runs (episodes/beliefs build; concept reflection also runs, calling the LLM even with enrichment off — conscious spend). Manual POST /v1/understanding/synthesize works in every mode.
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).

Everything beyond retrieval is opt-in (v0.9.0). The fresh-install default is vector-only — the exact benchmark configuration: hybrid vector+BM25 retrieval with no entity graph, no facts, no enrichment, no artifact routes, and no background layer builds. Each feature has its own explicit switch: CORTEX_ENTITY_GRAPH=1 (graph), CORTEX_ENRICHMENT_DELAY_SECONDS (+ CORTEX_ENRICHMENT_{URL,MODEL}) for enrichment/fact extraction, and CORTEX_V1_LAYERS_AUTO=1 for the synthesis scheduler. With none of them set, nothing calls an LLM in the background and no derived layers build.

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, query expansion, the answer verifierCalls text-embedding-3-small for vectors, gpt-4o-mini to expand some queries, and gpt-4.1 to check some answers (the verifier is skipped without a key). Enrichment, off by default, has its own CORTEX_ENRICHMENT_* settings.
ANTHROPIC_API_KEY/v1/answerRenders the final answer (Claude is the recommended answer model).
COHERE_API_KEYOptional rerankerA rerank credential (this, or the role-scoped CORTEX_RERANKER_API_KEY, which wins) is required by the cross-encoder reranker, but not sufficient alone: also set CORTEX_RERANKER_PROVIDER=cohere (and optionally CORTEX_RERANKER_MODEL, default rerank-v3.5, or CORTEX_RERANKER_URL to reach a Cohere-shaped rerank endpoint you host).

The image does not start without an embedding key. It is configured for OpenAI embeddings, so rather than store vectors nothing can search, it exits at startup with FATAL: an explicit CORTEX_EMBEDDING_URL requires CORTEX_EMBEDDING_API_KEY, OPENAI_API_KEY, or LLM_API_KEY. A test setup can ask for CORTEX_EMBEDDING_PROVIDER=mock: mock vectors pin the data directory to mock, and recall on it is meaningless. Without an answer key, /v1/answer and /v1/compose return 503 ANSWER_UNAVAILABLE; everything else works.

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

Default configuration and the published benchmarks

The image's defaults:

Override anything at runtime with -e VAR=value or --env-file your.env. Nothing more is needed to run CortexDB continuously.

Our published scores were measured on CortexDB 0.14.2, blind, with a configuration that differs from those defaults:

The method, and how other systems' published numbers were measured, are at https://cortexdb.ai/benchmarks. To answer the way the LongMemEval run did:

CORTEX_ANSWER_MODEL=claude-opus-5-5
CORTEX_ANSWER_MAX_TOKENS=16000
CORTEX_ANSWER_THINKING_BUDGET=1024
CORTEX_ANSWER_THINKING_EFFORT=high
CORTEX_RERANKER_PROVIDER=cohere
CORTEX_RERANKER_API_KEY=...

That run also turned both answer filters off (CORTEX_QUANTITY_SUM_ENABLE=0, CORTEX_FACT_VALIDITY_FILTER=0) and the background scheduler off (CORTEX_SCHEDULER_DISABLE=1), and its harness, acting as the application, extracted facts from each conversation with gpt-4o-mini and stored them beside the turns. Ask us for the reproduction kit, which lists every setting.

Use the Python SDK

pip install cortexdbai
import os
from cortexdb import Cortex

with Cortex(
    "http://localhost:3141",
    bearer=os.environ["CORTEX_API_KEY"],
) as cortex:
    cortex.experience(
        "ws:demo",
        text="Priya at Acme Corp signed for 200 seats. Q3 close.",
        idempotency_key="getting-started-acme-q3-python",
        wait="indexed",
    )
    pack = cortex.recall(
        "ws:demo",
        query="How many seats did Acme sign for?",
    )
    print(pack["context_block"])

The npm package is also named cortexdbai:

npm install cortexdbai

Provider and feature configuration

The Docker image has an explicit OpenAI embedding endpoint, so it fails closed at startup when no embedding credential is available. OPENAI_API_KEY is the shortest path for the default configuration. A different OpenAI-compatible embedding service can be selected with CORTEX_EMBEDDING_URL, CORTEX_EMBEDDING_MODEL, CORTEX_EMBEDDING_DIMS, and CORTEX_EMBEDDING_API_KEY. Embedding identity and dimensions are durable data properties; do not change them for an existing data directory without a planned re-index or migration.

The image defaults /v1/answer to Anthropic. Set ANTHROPIC_API_KEY to use that route, or configure a different supported answer provider. Capture and recall do not require an answer-provider key.

Enrichment, fact extraction, semantic artifacts, and automatic derived-layer rebuilds are optional. They remain off until their provider and feature settings are configured; deterministic build endpoints remain available on demand. Enabling provider-backed features can improve derived context and answer quality, but also adds cost and asynchronous processing. See Production Deployment for the complete settings, operational limits, and backup requirements.

The mock embedding provider is intended only for plumbing tests. Its vectors do not provide meaningful semantic retrieval and must not be used to assess quality.

Authentication postures

CORTEX_API_KEY is one of three postures, and the one you do not choose is the one worth understanding.

What you setWhat the server does
CORTEX_API_KEY=<value>Bearer auth. The value itself is a working static operator credential (it is not membership-enforced — it reads and writes across every scope). Minted PASETO tokens and registered issuers work alongside it. A request with no bearer is 401 MISSING_TOKEN, including one that carries only an X-Cortex-Actor header.
No key, port reachable off-loopback (every docker run, because the image binds 0.0.0.0)The server generates a key on first boot rather than serving an open store, persists it at <data_dir>/generated_api_key, and prints it in the startup log (docker logs cortexdb). Auth is then exactly as above — you just did not choose the key.
No key, loopback bind, or CORTEX_INSECURE_NO_AUTH=1No authentication at all, and not merely anonymous access: a request carrying only X-Cortex-Actor: user:someone is served as that actor, with that actor's full capability set and scope access. CORTEX_DEPLOYMENT_PRESET does not restrict this — a keyless on_prem_enterprise boot accepts the same impersonation a keyless dev_local one does. It is a local development mode. Never expose that port.

So "set CORTEX_API_KEY to require bearer auth" is true, and the inverse is not: leaving it unset does not give you an anonymous read-only store, it gives you either a key you have to go and read out of the log, or a surface where the caller names their own identity. The boot log states which of the three you got — look for v1 surface: bind + auth posture, whose auth_enabled and unsigned_actor_accepted fields name the posture outright.

Data and operations

Container data lives in /data; the command above persists it in the cortexdb-data volume. Monitor /v1/admin/ready and take a verified backup before upgrading or changing durable feature settings.

Every memory belongs to a scope. Use separate tenant/workspace paths and signed authorization for multi-tenant deployments. The static CORTEX_API_KEY flow above is an operator-oriented local quickstart, not a replacement for a production identity system.

For the request and response schemas, see API Reference.

Linux binary

Download cortexdb-<version>-linux-<arch>.tar.gz and the .sha256 beside it from the customer portal, https://customer.cortexdb.ai (Releases), with your company's license; check it with sha256sum -c and extract it. The archives require glibc 2.39 or newer plus the OpenSSL 3 runtime (libssl.so.3), an Ubuntu 24.04-class userspace; the image file on the same page is the portable option for older or different host userspaces. An authenticated loopback launch is:

export OPENAI_API_KEY="..."
export CORTEX_API_KEY="$(openssl rand -hex 32)"
export CORTEX_LICENSE='...'
export CORTEX_V1_API_ADDR="127.0.0.1:3141"
./cortexdb 3141 ./data

No side-car assets are required. (Earlier revisions of this page said the binary expects assets/wordnet_synonyms.json alongside it — that is no longer true: nothing in crates/ reads a synonym file. The retrieval-side WordNet expansion went out with the legacy read path in commit 6910c8f1, and both assets/wordnet_synonyms.json and the scripts/generate_wordnet_synonyms.py that generated it have since been deleted from the tree; the Dockerfile comment that still names the file under /opt/cortexdb/assets/ is a leftover.) The one asset the image now carries is a bitemporal ontology example, and it is optional: the ontology is read from wherever CORTEX_BITEMPORAL_ONTOLOGY_JSON points — unset by default (crates/cortex-coordinator/src/bitemporal_bridge.rs:291) — with assets/pilot_ontology.example.json as the worked example.

Help