docs

Quick start

Run the whole stack locally with Docker, create a user, and send a first conversation through the proxy.

  1. 1
    Copy the environment file.
    terminal
    cp .env.example .env
  2. 2
    Set a database password and an extraction provider. Leave ENGRAM_SERVICE_KEY and the Clerk keys empty for a self-hosted start.
    .env
    POSTGRES_PASSWORD=replace_with_a_strong_password
    EXTRACTION_PROVIDER=openai
    OPENAI_API_KEY=your_key_here
  3. 3
    Start the stack.
    terminal
    docker compose up -d
  4. 4
    Create a user. Save the returned api_key. It is shown once; Engram stores only a hash.
    terminal
    curl -X POST http://localhost:8000/users \
      -H "Content-Type: application/json" \
      -d '{"external_id": "test_user_1"}'
  5. 5
    Send the first conversation through the proxy.
    terminal
    curl -X POST http://localhost:8000/v1/chat \
      -H "Content-Type: application/json" \
      -H "X-Engram-Key: <api_key>" \
      -H "X-Engram-User-ID: test_user_1" \
      -H "X-Engram-Provider: openai" \
      -d '{"model": "gpt-4o-mini", "messages": [{"role": "user",
           "content": "I prefer FastAPI for backend development."}]}'
  6. 6
    Review what it learned. After a few seconds, new memories wait in the pending queue.
    terminal
    curl 'http://localhost:8000/memories?status=pending' \
      -H "X-Engram-Key: <api_key>"
  7. 7
    Approve a memory before expecting the proxy to retrieve it.
    terminal
    curl -X PATCH http://localhost:8000/memories/<memory_id> \
      -H "Content-Type: application/json" \
      -H "X-Engram-Key: <api_key>" \
      -d '{"status": "approved"}'
noteMemories you create by hand are approved by default. Extraction proposes changes to existing memories as revisions; accept one to replace the fact, and earlier versions stay available to restore.

Dashboard login

The dashboard uses Clerk for sign-in. Set the same ENGRAM_SERVICE_KEY on the api and dashboard services; the dashboard uses it server-side to issue an Engram key for the signed-in user without exposing it to the browser.

.env
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
ENGRAM_SERVICE_KEY=generate_a_long_random_value

Without Clerk, paste an ek_… key in Settings. The browser keeps it in local storage, and every dashboard page uses it.

Proxy

Send chat requests to POST /v1/chat, or the OpenAI-compatible POST /v1/chat/completions, with your Engram key and a provider header. Engram retrieves, injects, forwards, and returns the provider's response immediately; extraction happens afterwards.

HeaderPurpose
X-Engram-KeyYour workspace API key (ek_…)
X-Engram-User-IDWhose memories to use
X-Engram-Provideropenai, anthropic, gemini or ollama
X-Engram-NamespaceThe project to read and write; defaults to default

Set stream: true for server-sent events. Tokens flow as they arrive, and extraction starts once the stream closes.

terminal
curl -N -X POST http://localhost:8000/v1/chat \
  -H "Content-Type: application/json" \
  -H "X-Engram-Key: ek_your_key_here" \
  -H "X-Engram-User-ID: test_user_1" \
  -H "X-Engram-Provider: openai" \
  -d '{"model":"gpt-4o-mini","stream":true,
       "messages":[{"role":"user","content":"What stack should I use?"}]}'

Memories API

RouteDoes
GET /memories?status=pendingList memories waiting for review
POST /memories/searchSearch; the response includes context, the exact block the proxy would inject
PATCH /memories/{id}Edit or approve a memory
GET /memories/{id}/historyEvery revision of a fact
GET /memories/{id}/sourceThe conversation it came from
DELETE /memories/{id}Forget it; saved retrieval text is redacted
GET /memories/exportExport everything
GET /logs/{id}One retrieval: the query, the memories, their scores

MCP server

The engramd package on npm runs an MCP server with seven tools, scoped to one project at a time. It speaks stdio by default; --transport http serves Streamable HTTP at POST /mcp on port 3000.

claude_desktop_config.json
{
  "mcpServers": {
    "engram": {
      "command": "npx",
      "args": ["-y", "engramd"],
      "env": { "ENGRAM_API_KEY": "ek_your_key_here" }
    }
  }
}
Claude Code
claude mcp add engram -e ENGRAM_API_KEY=ek_your_key_here -- npx -y engramd

Set ENGRAM_API_URL to point at your own API, and ENGRAM_NAMESPACE to pick a project.

search_memoriesadd_memorylist_memories
update_memorydelete_memorycapture_conversation
get_retrieval_log

Auto capture

capture_conversationlets an assistant store memories without you saying "remember this". It sends the latest user message and reply, and Engram extracts only durable facts: preferences, projects, skills and corrections. Greetings, one-off questions and the assistant's own claims are skipped. Add an instruction like this to your client:

system prompt
Before answering when user context may matter, search Engram for relevant memories.
After each meaningful exchange, call capture_conversation with the user message,
assistant response, source client name, and session id.

Projects & orgs

Namespaces split one user's memories into projects. Pass X-Engram-Namespace on proxy requests and ?namespace= on REST calls; the default is default. Organizations group users with owner, admin and member roles; memories tagged with an org_id are visible to every member.

terminal
# create an org (you become the owner)
curl -X POST http://localhost:8000/orgs \
  -H "X-Engram-Key: ek_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"Acme"}'

# add a member by external_id
curl -X POST http://localhost:8000/orgs/<org_id>/members \
  -H "X-Engram-Key: ek_..." \
  -H "Content-Type: application/json" \
  -d '{"external_id":"teammate_42","role":"member"}'

Retrieval

Engram builds a query from up to six recent user messages, embeds it with BAAI/bge-small-en-v1.5, and scores approved memories in the user's workspace and namespace in one SQL query.

SettingDefaultEffect
RETRIEVAL_KEYWORD_WEIGHT0.3Full-text rank, so exact names count
RETRIEVAL_RECENCY_HALF_LIFE_DAYS30Light boost for recent facts
RETRIEVAL_THRESHOLD0.3Skip weaker memories unless pinned
RETRIEVAL_RELATIVE_CUTOFF0.08Inject only near the top score

Run python -m api.eval.retrieval_eval before changing a weight. On the golden set it scores recall@5 0.969 and precision 0.745, injecting 1.8 memories per query.

Extraction

Extraction runs as a Postgres-backed job with bounded retries. When a new fact lands near an existing memory (cosine above RECONCILE_THRESHOLD, default 0.6), one extra model call decides: add it, propose an update, flag a conflict, or discard it as redundant. Updates and conflicts need approval. Disable with ENABLE_RECONCILIATION=false.

Deploy

API

Run the FastAPI image on any container host. Set DATABASE_URL, CORS_ORIGINS, ENGRAM_SERVICE_KEY and ENGRAM_PROVIDER_KEY_ENCRYPTION_KEY. Hosted users save their own provider key per workspace.

Database

PostgreSQL with the vector extension. Local Docker Postgres and Supabase both work; the schema applies on API startup.

Dashboard

Deploy dashboard/ to Vercel with NEXT_PUBLIC_API_URL pointing at the API, and add its origin to the API's CORS_ORIGINS.

Supabase

Enable the vector extension, put the connection string in DATABASE_URL, and apply the schema. Prefer the Session pooler; with the Transaction pooler on port 6543, set DATABASE_STATEMENT_CACHE_SIZE=0.

terminal
docker compose -f docker-compose.supabase.yml run --rm api python -m api.apply_schema

Limits

Hosted workspaces have fixed limits; requests over one return 429 with X-Engram-Quota-* headers. Self-hosters can raise them freely.

SettingDefault
WORKSPACE_MEMBER_LIMIT5
WORKSPACE_MEMORY_LIMIT2,000
WORKSPACE_MONTHLY_RETRIEVAL_LIMIT10,000

Troubleshooting

SymptomCheck
The dashboard says the key is invalidThe browser saved the same ek_… key as your client, and the API's CORS_ORIGINS includes the dashboard origin.
The MCP server shows no toolsRestart the client and check that ENGRAM_API_KEY is set in its MCP config.
No memories appearNew facts wait as pending. Approve them on the review screen, or add one by hand.
The proxy fails provider requestsCheck the provider key in Settings and that X-Engram-Provider matches it.
Streaming hangs behind a reverse proxyDisable response buffering. Engram already sends X-Accel-Buffering: no for nginx.