Skip to content
Talk to our solutions team

AI Knowledge Core Concepts

A document is a named record type a product declares for search: its fields, its key and its access rules. Every indexed item is an instance of one document, and every search targets one document on one backend.

Documents are declared in the product’s search/ folder (see Configuration), and each tenant of the product gets its own storage for each one.

Field typetype:Value comes from
Propertyproperty, or omittedThe incoming document, by field name
ComputedcomputedA JavaScript expression evaluated when the document is indexed, with the incoming document bound as env

Every field has a datatype:

datatypeHolds
stringText. config.length bounds it
intA whole number
doubleA floating-point number
booltrue or false
byteBytes, sent as base64
floatvectorAn embedding: config.dimension numbers, 1 to 16000

index: true makes a field searchable as text on a lexical backend; a document that declares no such field is searched across all of its fields. Every field except a floatvector or byte field is available to filters, on every backend. A floatvector field is indexed by its config.index block: the algorithm (hnsw, the default, ivfflat or none) and the distance metric (l2, the default, cosine or ip).

A computed field is how one searchable value is built from several:

- name: slug
type: computed
datatype: string
expression: env.title.toLowerCase().split(" ").join("-")

Each document declares exactly one key field (key: true), a string or an int, and its value is the document id. When the incoming document leaves the key field empty, the request’s docid is used, and when both are empty a new ULID is generated. An id is 1 to 128 letters, digits, - or _.

Indexing a document whose id already exists replaces it. Use a stable identifier from your own system as the id, so a re-index updates documents in place.

A backend is a named store a product declares, of one type and one engine, holding one or more documents:

typebackendA document it holds must have
lexicalmeilisearchNo floatvector field
semanticpgvectorAt least one floatvector field
semanticmilvusExactly one floatvector field, and no byte field

A backend may hold several documents, and a document may be held by several backends it fits, such as a pgvector backend and a Milvus one. For text search and vector search over the same records, declare two documents, one with the text fields on a lexical backend and one with the embedding on a semantic backend, and index both under the same ids. The routes name the backend and the document, so a caller always says which one it searches.

Results come back best first, each with a score where higher is a better match.

SearchscoreAlso returned
LexicalMeilisearch’s ranking score, from 0 to 1
Vector, cosineCosine similarity: 1 minus the cosine distancedistance, metric
Vector, ipThe inner productdistance, metric
Vector, l21 / (1 + the Euclidean distance)distance, metric

The vector field’s declared metric decides how both the index and the score are computed, so choose the metric your embedding model is trained for, usually cosine.

A search, and a bulk delete, take a filter over the document’s fields other than its floatvector and byte fields:

{
"filter": {
"$and": [
{ "team": "docs" },
{ "published": { "$gte": 20260101 } },
{ "owner": { "$in": ["u1", "u2"] } }
]
}
}
FormMeaning
{"<field>": <value>}Equal; null matches an empty field
{"<field>": {"$eq"|"$ne"|"$gt"|"$gte"|"$lt"|"$lte": <value>}}Comparison
{"<field>": {"$in"|"$nin": [<value>, ...]}}One of, none of
{"<field>": {"$null": true|false}}Empty, or not
{"<field>": {"$between": [<low>, <high>]}}Inclusive range
{"$and": [...]}, {"$or": [...]}, {"$not": {...}}Combinations

Several keys in one object, and several operators on one field, all have to hold. The filter is applied inside the search, together with the caller’s row rule, so limit counts only matching documents the caller may read. A filter nests at most 16 levels, holds at most 256 conditions, and an $in list holds at most 1000 values.

A document’s access: block uses the Data access grammar, with expr expressions:

  • actions gates each operation for the caller: read to search, create and update to index, delete to delete. An operation the block gives no rule is refused.
  • rls decides which documents a caller may see (read) or write (create, update, delete), from the document’s fields and the caller’s identity, such as row.owner == user.id || "admin" in user.roles.

A search applies the read row rule as part of the query on every backend. An index request checks the create row rule on each incoming document and, for an id that already exists, the update row rule on the stored one, before anything is written. A delete only removes documents the delete row rule admits.

Every request names its tenant through the four CEPT headers. Each tenant has its own index, collection or table for each document, and its definitions come from its own product, so one deployment of the search service serves every product’s tenants. The same document id in two tenants is two documents.

  • Configuration: declaring documents, backends and sync
  • API: every route, request and error