# empremta documentation

empremta is long-term memory for assistants, as a service: an HTTP API, an MCP server and a
TypeScript SDK, on Postgres with pgvector, with the models you choose (any OpenAI-compatible API,
local ones included, Gemini or Claude). It keeps what each person tells your assistant and what
reaches them (email, events, tasks, documents), and hands it to the model on every turn.

- Connect a coding agent (Claude Code, Codex, Grok, Antigravity, any MCP client): [agente.md](agente.md)
- The HTTP API: [api.html](api.html) to read it, [openapi.json](openapi.json) (OpenAPI 3.1) for tools
- Source code: https://github.com/vicktor/Empremta

The hosted service is at `https://empremta.bauber.xyz` (API at `/v1`, MCP at `/mcp`, panel at
`/panel/`); a self-hosted one serves the same paths at its own address.

## Concepts

**Product and person.** One service holds several products (a personal assistant, a support chat, a
coding agent…). Each product has a schema and API keys (`emp_…`). Every call is scoped to one person
of one product: the product comes from the key, the person from `subject` in the request body
(their id in your product). A person's id never goes in a URL.

**Facts, memories and the literal trace.**

- *Facts* are what must never be forgotten ("my accountant is Pedro García", "no meetings before
  ten"). They are injected whole on every turn, without searching. A closed vocabulary per product
  (the schema) keeps the same thing from being filed under a new name.
- *Memories* (episodes) are the long tail: how the meeting went, a name mentioned in passing. They
  are found by similarity (vectors), by association (people and things they name) and by words.
- *The literal trace*: every message is kept verbatim and searchable, so what the extractor missed
  can still be found.

**Nothing is overwritten.** A new value leaves the old one in the history. Every fact carries a
literal quote, the message it came from and who said it; no quote, no fact. The merge is decided by
code, not by the model. When two versions clash, both stay as a discrepancy and the assistant asks.

**Who said it.** Only the person's own words become facts about them. What the assistant says never
does. A third party (an email sender, a document) signs with their name, can only state what the
schema lets them about the person, and cannot replace what the person said.

**Writing never waits for a model.** Messages and items are stored and queued; extraction, merging
and embedding run in a background queue with retries and one atomic write per job.

## Using it from a product

### TypeScript SDK

```ts
import { Empremta } from '@empremta/sdk';
import { claudeChat } from '@empremta/sdk/claude';   // or openaiChat, geminiChat

const memory = new Empremta({ baseUrl: 'https://empremta.bauber.xyz', apiKey: 'emp_…' });
const chat = claudeChat(new Anthropic(), { model: 'claude-sonnet-5-5' });
const { text } = await memory.subject('laura').turn({ text, conversation: { externalId: 'chat-1' }, chat });
```

`turn` gets the context, runs the tool loop (forcing a search in the first round when the message is
a question) and stores the turn afterwards.

### HTTP API, from any language

Once: `GET /v1/tools` returns the memory guide (`guide`, for the system prompt), the tools as JSON
Schema (`tools`, valid for OpenAI, Gemini and Claude) and the loop limits (`loop`).

On every turn:

```bash
# 1. The context, at the end of the system prompt, after the guide.
curl https://empremta.bauber.xyz/v1/context -H "authorization: Bearer $KEY" -H 'content-type: application/json' -d '{
  "subject": {"externalId": "laura", "displayName": "Laura", "locale": "en", "timezone": "Europe/Madrid"},
  "conversation": {"externalId": "chat-2026-10-16"},
  "query": "When did my accountant say the quarterly return is due?"
}'

# 2. The product's tool loop: run each tool call the model makes.
curl https://empremta.bauber.xyz/v1/tools/recall -H "authorization: Bearer $KEY" -H 'content-type: application/json' \
  -d '{"subject": {"externalId": "laura"}, "args": {"query": "Pedro quarterly return"}}'

# 3. After replying: the question and the answer. Filed in the background.
curl https://empremta.bauber.xyz/v1/messages -H "authorization: Bearer $KEY" -H 'content-type: application/json' -d '{
  "subject": {"externalId": "laura"},
  "conversation": {"externalId": "chat-2026-10-16"},
  "messages": [
    {"role": "user", "text": "When did my accountant say the quarterly return is due?"},
    {"role": "assistant", "text": "July 20, as Pedro told you on June 18."}
  ]
}'
```

When the message is a question, force a tool call in the first round (`tool_choice: "required"`
with OpenAI-compatible APIs, `functionCallingConfig.mode = ANY` with Gemini). Without it, with
something similar in front of it, a model answers "I don't know" without looking.

**What arrives another way**: `POST /v1/items` with `kind` (`email`, `event`, `task`, `ticket`,
`document`, `note`), `externalId`, `title`, `body`, `author`, dates and status. Sending the same item
again does nothing; when it changes, it is a new version and the old one stops showing.

**The memory's language**: the `locale` the product sends when writing, or learned from what the
person writes. Context labels come in that language.

The tools the model can call: `recall` (search everything), `read_conversation`, `review_period`
(what happened between two dates), `fact_history` (how a fact changed) and `read_item` (an email or
a document).

## MCP

`/mcp` exposes the same memory to any agent over Streamable HTTP, stateless, with the protocol
revisions 2026-07-28 and 2025: the five tools plus `memory_context` (the whole context) and
`remember` (an assistant note: searchable, never a fact). The memory guide ships as the skill
`memory`.

A person connects their own client with a **person token** (`emps_…`): the product requests it with
`POST /v1/subject-tokens` (or `createToken()` in the SDK). It opens only that person's memory, is
valid only at `/mcp`, expires after 90 days by default and can be revoked for good. The product key
is never handed to anyone.

```json
{ "mcpServers": { "empremta": { "type": "http", "url": "https://empremta.bauber.xyz/mcp",
  "headers": { "Authorization": "Bearer emps_…" } } } }
```

### OAuth: claude.ai, ChatGPT, Cursor

Clients that cannot set a header connect with OAuth 2.1, when the service has a public address
(the hosted one has it; a self-hosted one needs `EMPREMTA_PUBLIC_URL`). Give the client only the MCP URL (in claude.ai: Settings, Connectors, Add
custom connector; in ChatGPT, a connector in developer mode). The client discovers the authorization
server from the `401` at `/mcp` (RFC 9728 and RFC 8414), identifies itself with a client metadata
document or by registering (RFC 7591), and opens `/oauth/authorize`: a page that says who is asking
and where it returns, where the person pastes their `emps_…` token once. The client then gets its
own access and refresh tokens, valid only for that person and that `/mcp`, and only for as long as
the person token is. Public clients with PKCE S256; refresh tokens rotate, and a reused code or
refresh token revokes the whole grant.

### Plugins for Claude Code and Codex

A plugin, the same code for both, loads each repository's memory when a session starts, saves what
is new after each turn and indexes the code (`connectors/claude-code` in the repository). In Codex
the commands are skills (`$empremta:index`, `$empremta:import`, `$empremta:global`); it is built with
`npm run build:codex` in `connectors/`, installed with `codex plugin marketplace add` and
`codex plugin add empremta@empremta`, the service and key are set once with
`node connectors/claude-code/main.ts key <url>` (the key goes to the system keychain), and its three
hooks are approved in `/hooks`.

Sessions from before the plugin was installed come in by hand, from a terminal in the repository:
`node connectors/claude-code/main.ts history [--days N] [--dry-run]` (with `codex` before `history`
when it is set up for Codex). It reads the Claude Code and Codex sessions of that repository and its
worktrees, from the account's own folders and never from a folder the environment names, shows how
many sessions and messages there are and roughly how many tokens archiving them takes, and sends
nothing until a code is typed. It saves what the hooks would have saved (only what the person typed
counts as theirs, secrets struck out), and running it twice sends nothing twice.

## Connectors

Separate processes that save through the SDK: files (PDF, DOCX, text, images), Gmail and Google
Calendar (read-only), ICS calendars (iCloud, Outlook, Fastmail, Proton), a Telegram bot, and any MCP
server. They strike out secrets before sending and never duplicate anything when a pass repeats.

## Running it

Node 24, Postgres with pgvector, a model that generates and one that embeds (same provider or two):

```bash
export EMPREMTA_ADMIN_KEY=$(openssl rand -base64 32) EMPREMTA_DB_PASSWORD=$(openssl rand -hex 24)
docker compose up            # Postgres and the server, ports bound to 127.0.0.1

curl -X POST localhost:8080/admin/tenants -H "authorization: Bearer $EMPREMTA_ADMIN_KEY" \
  -H 'content-type: application/json' -d '{"name":"My assistant","schemaId":"personal"}'
# → {"tenant":{…},"apiKey":"emp_…"}   shown once; only its hash is stored
```

Models: `EMPREMTA_MODELS` (who generates: `openai`, `gemini`, `claude`) and `EMPREMTA_EMBEDDINGS`
(who embeds: `openai`, `gemini`). With an OpenAI-compatible local server (LM Studio, Ollama, vLLM,
llama.cpp) serving a chat model and an embedding model, nothing leaves your machine. All settings:
`.env.example` in the repository.

Schemas included: `personal` (a personal assistant), `support` (a support chat with human agents;
people of the same account share its memory) and `coding` (a software project).

## Privacy and rights

- Export and erase everything about a person (`/v1/export`, `/v1/erase`). Nothing else deletes.
- The request log never stores anyone's text: kind, duration and outcome, kept 30 days by default.
- Per-product limits (requests per minute, people, messages, documents and tokens per month).
- The hosted version keeps data in the EU and calls models only in EU regions; or run it on your own
  server.

## License

The server: Business Source License 1.1 (free in production for non-commercial use or under one
million dollars of yearly revenue, except to offer it as a memory service; each version becomes
Apache 2.0 after four years). The SDK: MIT.
