current_message and the retrieval switches to semantic mode, returning memories most relevant to what was just said.
Request
Headers
| Name | Required | Description |
|---|---|---|
X-API-Key | Yes | Your MemLayer API key (ml_live_xxx) |
Query Parameters
Load memories belonging to this user. Must exactly match the value used when storing.
Load memories associated with this agent. Must exactly match the value used when storing.
Maximum number of memories to return. Range: 1–50. Unlike search, this endpoint can return up to 50 results — useful for building a rich system prompt.
Optional. The user’s first message in this session. When provided, MemLayer runs a semantic search using this text and returns memories most relevant to the opening message. When omitted, memories are ranked by importance and recency instead.
Response
Success — 200
Array of memory objects, ordered by relevance (semantic mode) or by importance + recency (default mode). See Search Memories for the full
MemoryOut field reference. Note that score and score_detail are only populated when current_message is provided.Number of memories returned in this response.
The
top_k value applied to this request.Always
0 for the context endpoint — pagination is not supported here.Errors
| Code | Meaning |
|---|---|
401 | Invalid or missing X-API-Key |
403 | Account suspended |
422 | Validation error — check parameter types |
Notes
context() vs recall() — when to use each
context() vs recall() — when to use each
These two endpoints serve different moments in a conversation:
The recommended pattern is to call
GET /memories/context | GET /memories/search | |
|---|---|---|
| When | Session start | Mid-conversation |
| What you have | Nothing yet, or first message | A specific user query |
| Returns | Broad background context | Targeted, query-specific results |
| Default ranking | Importance + recency | Hybrid semantic score |
context() once at session start to build the system prompt, then call recall() on each user turn to fetch memories relevant to that specific message.Handling new users
Handling new users
If the user has no memories yet,
context() returns an empty memories array and total: 0. Your agent should handle this gracefully rather than injecting an empty block into the system prompt:Choosing top_k for system prompts
Choosing top_k for system prompts
Context windows are finite. A
top_k of 10–15 memories is usually enough to give your agent useful background without padding the prompt unnecessarily. If you’re building a memory browser or audit UI, use GET /memories instead — it supports pagination and returns all memories, not just the most relevant ones.