Skip to main content
The Memory API manages long-term semantic memory for users. Unlike session history (which stores the conversation transcript), memories capture specific user facts and preferences that should persist across sessions — for example, “User prefers dark mode” or “User works in the finance department.” These facts are stored as vector embeddings in PostgreSQL and retrieved by semantic similarity during agent runs. All endpoints scope their operations to a specific user via the userId parameter. When userId is omitted, the server resolves it from the authenticated principal. All requests require a valid bearer token in the Authorization header.

Add a memory

Stores a new fact in the semantic memory store for the authenticated user. The content is embedded and indexed in pgvector for future retrieval.
string
required
The fact or preference to store. Write it as a natural language statement, e.g. "User prefers responses in bullet-point format.". The content field must not be blank.
string
Confirmation that the memory was saved.
Example response

Search memories

Performs a semantic vector search across the user’s memory store and returns the most relevant facts as plain strings. The search uses embedding similarity — you do not need exact keyword matches.
string
required
The natural language query to search for relevant memories.
string[]
Array of memory content strings, ranked by semantic similarity to the query.
Example response

Delete memories

Deletes a specific list of memories by their document IDs. Pass an array of IDs in the request body. Returns 204 No Content on success.
string[]
required
Array of memory document IDs to delete.
Returns 204 No Content with an empty body on success.

Optimize memories

Triggers an asynchronous background job that consolidates and deduplicates the user’s memory store using an LLM. Redundant or contradictory memories are merged or removed. Returns a jobId immediately.
string
The user whose memories to optimize. Defaults to the authenticated principal when omitted.
string
The background job identifier. The optimization runs asynchronously — no webhook or polling endpoint is currently exposed for this job type.
Example response
Memory optimization runs asynchronously. If an optimization pass is already in progress for the same user when you call this endpoint, the system returns immediately without queuing a duplicate job.

Memory statistics

Returns aggregate statistics about the user’s memory store, such as total memory count and approximate token usage.
string
The user whose statistics to retrieve. Defaults to the authenticated principal.
Example response

Memory topics

Returns a list of high-level topic clusters derived from the user’s memories. Topics are generated and cached by the memory optimization routine.
string
The user whose topics to retrieve. Defaults to the authenticated principal.
string[]
Array of topic label strings, e.g. "work preferences", "communication style", "domain expertise".
Example response
Topics are refreshed by the optimize endpoint. If topics are stale or empty, trigger POST /api/memories/optimize to regenerate them from the current memory store.