capsa.

open source · Apache-2.0 · Go · PostgreSQL + pgvector

An encrypted memory and knowledge base for AI agents.

capsa keeps OKF markdown bundles in PostgreSQL with pgvector, seals the content at rest with AES-256-GCM, and serves it to your agents over an MCP server: semantic search by meaning, in Russian and English, with no LLM in the retrieval path. Self-hosted, one binary, nothing to run but the database.

Works as Claude Code memory, Cursor memory, OpenCode memory — any MCP client.

The database holds
enc1:9f3a7c21:7KpQ4v…Lm0x
The agent reads
services/chat: the Telegram bridge
talks to the model upstream over
a 300 s long-poll…
A dump of the database is
sealed per value, bound to its row and column —
the vectors and the paths stay open
so filters still run.
Why

Four choices, not feature checkboxes.

Each one is something capsa deliberately does differently from the usual agent-memory stack.

01

Encrypted at rest

A dump of the database is not a knowledge leak. Concept text, chunks, versions, raw notes and even the agents' search queries are sealed per value with AES-256-GCM, each bound to its row and column. The vectors and the structural columns stay plaintext so filters still run. The embedding provider sees plaintext; the database does not — use a local endpoint and nothing leaves your host.

02

Postgres only

No Qdrant, no Redis, no object store. One database to back up, one thing to operate; the vectors sit beside the rows the filters need. Migrations are embedded in the binary and applied at start, under an advisory lock.

03

OKF is the format

A knowledge base is a directory of typed markdown files with YAML frontmatter and links — Open Knowledge Format. Readable by agents, diffable by people, exportable 1:1 from the database with capsa export. capsa is a consumer of the format, not a lock-in.

04

No LLM in the retrieval path

A search is a vector comparison and a sort: no model call per query, no tokens, milliseconds. Point CAPSA_EMBEDDINGS_BASE_URL at a local Ollama or TEI for local embeddings, or at OpenRouter for the best-measured model. An optional cross-encoder reranker can be switched on as a second stage.

Sealed
  • concept title, description, frontmatter, body, content
  • version content · chunk heading and text
  • episode (raw note) content · the text of every search query
Plaintext, by design
  • path, type, tags, status, trust tier, superseded_by
  • bundle slug, title, description · content hash
  • vectors · token hashes · audit and query-log metadata

With a key set the full-text index is off: search needs an embeddings endpoint. The server refuses a wrong key at startup. A lost key is a lost database — back it up like the data.

Quick start

Five minutes to a memory your agent can search.

One binary from GitHub Releases, go install github.com/svetlovtech/capsa/cmd/capsa@latest, or docker compose up -d (PostgreSQL + capsa on 127.0.0.1:8116).

# 1. a content key — keep it in a password manager before anything is sealed with it
capsa keygen

# 2. the key goes to capsa (a chmod 600 file via CAPSA_CONTENT_KEY_FILE is preferred)
export CAPSA_CONTENT_KEY='…'
export CAPSA_DATABASE_URL='postgres://capsa:capsa@127.0.0.1:5432/capsa?sslmode=disable'

# 3. check the database — --fix creates the pgvector extension when the role may
capsa doctor --fix

# 4. an embeddings endpoint (Ollama, local; bge-m3 takes no query instruction)
export CAPSA_EMBEDDINGS_BASE_URL=http://127.0.0.1:11434/v1
export CAPSA_EMBEDDINGS_MODEL=bge-m3 CAPSA_EMBEDDINGS_QUERY_INSTRUCTION=

# 5. run
capsa serve &

# 6. a token for an agent — shown once
capsa token create --name agent --scopes read,write

# 7. knowledge in, and check it was embedded
capsa import --dir testdata/smoke --slug smoke
capsa stats
Claude Code
claude mcp add --transport http capsa \
  http://127.0.0.1:8116/mcp \
  --header "Authorization: Bearer mem_…"
Cursor · Cline · Claude Desktop
{
  "mcpServers": {
    "capsa": {
      "type": "http",
      "url": "http://127.0.0.1:8116/mcp",
      "headers": {
        "Authorization": "Bearer mem_…"
      }
    }
  }
}

OpenCode uses {"type": "remote"} under mcp; some clients spell the type streamable-http. Then tell the agent: search the memory before you guess.

Retrieval quality

Measured, blind, on a real corpus.

75 questions written by a separate agent that knew nothing of the retrieval methods, over a real 899-file OKF bundle. File-level recall: a hit is the gold file in the top-k.

Strict gold set, 70 answerable questions — from docs/eval/models_strict.md. The question set is not published because it references private documents.
Method R@1 R@3 R@5 R@10 MRR@10 avg KB to answer
grep-literal 6%29%37%61%0.224420.7
Postgres full-text (fts-chunk) 36%56%69%81%0.4957.0
vector — bge-m3, local 60%86%91%96%0.7273.3
vector — qwen3-embedding-8b (default) 70%89%93%97%0.8042.2

On paraphrased questions the default finds the file 87% of the time against 33% for grep and 27% for full-text; an agent reads about 2–3 KB instead of 400 KB. Embedding the whole corpus costs about $0.01. Ten models compared, with paired confidence intervals, in docs/eval.

MCP tools

Seven tools over Streamable HTTP.

Every answer is JSON. Paths are OKF concept ids: the bundle-relative file path without .md. Tokens carry read, write or admin, optionally restricted to a list of bundles.

memory_search read
Semantic search over concepts: chunks with their concept path, score, status, trust tier and staleness, plus mode and an advisory low_confidence.
memory_get read
One concept — its whole markdown file, version, and the concepts linked to and from it.
memory_list read
The concepts of a bundle, optionally under a path prefix. To see what is there before searching.
memory_put write
Write or update a concept as a whole OKF file. A changed file is a new version; unchanged is a no-op. The tool for knowledge that must be found later.
memory_deprecate write
Retire a concept, optionally superseded by another. Deprecated concepts drop out of search.
memory_remember write
Append a raw note to the bundle's episode log. Append-only; not searched yet — good for session events, not for knowledge.
memory_whoami any
The token's name, scopes and the bundles it may touch.

Admin REST API under /api/admin (bundles, concepts, tokens, stats, query and audit logs). Health at /healthz and /readyz.

Give your agents a memory they can't leak.

Star or fork on GitHub ↗