// Schema for the {{projectName}} AI backend. // // Tables are auto-discovered: every exported `table(...)` in this file // (or any `*.entity.ts` / `*.schema.ts` file) is registered by // `voltro dev` — no manual barrel. `actors` + `tenants` are the // framework's core tables: the built-in `audit()` / `tenant()` / // `softDelete()` mixins reference them, so they must be declared (the // CLI wires them into the mixin registry once it finds them). // // The agent thread tables (`agent_threads`, `agent_messages`) are // auto-provided + auto-migrated by the framework because this app ships // an `*.agent.tsx` — you do NOT declare them here. import { databaseHandle, id, table, text, vectorEmbedding, type InferRow, } from '@voltro/database' // ---------- Core tables (required by the audit / tenant mixins) ---------- export const actors = table('actors', { id: id(), kind: text().oneOf(['user', 'serviceAccount', 'apiKey', 'system']), displayName: text().nullable(), }) export const tenants = table('tenants', { id: id(), name: text(), }) // ---------- Knowledge base ---------- // // `vectorEmbedding({ from: 'body', ... })` adds an `embedding` vector // column + an HNSW index over it, and registers a re-embed hook that // calls `@voltro/ai`'s `embed` on every insert/update of `body` — so a // plain `ctx.store.insert('docs', { title, body })` auto-embeds, no app // code. Query it with `database.docs.nearestNeighbours(queryString, k)` // (the string overload is valid because this table carries the mixin — // the runtime embeds the query string before searching). // // `dimensions` MUST match the model's output width. 1536 = // text-embedding-3-small (OpenAI). If you point AI_MODEL at a different // embedding model, change this to match (e.g. 768 / 3072) or the vector // width won't line up. export const docs = table('docs', { id: id({ prefix: 'doc' }), title: text(), body: text(), }) .with( vectorEmbedding({ from: 'body', model: 'text-embedding-3-small', dimensions: 1536, }), ) export type Doc = InferRow export const database = databaseHandle({ actors, tenants, docs })