AI Knowledge Core Concepts
Documents
Section titled “Documents”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.
Fields
Section titled “Fields”| Field type | type: | Value comes from |
|---|---|---|
| Property | property, or omitted | The incoming document, by field name |
| Computed | computed | A JavaScript expression evaluated when the document is indexed, with the incoming document bound as env |
Every field has a datatype:
datatype | Holds |
|---|---|
string | Text. config.length bounds it |
int | A whole number |
double | A floating-point number |
bool | true or false |
byte | Bytes, sent as base64 |
floatvector | An 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("-")The document id
Section titled “The document id”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.
Backends
Section titled “Backends”A backend is a named store a product declares, of one type and one engine, holding one or more documents:
type | backend | A document it holds must have |
|---|---|---|
lexical | meilisearch | No floatvector field |
semantic | pgvector | At least one floatvector field |
semantic | milvus | Exactly 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.
Scores
Section titled “Scores”Results come back best first, each with a score where higher is a better match.
| Search | score | Also returned |
|---|---|---|
| Lexical | Meilisearch’s ranking score, from 0 to 1 | |
Vector, cosine | Cosine similarity: 1 minus the cosine distance | distance, metric |
Vector, ip | The inner product | distance, metric |
Vector, l2 | 1 / (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.
Filters
Section titled “Filters”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"] } } ] }}| Form | Meaning |
|---|---|
{"<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.
Access rules
Section titled “Access rules”A document’s access: block uses the Data access grammar, with expr
expressions:
actionsgates each operation for the caller:readto search,createandupdateto index,deleteto delete. An operation the block gives no rule is refused.rlsdecides which documents a caller may see (read) or write (create,update,delete), from the document’s fields and the caller’s identity, such asrow.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.
Tenancy
Section titled “Tenancy”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