Retrieval is how stored memory is recalled and turned into usable context. This document defines the retrieval contract: what MUST be observable, and what is left to the implementation.
SGM standardizes what is returned, not how it is ranked. Storage, indexing, embedding, and ranking algorithms are implementation concerns. Two conforming implementations MAY rank the same query differently and both be correct — as long as both return records satisfying the query’s stated filters.
A retrieval takes a query and returns a result set.
| Field | Type | Meaning |
|---|---|---|
scope |
object | Restrict to a scope (required for isolation — see scopes.md) |
text |
string | Free-text query (implementation-defined matching) |
ids |
string[] | Exact record IDs |
types |
string[] | Filter by record type |
tags |
string[] | Filter by tag (AND or OR is implementation-defined; MUST be documented) |
limit |
integer | Max records to return |
offset |
integer | Pagination offset |
At least one of text, ids, types, or tags SHOULD be present.
{
"records": [ /* memory records (see memory.md) */ ],
"total": 42,
"limit": 10,
"offset": 0,
"truncated": false
}
total is the count of records matching the query before limit/offset.truncated is true if records were omitted due to limit.A conforming implementation MUST guarantee:
id in scope is retrievable
by {ids:[id], scope} with the same content it was stored with.S MUST NOT return records outside
S unless cross-scope retrieval is explicitly requested and permitted (see
scopes.md).type it was stored with.metadata and unknown types round-trip unchanged
(see memory.md).text matching is implementation-defined. An implementation MAY use:
The only protocol requirement is that a record whose content matches the query is eligible to be returned. Ranking order is not standardized.
Records MAY reference content stored outside the record (see memory.md). Two reference behaviors:
read. Advertised by the references capability.A consumer MUST treat an unresolvable reference as valid: the reference object itself is the shared contract.
Retrieval produces records; context is the assembled, consumable object handed to another tool. See context.md. The mapping from result set to context is part of retrieval: a conforming implementation MUST be able to emit a context object containing the retrieved records with their scope and provenance intact.
limit + offset MUST be supported for deterministic paging.offset exceeds total, an empty records array is returned with
total intact — this is not an error.limit is capped by the implementation; the cap MUST be discoverable via
capability discovery (see capabilities.md).