Skip to content

Retrieval (RETRIEVE)

Retrieval is a relation source inside OSL-SQL: the RETRIEVE(...) table function. There is no separate /osl/retrieve endpoint any more — you SELECT from RETRIEVE(...) in a POST /osl/query body.

SELECT text, customer_id
FROM RETRIEVE(facet => 'meeting_transcripts',
query => 'european equity exposure',
top_k => 5)
RETRIEVE(facet => …, [query => …], [top_k => <page size>], [after => '<cursor>'])
  • facet — a declared UnstructuredFacet.
  • query — natural text; the engine embeds it with the facet’s declared model and orders by relevance. Without query the RETRIEVE is a listing.
  • top_k — the page size, bounded by the facet’s max_top_k and the policy’s page limits.
  • after — the opaque cursor of the previous page (see Pagination).
  • An optional WHERE over declared metadata (literal comparisons, IN, BETWEEN, combined with AND), doc_id IN (…) and MATCHES(…) narrows the read; it is applied by the governed store together with the ACL.

The SELECT may project text, declared metadata and derived operator outputs; doc_id, chunk_id, source, cite and redacted_fields are always preserved for grounding. The raw score used to rank the retrieval is not projectable and never served.

{
"text": "Anna wants to increase EU equity exposure […]",
"customer_id": "9c1e…f04a",
"cite": { "source": "gong://…", "doc_id": "meet-2026-05-08-7a3c", "chunk_id": "chk-…" },
"redacted_fields": []
}

A standalone RETRIEVE reads a governed subspace — the subject’s visible population (ACL, regions, redaction version, anchor scope) narrowed by the query’s own filters, doc_id IN (…) and MATCHES — and returns one page of it. Granting a facet grants reading the whole visible subspace, page by page; the policy’s limits size each page.

-- page 3 of a relevance-ordered chain: same query, plus the previous page's cursor
SELECT doc_id, sent_at, text
FROM RETRIEVE(facet => 'emails', query => 'tariff review discussion', top_k => 25, after => 'osl1.pQ3…')
WHERE sent_at >= '2026-04-01'

The response adds two blocks next to the passages:

"subspace": { "facet": "emails", "documents": 1500, "chunks": 4210,
"narrowed_by": ["filter"], "lance_version": "57", "scope": "facet" },
"served": { "page": 3, "page_size": 25, "order": "relevance", "order_exact": true,
"documents": 9, "chunks": 25, "tokens": 6080,
"cumulative": { "pages": 3, "chunks": 75, "tokens": 18240 },
"has_more": true, "complete": false, "next": "osl1.…",
"cappedBy": "policy.top_k", "cappedByPolicies": [{ "id": "pol-agents-reading", "title": "…" }] }
  • Page 1 pins the Lance version and counts the subspace once; subspace is repeated verbatim on every page, and rows ingested after page 1 are not in the chain. population (RFC 0006) stays and equals subspace.documents.
  • Next pages repeat the same query — everything but after and top_k identical — with after => '<served.next>'. The cursor travels only inside the OSL text; there is no body-level cursor field. Every page re-resolves the subject’s policy and runs the full governed read.
  • Relevance order is exact and independent of page size or replica. Above the engine’s exact-paging bound (200 000 chunks by default) a continued relevance read is refused with 413 E0519 — narrow the subspace or order by a column; a first page above it is served approximately and says so (order_exact: false, no next).
  • The receipt is honest. served.has_more says whether more exists; served.complete: true appears only on the last page of a chain that served every chunk of the subspace. cappedBy names the control that set the page size — it does not mean “you cannot see more”. If the ordered read and the governed count ever disagree, the page is refused (502 E0523).
  • The cursor is osl1. + an AES-256-GCM-sealed payload bound to the subject, the query, the policy snapshot and the pinned version. Clients must not parse or edit it. Invalid, another subject’s, or for another query → 400 E0530; expired, version erased or retired, policy or facet changed → 409 E0531 (restart from page 1). The precise reason is recorded in the audit only.

Without query =>, a RETRIEVE is a listing — no embedding is computed:

SELECT doc_id, sent_at, sender
FROM RETRIEVE(facet => 'emails', top_k => 25)
WHERE sent_at >= '2026-04-01'
ORDER BY sent_at DESC

ORDER BY names one column: doc_id, ingested_at or a scalar-indexed metadata field that is cleartext on every row the subject may read (400 E0518 otherwise, audited as a deny); default doc_id ASC, NULLs last, with (doc_id, chunk_id) as the tie-breaker. ORDER BY together with query => is E0511. A listing that does not project text serves no passage text and consumes none of the text budget — this is how “which emails?” is answered before reading them. The governed schema lists the columns each subject may order by (orderable_fields).

MATCHES is a deterministic full-text predicate in the WHERE of RETRIEVE, osl.documents.<facet> and the job relations. It narrows the visible population to a set — it never ranks, never scores and never returns text by itself.

SELECT doc_id, text
FROM RETRIEVE(facet => 'emails', query => 'tariff review discussion', top_k => 10)
WHERE MATCHES(subject_line, 'tarifa') AND mailbox = 'ventas'
SELECT count(*) AS emails
FROM osl.documents.emails
WHERE MATCHES('"tariff review" OR (tariff AND (review OR revision))')
  • MATCHES('<query>') searches the passage text; MATCHES(<field>, '<query>') a declared string metadata field. Either needs a declared full-text index on that column (E0511 otherwise).
  • Upper-case AND / OR / NOT, "phrases", parentheses and word~1 (edit distance 1). Adjacent words must all match. NOT needs a positive clause in the same group. No prefix, wildcard or regex atoms. Fixed analysis: lower-case, ASCII folding, no stemming, no stop words. Grammar limits apply (512 characters, 32 words/phrases, …; E0511 beyond).
  • It searches the subject’s own redaction-version table and its own index, with the same governed prefilter and ACL — a name the redaction removed is not found. MATCHES(<field>, …) needs the field in cleartext for the subject (E0518). The set is exhaustive or refused (E0523).
  • No fallback: without a usable full-text index on the served version, the query is refused with 503 E0533 — never a substring scan, another version’s index or vector similarity.

A policy’s facet grant sizes one page with topK, maxChunks and maxTokens (plus an optional default pageSize). A request above the page maximum is served at the maximum with cappedBy. Because a client can now continue page after page, these limits no longer bound total volume — a policy that needs to bound volume or pace adds a reading window (window: {tokens, seconds}), a cumulative per-subject, per-facet budget:

  • A page that would exceed a window is shrunk (cappedBy: "policy.window"); one that cannot hold a single passage is refused with 429 E0532 and a Retry-After header.
  • served.cumulative_window reports consumption per window policy.
  • With a window configured and its ledger unavailable, text reads of that facet fail closed with 503 E0534.

See Write access policies for how limits compose.

  • Redaction version. The facet is served at the subject’s required redaction version — exact-or-deny. Redacted metadata fields are listed in redacted_fields.
  • Row-level ACL. Deny-by-default: an actor with no grant gets zero passages.
  • Visibility is pushed into every read — the full-text match set, the ordered stream, the vector search and the subspace count — so a row the subject cannot read costs no time, fills no budget and crowds no page.
  • Isolation. The query opens only the selected version’s Lance table — no side-channel to less-redacted vectors.