Query
The structured-read primitive. Where search ranks rows by semantic similarity
over the vector index, query hits your source database directly through the
bridge and returns exact matches. Use it for admin list views, filter-driven
pages, reporting exports, and anywhere real-time source data beats ranked
relevance.
Flip Config between JSON and the Console lens editor, Explorer for the where-predicate view, Call between Client / HTTP / WebSocket / cURL.
Play with query on real data at demo.semilayer.com/query — build a where clause, pick ordering, scroll through the rows.
What query does (and doesn't)
- Does: equality + range predicates,
orderBy,limit/offset+ cursor pagination, field projection withselect, row-level security viaX-User-Token, join expansion viainclude. - Doesn't: semantic ranking, fuzzy matching, relevance scores. That's
search.
grants.query is required. query() is disabled by default on every
lens. Set grants: { query: 'public' | 'authenticated' | ... } to opt in. The
Beam codegen respects this — if the grant isn't set, no query() method is
emitted for that lens.
How it compares to search
search | query | |
|---|---|---|
| Reads from | Vector index | Source DB via bridge |
| Freshness | At last ingest | Real-time |
| Ranks by | Vector similarity | orderBy (your call) |
| Query shape | Natural language | where predicate |
| Latency | ~10–50ms | Depends on source |
| Cost | Index lookup only | A round-trip to your DB |
They're complementary. A common pattern: use query to narrow the candidate
pool to a few thousand rows, then use search to rank within that pool. See
Search — Filters & mode.
Three shapes from one primitive
- Exact list —
where: { category: 'footwear' }. Equality filters. Fast, obvious, the most common shape. - Operator filter —
where: { rating: { $gte: 4 }, price: { $lt: 100 } }. Ranges,$in, inequality. - Paginated scroll —
limit+cursorfor datasets that don't fit in one response. See Pagination.
Where to start
- Quickstart — enable
grants.queryon an existing lens and make your first call. - Predicates — the full
wheregrammar: operators, arrays, limits. - Pagination —
offsetvscursor, andstream.queryfor large exports. - Recipes — admin list view, reporting export, filter-driven browse, activity timeline.