AI Knowledge Configuration
Configuration has two halves. The product declares what is searched: documents, the
backends that hold them, and sync mappings, in its search/ folder. The tenant configures
where each backend runs: connection settings and, for pgvector, a datastore.
The search/ folder
Section titled “The search/ folder”Every .yaml and .yml file in the product’s search/ folder is read, and the files are
taken together as one set. A file may hold any of the three top-level keys:
| Key | Holds |
|---|---|
documents | Document definitions: fields, key and access |
backends | Backend declarations and the documents each holds |
sync | Mappings that keep a document in step with a Data entity |
The set is validated whole when it loads: a key the service does not read, a name used twice,
a backend that lists an undeclared document, or a document that does not fit its backend, is
reported with every other problem in one error, and the tenant keeps serving the set it had
until the folder is fixed. kis spec validate checks these files against the same grammar
before you ship them.
Declaring documents
Section titled “Declaring documents”documents: - name: pages fields: - { name: id, datatype: string, key: true } - { name: title, datatype: string, index: true } - { name: team, datatype: string } - name: slug type: computed datatype: string expression: env.title.toLowerCase().split(" ").join("-") access: actions: read: { language: expr, expression: '"search" in user.roles' } create: { language: expr, expression: '"editor" in user.roles' } update: { language: expr, expression: '"editor" in user.roles' } delete: { language: expr, expression: '"editor" in user.roles' } rls: read: { language: expr, expression: 'row.team in user.roles || "admin" in user.roles' }| Field key | Meaning |
|---|---|
name | The field name: a letter or _, then letters, digits or _, up to 63 characters |
datatype | string, int, double, bool, byte or floatvector |
type | property (the default) or computed |
key | The key field, whose value is the document id. Exactly one per document, a string or an int. A field named id must be the key |
index | Searchable as text on a lexical backend |
expression | A computed field’s JavaScript expression, with the incoming document as env |
config.length | The longest string a string field holds |
config.dimension | A floatvector field’s dimension, 1 to 16000 |
config.index | A floatvector field’s index: algorithm (hnsw, ivfflat or none), distance_metric (l2, cosine or ip), and m and ef_construction for hnsw or lists for ivfflat |
A vector document:
documents: - name: notes fields: - { name: id, datatype: string, key: true } - { name: owner, datatype: string } - { name: body, datatype: string } - name: embedding datatype: floatvector config: dimension: 1536 index: { algorithm: hnsw, distance_metric: cosine, m: 16, ef_construction: 64 } access: actions: read: { language: expr, expression: '"search" in user.roles' } create: { language: expr, expression: '"search" in user.roles' } update: { language: expr, expression: '"search" in user.roles' } delete: { language: expr, expression: '"search" in user.roles' } rls: read: { language: expr, expression: 'row.owner == user.id || "admin" in user.roles' } create: { language: expr, expression: 'row.owner == user.id || "admin" in user.roles' } update: { language: expr, expression: 'row.owner == user.id || "admin" in user.roles' } delete: { language: expr, expression: 'row.owner == user.id || "admin" in user.roles' }Set dimension to the dimension of the embedding model you use, and distance_metric to the
metric it is trained for.
Access rules
Section titled “Access rules”access takes the actions and rls tiers of the Data access grammar,
written as expr expressions. An operation with no actions rule is refused, so declare all
four. Rules read the caller as user (user.id, user.roles) and, in rls, the document as
row. A row rule is compiled when the set loads, and a rule that cannot be applied to the
document’s fields refuses the set.
Declaring backends
Section titled “Declaring backends”backends: - name: site type: lexical backend: meilisearch documents: - name: pages - name: kb type: semantic backend: pgvector documents: - name: notes| Key | Meaning |
|---|---|
name | The backend name the routes use |
type | lexical for meilisearch; semantic for pgvector and milvus |
backend | meilisearch, pgvector or milvus |
documents | The documents it holds, by name |
config.database | Milvus only: the Milvus database to use |
Choosing an engine
Section titled “Choosing an engine”| Engine | Choose it when |
|---|---|
meilisearch | Text search over titles, bodies, names and codes |
pgvector | Vector search beside data you already keep in PostgreSQL |
milvus | Vector search over collections larger than you want in PostgreSQL |
Tenant configuration
Section titled “Tenant configuration”The tenant’s configuration names where each engine runs, under backend:, and gives pgvector
its datastore:
# the tenant's configuration nodebackend: meilisearch: url: https://meili.internal:7700 key: <the Meilisearch API key> milvus: url: milvus.internal:19530datastores: search: dbpool: vectorsdbpools: vectors: type: postgres dbserver: pg.internal:5432 database: search dbuser: search password: <a vault reference>| Key | Used by |
|---|---|
backend.meilisearch.url, backend.meilisearch.key | Every meilisearch backend of the tenant |
backend.milvus.url | Every milvus backend of the tenant |
datastores.search | Every pgvector backend of the tenant: a PostgreSQL datastore with the vector extension created (CREATE EXTENSION vector) |
The service creates each tenant’s indexes, collections and tables itself: a Meilisearch index or Milvus collection on first use, and the pgvector tables when the definitions load.
Keeping a document in step with an entity
Section titled “Keeping a document in step with an entity”A sync mapping feeds a document from a Data entity’s committed changes:
sync: - entity: note # a Data entity with an events: block backend: kb document: notes fields: owner: created_by # document field: entity field| Key | Meaning |
|---|---|
entity | The Data entity whose events feed the document |
backend, document | The backend and the document it holds |
fields | Document field to entity field. A field not listed is read from the entity field of the same name |
A create, update or restore of the entity indexes the document, and a delete or purge removes it. The document id is the entity field the key is read from, or the entity’s own id.
Three pieces connect the two services:
- The entity declares an
events:block, so Data publishes its changes. See subscriptions. - Data’s boot configuration names the search service as a delivery target:
events.targets.<name>.urlis the search service’s/sync/seshatroute,events.targets.<name>.secretthe signing secret, andtopicsthe entity’s topic. - The search service’s boot configuration holds the same secret as
sync.secret.
# the search service's boot configurationsync: secret: <a vault reference to the shared secret> maxskew: 5m| Key | Default | Meaning |
|---|---|---|
sync.secret | none | The secret deliveries are signed with. The sync route accepts deliveries once it is set |
sync.maxskew | 5m | How far a delivery’s signed timestamp may be from now |
loadtenants | none | Tenant keys whose configuration is loaded at start |
Deliveries are at least once. A delivery the service has already applied is answered as a duplicate, and a change the definitions cannot apply is answered as skipped, so the outbox does not retry it.
- API: every route, request and error
- Operations: reloads, storage names and what to watch