Skip to content

Memory Engine API

Document ID: MEM-002
File Path: docs/06-memory-engine/memory-api.md
Version: 1.0.0
Status: Draft
Owner: AI Platform Team
Last Updated: 2026-06-27


This document defines the external contract of the Memory Engine — the API every caller uses to store and retrieve memory, independent of the underlying storage backends.

The contract is exposed over REST (HTTP/JSON) and gRPC with identical semantics, and maps directly onto the MemoryProvider trait from the Memory System.


  1. One schema for all memory types; the backend tier is chosen by the Engine.
  2. Every record is scoped by tenant and a scope (private → public).
  3. Reads return relevance score and the matched version.
  4. Embeddings are generated by the Engine; callers send text, not vectors (vectors optional for advanced callers).
  5. The contract is versioned under /v1.

MethodPathPurpose
POST/v1/memoriesStore a memory
GET/v1/memories/{id}Fetch a memory by id
PATCH/v1/memories/{id}Update (creates a new version)
DELETE/v1/memories/{id}Delete / tombstone
POST/v1/memories/queryRetrieve by hybrid search
GET/v1/memories/{id}/versionsList versions
POST/v1/memories/batchBulk store
GET/healthz, /readyz, /metricsOperations

gRPC exposes Store, Get, Update, Delete, Query, ListVersions, BatchStore on the MemoryEngine service.


{
"id": "mem_01H...",
"tenant": "acme",
"scope": "project",
"project": "support-bot",
"agent": "order-assistant",
"type": "semantic",
"title": "Refund policy",
"content": "Refunds are processed within 14 days of purchase.",
"tags": ["policy", "refunds"],
"labels": { "source": "handbook", "confidence": "high" },
"metadata": { "url": "https://intranet/handbook#refunds" },
"version": 1,
"created_at": "2026-06-27T10:00:00Z",
"updated_at": "2026-06-27T10:00:00Z"
}
FieldNotes
typeOne of working, conversation, workflow, episodic, semantic, shared, organizational, archived
scopeprivate, agent, workflow, project, organization, public
contentText; the Engine embeds it unless embedding is supplied
embeddingOptional caller-supplied vector (skips embedding generation)
versionServer-assigned; increments on update

Request:

{
"scope": "project",
"project": "support-bot",
"type": "semantic",
"title": "Refund policy",
"content": "Refunds are processed within 14 days of purchase.",
"tags": ["policy", "refunds"]
}

Response:

{ "id": "mem_01H...", "version": 1, "embedded": true, "tier": "warm" }

If embedding generation is deferred (Gateway busy), embedded is false and the record becomes semantically searchable once the async embed completes.


The query API drives the Retrieval and Ranking pipelines.

{
"query": "how long do refunds take?",
"scope": ["project", "organization"],
"project": "support-bot",
"types": ["semantic", "episodic"],
"strategy": "hybrid",
"filters": {
"tags": ["refunds"],
"labels": { "confidence": "high" },
"created_after": "2026-01-01T00:00:00Z"
},
"ranking": {
"weights": { "relevance": 0.6, "recency": 0.2, "importance": 0.2 }
},
"limit": 10,
"token_budget": 1500,
"include_graph": true
}
FieldMeaning
strategyvector, keyword, hybrid, or graph (see Retrieval)
filtersMetadata constraints applied before/after search
ranking.weightsOverrides default scoring weights (see Ranking)
token_budgetEngine compresses results to fit (see Compression)
include_graphExpand results with related graph entities

{
"results": [
{
"id": "mem_01H...",
"type": "semantic",
"title": "Refund policy",
"content": "Refunds are processed within 14 days of purchase.",
"version": 1,
"score": 0.94,
"score_breakdown": { "relevance": 0.91, "recency": 0.40, "importance": 0.80 },
"match": "hybrid"
}
],
"graph": {
"entities": [{ "id": "policy:refunds", "type": "policy" }],
"edges": [{ "from": "policy:refunds", "to": "team:finance", "rel": "owned_by" }]
},
"usage": { "embeddings": 1, "compressed": true, "returned_tokens": 1280 },
"degraded": false
}

degraded: true indicates retrieval fell back (e.g. keyword-only because the vector store was unavailable) — recall may be reduced.


PATCH /v1/memories/{id} creates a new version rather than mutating in place. Prior versions remain retrievable via GET /v1/memories/{id}/versions. Updates re-embed and re-index automatically.


DELETE performs a soft delete (tombstone) by default so audit and version history are preserved; a hard=true query parameter permanently purges the record and its index entries (subject to retention policy and permissions).


Reads respect the caller’s permissions across scopes (aligned with Memory System §24):

private < agent < workflow < project < organization < public

A query may request multiple scopes; the Engine returns only records the principal is authorized to read and records this in the audit log.


{
"error": {
"code": "forbidden",
"message": "Principal may not read organization-scoped memory.",
"type": "client_error",
"retryable": false
}
}
CodeHTTPRetryableMeaning
unauthenticated401noMissing/invalid credentials
forbidden403noScope/policy denied
not_found404noUnknown memory id
invalid_request400noSchema validation failed
embedding_unavailable202yesStored; embedding deferred
storage_unavailable503yesBackend temporarily unavailable
quota_exceeded429yesTenant memory quota hit

  • Writes accept an Idempotency-Key to dedupe client retries.
  • POST /v1/memories/batch ingests up to 1,000 records per call; partial failures are reported per-item without failing the whole batch.

/v1 is additive-compatible; breaking changes introduce /v2. Storage/tier changes never affect the contract version.




VersionDateDescription
1.0.02026-06-27Initial Memory Engine API