Schema (Config)
The sl.config.ts file is the single source of truth for your SemiLayer setup. It declares
your sources (database connections), lenses (intelligent collections), and auth configuration.
File Location
SemiLayer searches for sl.config.ts (or sl.config.js) starting from the current working
directory and walking up to the filesystem root. Place it at the root of your project.
Top-Level Shape
Sources
A Source declares a database connection. The key becomes the source name referenced by Lenses.
In production (cloud deployments), the connection string is stored encrypted on the
SemiLayer platform via semilayer source add --connection-string "...". The config file
then only needs the bridge name — the worker resolves credentials from the platform at runtime.
Lenses
A Lens is a declaration of intelligence over a database table. The key becomes the lens name (and the property name on the generated Beam client).
Fields
Fields declare what to read from the source and how to expose it. The key becomes the output field name.
Field Types
| Type | TypeScript output | Use for |
|---|---|---|
text | string | Free-form strings, descriptions, titles |
number | number | Integers, floats, prices |
boolean | boolean | Flags, toggles |
date | string | ISO date / datetime strings |
json | unknown | Arbitrary JSON objects / arrays |
enum | string | One of a declared set of values |
relation | string | number | Foreign key references |
Marking Fields for Embedding
Add searchable: true to include a field in the semantic search embedding:
Fields with higher weight are repeated in the embedding input, boosting their relevance signal in search results.
Column Mapping (from)
When the source column name differs from your desired output field name:
When a field is built from multiple source columns:
Transforms
Apply a transform chain to the resolved value before indexing:
Available Transforms
| Transform | Parameters | What it does |
|---|---|---|
toString | — | Convert to string |
toNumber | — | Parse as number |
toBoolean | — | Parse as boolean |
toDate | format? | Parse as date |
round | decimals?, mode? | Round number |
trim | — | Trim whitespace |
lowercase | — | Convert to lowercase |
uppercase | — | Convert to uppercase |
default | value | Replace null/undefined |
split | separator | String → array |
join | separator | Array → string |
truncate | length | Limit string length |
replace | pattern, replacement | Regex replace |
custom | body | Inline function body (advanced) |
Facets
Facets declare which semantic operations are enabled on the Lens.
Sync Configuration
Keep the index fresh as your source data changes.
syncInterval — Periodic incremental sync. Valid values:
'1m' | '5m' | '15m' | '30m' | '1h' | '6h' | '24h'
changeTrackingColumn — The column used to detect new/updated records during
incremental sync. Defaults to updated_at.
Access Rules
See Auth & RBAC for the full access rule reference.
Auth
Configure JWKS validation for user JWTs. This enables 'authenticated' rules and
function rules that receive user claims.
Complete Example
Drift Detection
When you run semilayer push, SemiLayer computes a hash of your Lens config and
compares it against the last pushed hash. If the config changed, it reports a drift:
Changes to fields (adding, removing, or changing a searchable field) require a rebuild
to generate fresh embeddings. Changes to rules, facets.mode, or syncInterval take
effect immediately without a rebuild.