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.
The form
Section titled “The form”SELECT text, customer_idFROM RETRIEVE(facet => 'meeting_transcripts', query => 'european equity exposure', top_k => 5)RETRIEVE(facet => …, [query => …], [top_k => <page size>], [after => '<cursor>'])facet— a declaredUnstructuredFacet.query— natural text; the engine embeds it with the facet’s declared model and orders by relevance. Withoutquerythe RETRIEVE is a listing.top_k— the page size, bounded by the facet’smax_top_kand the policy’s page limits.after— the opaque cursor of the previous page (see Pagination).- An optional
WHEREover declared metadata (literal comparisons,IN,BETWEEN, combined withAND),doc_id IN (…)andMATCHES(…)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": []}SELECT text, SIMILARITY(text, 'churn risk') AS churn_similarityFROM RETRIEVE(facet => 'meeting_transcripts', query => 'renewal', top_k => 3)SIMILARITY/SUMMARIZE/… are projection operators
— unary maps over already-governed passages. SIMILARITY computes another
cosine against a concept: without an alias it stays internal; with AS <out>
it is served.
Pagination
Section titled “Pagination”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 cursorSELECT doc_id, sent_at, textFROM 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;
subspaceis repeated verbatim on every page, and rows ingested after page 1 are not in the chain.population(RFC 0006) stays and equalssubspace.documents. - Next pages repeat the same query — everything but
afterandtop_kidentical — withafter => '<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, nonext). - The receipt is honest.
served.has_moresays whether more exists;served.complete: trueappears only on the last page of a chain that served every chunk of the subspace.cappedBynames 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.
Listings ordered by a column
Section titled “Listings ordered by a column”Without query =>, a RETRIEVE is a listing — no embedding is computed:
SELECT doc_id, sent_at, senderFROM RETRIEVE(facet => 'emails', top_k => 25)WHERE sent_at >= '2026-04-01'ORDER BY sent_at DESCORDER 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).
Narrowing by text: MATCHES
Section titled “Narrowing by text: MATCHES”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, textFROM RETRIEVE(facet => 'emails', query => 'tariff review discussion', top_k => 10)WHERE MATCHES(subject_line, 'tarifa') AND mailbox = 'ventas'
SELECT count(*) AS emailsFROM osl.documents.emailsWHERE MATCHES('"tariff review" OR (tariff AND (review OR revision))')MATCHES('<query>')searches the passagetext;MATCHES(<field>, '<query>')a declared string metadata field. Either needs a declared full-text index on that column (E0511otherwise).- Upper-case
AND/OR/NOT,"phrases", parentheses andword~1(edit distance 1). Adjacent words must all match.NOTneeds 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, …;E0511beyond). - 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.
Page sizes and reading windows
Section titled “Page sizes and reading windows”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 with429 E0532and aRetry-Afterheader. served.cumulative_windowreports 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.
How retrieval is governed
Section titled “How retrieval is governed”- 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.
Related
Section titled “Related”- The query surface (OSL-SQL) — all forms, document analytics and jobs.
- Access & capabilities — grants, redaction versions, MEET.
- For a governed preview of a few chunks, use
POST /osl/sample.