Memory (memory-service)¶
memory-service is the memory service of the Taimen platform: a typed knowledge graph and a vector index on top of a single PostgreSQL, which answer questions with citations to sources and assemble ready-to-use context for agents. This section is for integrators who write knowledge to memory and read it, and for administrators who deploy and maintain the service.
Purpose¶
The service does three things:
- Stores knowledge (articles, documents, facts, events from external systems) as a graph of entities and relations (PostgreSQL tables) and as text fragments with embeddings (pgvector).
- Finds what is relevant with hybrid search (vector + full-text search + graph neighbors), with optional reranking and answer synthesis by an LLM.
- Assembles context: a structured
ContextPackwithin a token budget, where each element carries provenance (where it came from) and an explanation of why it was included.
The main product requirement is a source in every answer: by source_path
and node_key, a consumer can always show the original document a hint came
from (GET /api/brain/sources/{natural_key}).
The service is product-neutral: its code knows no domains. The entity kinds and relations of a specific subject area are described as data, in domain packs (see Knowledge model).
Place in the platform¶
flowchart LR
subgraph CP[Control Plane]
API[control-plane-api<br/>POST /api/v1/context<br/>/api/v1/knowledge/*]
CA[context-adapter<br/>outbox → observations]
end
subgraph MEM[memory-service :8077]
BRAIN["/api/brain/*<br/>query · recall · search<br/>retain · documents · sources"]
MAPI["/api/memory/*<br/>observations · context<br/>reconcile · packages"]
end
DB[(memory-db<br/>PostgreSQL 16<br/>pgvector + pg_trgm)]
IAM[iam-service<br/>JWKS]
POL[external PDP<br/>optional]
APP[Applications and demos<br/>static key or IAM token]
CA == "observations:batch" ==> MAPI
API == "context, reconcile,<br/>packages" ==> MAPI
APP ==> BRAIN
BRAIN ==> DB
MAPI ==> DB
MEM -. "signature check" .-> IAM
MEM -. "principal visibility" .-> POL
- Control Plane is the main consumer. Its
context-adapterdelivers core domain events to memory as observations (POST /api/memory/observations:batch), andcontrol-plane-apiassembles the combined work context (the core'sPOST /api/v1/contextcallsPOST /api/memory/context) and publishes client knowledge snapshots (POST /api/memory/reconcile, kind packages). Details are in Control Plane context. - Applications (chatbots, prompters, consoles) call
/api/brain/*directly with a static key or an IAM access token. -
IAM issues tokens with audience
memory-service; the service verifies their signature against JWKS. -
An external PDP (experimental, off by default) determines which namespaces and scopes a particular person or agent can see.
Memory is not the source of truth for operational state
Control Plane holds the authoritative state of tasks, runs, and approvals.
Memory holds evidence and knowledge, and the application's current state
can be passed into a request as ephemeral_context: it takes part in
context assembly but is not stored.
What the service consists of¶
| Part | What it is | Entry point |
|---|---|---|
| HTTP service | FastAPI: /api/brain/*, /api/memory/*, /healthz |
platform-memory-serve |
| MCP server | Graph tools for agents (stdio or streamable HTTP) | platform-memory-mcp |
| CLI | Schema initialization, vault loading, queries, traces | cb |
| Client | platform-memory-client: MemoryClient / AsyncMemoryClient |
directory services/memory-service/client |
| Database | PostgreSQL 16 + pgvector + pg_trgm; the graph is ordinary tables (MEM-ADR-023) | image memory-db |
Additional surfaces, the administrative console /console and the public demo
showcase /demo, are off by default and are not part of the consumer contract
(see Configuration).
Key concepts¶
| Concept | In short | More |
|---|---|---|
| Namespace | A hard knowledge base boundary: data of different namespaces never overlaps | Namespaces and access |
| Scope | A visibility label type:id inside a namespace (workspace:<id>, principal:<id>) |
Namespaces and access |
| Node | A graph entity with a natural_key, type, title, and provenance |
Knowledge model |
| Chunk | A text fragment with an embedding and a link to its source | Knowledge model |
| Observation | An immutable piece of evidence from an external system | Knowledge ingestion |
| Fact | A graph edge with a validity interval and an evidence class | Knowledge model |
| ContextPack | Assembled context with sections, sources, and a trace | Search and context |
Deployment as part of the platform¶
In the deploy/local/compose.yml, memory belongs to the core profile as two services:
| Service | Image | Port | Purpose |
|---|---|---|---|
memory-db |
memory-db (built from services/memory-service/infra/memory-db) |
compose network only | PostgreSQL 16 + pgvector + pg_trgm, database company_brain |
memory-service |
memory-service (build context is the superproject root) |
127.0.0.1:${MEMORY_HOST_PORT:-18001} → 8077 |
HTTP API |
The image build context is the superproject root because the service pulls in
the neighboring platform-auth-sdk as a path dependency. Memory is not
published through the edge proxy: platform services call it at the internal
address http://memory-service:8077.
Quick check after startup:
curl -fsS http://127.0.0.1:18001/healthz
# {"ok": true, "graph": "company_brain", "nodes": 123, "chunks": 456}
curl -fsS -H "Authorization: Bearer $MEMORY_API_KEY" \
http://127.0.0.1:18001/api/brain/health
# the same, but with a token check
/healthz requires no authorization and returns 503 if the database is
unavailable.
Operating principles¶
- Knowledge base isolation. Each request works in explicitly specified namespaces; access to them is checked against the token's grants. See Namespaces and access.
- Idempotent writes. Sending the same article (
external_id), the same document (natural_key), the same event (source.system+stream+external_id), or the same snapshot (snapshotId) again creates no duplicates. - Deletion with audit. Every deletion is recorded as a
deleteevent in the audit trail of its knowledge base and can be reconstructed withGET /api/brain/trace/{trace_id}. - An LLM is optional. Writing, projection, hybrid search, context assembly,
and traces work without a generative model. An LLM is needed only for
answer synthesis (
synthesize: true), reranking, and entity extraction from unstructured text. Embeddings are needed for the vector channel; for tests, there are offline providersfake/echo. - Personal data protection. When protection is on, tokens without
clearance get masked results, and every release of unmasked personal data is
logged as a
pii_accessevent.
What next¶
- Knowledge model: how the graph, chunks, facts, and provenance work.
- Namespaces and access: knowledge base names, keys, IAM tokens, visibility.
- Knowledge ingestion: retain, documents, observations, snapshots, deletion.
- Search and context assembly: hybrid search, reranking, ContextPack.
- API: reference for all routes.
- Configuration:
CB_*variables, providers, operations.