Learn · Models & search
Vector & hybrid search
Declare vector and full-text indexes on your types. Searches apply the caller’s access rules during the scan.
- API
POST /search- CLI
- —
- In the schema
ext::ai::index,ext::ai::hybrid_search
Vector and full-text indexes#
using extension napalm; enables the AI extension, so every project can attach deferred semantic vector indexes (ext::ai::index) to any object type alongside built-in full-text indexes (fts::index). Schemas may also declare using extension ai; explicitly. Full-text indexes update inside the write transaction, while deferred vector indexes compute embeddings asynchronously in the background through the project’s model provider. See Models and embeddings to configure model providers and spend caps.
- Deferred embedding
- Writes commit immediately while Napalm embeds indexed text in the background.
- In-scan policy check
- PostgreSQL checks access policies during scoring so top-k returns k readable rows.
- Hybrid RRF fusion
- Reciprocal rank fusion merges semantic similarity and full-text rank in one query.
In the notes schema below, Note declares both a vector index and a full-text index on its text fields.
using extension auth;using extension ai;using extension napalm;using future simple_scoping; module default { type Note { required title: str; body: str; deferred index ext::ai::index(embedding_model := 'text-embedding-3-small') on (.title ++ ' ' ++ (.body ?? '')); index fts::index on ( fts::with_options(.title ++ ' ' ++ (.body ?? ''), language := fts::Language.eng) ); access policy anyone_can_read allow select; }}Choose between vector similarity, lexical full-text search or hybrid fusion based on the query shape.
| Index or function | Purpose | When to use |
|---|---|---|
deferred index ext::ai::index | Deferred semantic vector similarity | When to useConceptual questions, paraphrases and multilingual recall across notes, tickets or passages. |
index fts::index | Synchronous full-text index updated at commit | When to useExact identifiers, SKUs, function names, error codes and quoted phrases. |
ext::ai::hybrid_search | Reciprocal rank fusion (RRF) | When to useQueries that combine conceptual similarity and exact keyword matching in one ranking. |
Semantic and hybrid search queries#
ext::ai::search ranks an indexed type by semantic proximity, while ext::ai::hybrid_search fuses semantic similarity and exact lexical terms using reciprocal rank fusion (RRF). Both functions return only the rows the caller may read.
Policy-checked hybrid search
Search checks select policies during scoring and merges vector distance with keyword rank.
Deployed and ad-hoc statements sent to the API may call both search functions, plus ext::ai::to_context to inspect the text an index embeds. No other ext::ai function is callable from API statements.
with found := ( select ext::ai::search(Note, <str>$words) order by .distance limit 5)select (for hit in found union { title := hit.object.title, distance := hit.distance })order by .distanceDirect search calls in EdgeQL follow three rules.
- The query
- Pass text as
<str>$wordsfor the index’s model to embed, or pass a precomputed vector as<array<float32>>$embedding. - Order and limit
- Wrap the search in a
selectwithorder by .distanceand alimit. Forext::ai::hybrid_search, sort withorder by .score desc. The limit caps the rows returned. - Not in a schema function
- A schema function cannot wrap a search because function arguments are not query parameters. Deploy the statement as a query file instead.
The search route and MCP search#
POSThttps://<label>.napalmdata.com/search
Every project exposes a POST /search HTTP endpoint, a matching client.search() SDK method and an MCP search tool. The endpoint embeds the query string, runs a hybrid RRF search against a type with both an ext::ai::index and an fts::index, and returns matches under the caller’s select access policies.
Built-in search endpoint
HTTP clients, generated SDKs and MCP agents call the same policy-checked search route.
Pass the indexed type name, query string, output fields and row limit in the JSON request body.
{ "type": "Note", "query": "Q3 enterprise pricing tiers", "fields": ["title"], "limit": 10}A project without a model provider for the type’s index returns 409 model_not_configured. The route never silently degrades to keyword-only search.
POST /search accepts only callers permitted by your branch’s passthrough mode, configured with napalm endpoint or in the console. User sessions receive 403 deployed_query_required when passthrough is keys, and all callers receive 403 deployed_query_required when passthrough is none (or when a service key or agent grant is restricted to named deployed queries). These callers search through a deployed query. Write the search as a query file, as in Semantic and hybrid search queries, and deploy the file with your own filters.
See Project API: POST /search for complete request and response fields. In-app AI copilots covers pairing hybrid retrieval with POST /ask and dry-run mutation approvals.
Access checks and index size#
Callers reach embeddings through each record according to its access policies, and Napalm evaluates those policies during candidate scoring. Standalone vector stores fetch a global top-k first and strip unauthorized hits afterward, so restricted rows in the top ranks leave the caller with fewer than k results.
In-scan access checks
Vector scoring checks select policies inline so callers receive k permitted matches.
Transaction-consistent results
Searches read the active SQL snapshot so revoked records vanish immediately.
Inline policy filtering keeps search accurate across small workspaces and large indexes alike.
- Small workspaces
- When access rules narrow a caller to a single user, project or small workspace, search scores every permitted row directly so no match is missed.
- Fresh rows
- Search reads the query’s own transaction snapshot, so a newly written record appears in semantic results as soon as its embedding commits.
- Any index size
- An index scales from a handful of rows past 100 million vectors with no schema changes.
- Same-commit revocation
- Unsharing or deleting a record removes it from vector search, full-text search, live subscriptions and EdgeQL queries in the same commit.
For distance metrics (Cosine, InnerProduct, L2) and custom dimensionality, see the AI extension reference and Models and embeddings.