@exulu/backend source. For constructor options, see Configuration.
Constructor
Search
search()
Runs vector, full-text, or hybrid retrieval over the context’s chunks, with RBAC filtering, score cutoffs, and chunk expansion.Natural-language query. Embedded via the context’s embedding model for
cosineDistance and hybridSearch. If a queryRewriter is configured, it runs first.Keywords for full-text matching (
tsvector and hybridSearch).Filters on item columns.
SearchFilters is an array of objects mapping field names to operators: eq, ne, in, contains, and, or — plus lte/gte for numbers and dates. Pass [] for none.Filters on chunk columns, same operator shape. Pass
[] for none.When set, access control is applied — only chunks from items the user may read (by
rights_mode, ownership, role, or team) are returned.Role ID used alongside
user for access control."cosineDistance" (vector similarity), "tsvector" (full-text), or "hybridSearch" (both combined).Sort configuration; pass
undefined for relevance ordering.Where the search originated, recorded in usage statistics — for example
"api" or "agent".Maximum results. When falsy, falls back to
configuration.maxRetrievalResults (default 10).Page number for pagination.
Per-call override of the configured score cutoffs.
Per-call override of the configured chunk expansion window.
Entity-layer filter:
{ entityIds?: string[]; entities?: { type: string; name: string }[]; mode?: "any" | "all" }. With "any" (default) a chunk must mention at least one of the entities; with "all", all of them. Requires the entity layer.Precomputed query embedding — skips re-embedding the query. Must come from this context’s embedding model.
Matched chunks. Each carries
chunk_content, chunk_index, chunk_id, chunk_source, chunk_metadata, timestamps, item_id, item_external_id, item_name, item timestamps, the method-specific scores (chunk_cosine_distance, chunk_fts_rank, chunk_hybrid_score), and — with the entity layer on — chunk_entities.{ name, id, embedder } of the searched context.Present when the entity layer is on: entities recognized in the query, how often they matched, and their top co-occurring entities.
Item management
createItem()
Inserts (or upserts) an item, then runs the processor and embedding generation as configured.Item data matching the context’s schema.
json field values that are objects or arrays are stringified automatically; tags arrays are joined to a comma-separated string.The app’s
ExuluConfig — needed for storage access in processors and chunkers.User ID for tracking and access control.
Role ID for tracking and access control.
When
true, requires external_id or id on the item and merges on conflict — external_id takes precedence. Throws when neither is present.Per-call override of
configuration.calculateVectors: true forces embedding generation, false suppresses it.An object containing only the generated
id — re-fetch with getItem() if you need the full row.Comma-separated job IDs when the processor and/or embedder ran in queue mode.
Embeddings are generated when the context has an embedder,
generateEmbeddingsOverwrite is not false, and either the override is true or calculateVectors is onInsert / always. The processor runs when its trigger is onInsert, onUpdate, or always.updateItem()
Updates an existing item byid, then runs the processor and embedding generation as configured.
Must include
id plus the fields to update. Throws when no row matches.The app’s
ExuluConfig.User ID for tracking.
Role ID for tracking.
true forces embedding generation, false suppresses it; otherwise calculateVectors of onUpdate / always applies.true forces the processor to run, false suppresses it; otherwise any non-manual trigger applies.The item as it was before the update — the method returns the previously fetched record, not the merged result.
Comma-separated job IDs when the processor and/or embedder ran in queue mode.
deleteItem()
Deletes an item and its chunks. Accepts eitherid or external_id.
Object with
id or external_id. When only external_id is given, the row is resolved first; throws when not found.ID of the deleted item.
getItem()
Fetches a single item byid or external_id, with its chunk count.
Object with
id or external_id.The item with all columns plus a
chunksCount property.getItems()
Fetches items with optional filters, field selection, and access control.Filter array in the same operator shape as
search() filters, for example [{ category: { eq: "guide" } }].Columns to return. Defaults to all.
When set, access control is applied and only rows the user may read are returned. When omitted, no access control is applied.
Role ID folded into the access-control check alongside
user.deleteAll()
Deletes every item, every chunk, and — when the entity layer is on — every entity in the context.Embeddings
embeddings.generate.one()
Generates embeddings for one item: loads the full record, chunks it, embeds the chunks through LiteLLM, and replaces the item’s rows in the chunks table. When the embedder has aqueue, the work is scheduled as a job instead.
Must contain
id. The full record is re-fetched from the database, so partial items are safe.Statistics label, for example
"api" or "processor".The app’s
ExuluConfig.The item ID.
Job ID when the embedder runs in queue mode (
chunks is 0 in that case).Number of chunks written when run inline.
embeddings.generate.all()
Generates (or queues) embeddings for all items in the context, onegenerate.one() call per item.
The app’s
ExuluConfig.User ID for tracking.
Role ID for tracking.
Cap on the number of items to process.
Job IDs (queue mode).
Number of items processed.
createAndUpsertEmbeddings()
Low-level worker used byembeddings.generate.one(): chunks, embeds, deletes the item’s old chunks, inserts the new ones, updates chunks_count and embeddings_updated_at, and re-runs entity extraction when the entity layer is on.
Processing
processField()
Runs the configured processor on an item — either inline or, when the processor has aqueue, as a background job. On inline success the result is written back to the items table with last_processed_at set, and embeddings are triggered when processor.config.generateEmbeddings is true.
Statistics label for the run.
The item to process.
The app’s
ExuluConfig — provides storage access to the processor’s utils.storage.The processed item, or
undefined when the job was queued or the processor’s filter skipped the item.Job ID in queue mode, or the follow-up embeddings job ID when
generateEmbeddings queued one.Sources
executeSource()
Runs a source’sexecute function with the given inputs and returns the fetched items. It does not write them — the worker’s scheduled source jobs handle persistence, upserting returned items that carry an external_id (or id) and inserting the rest.
One of the context’s sources.
Input values, spread into the source’s
execute arguments alongside exuluConfig.The items the source produced.
Entity layer
Available undercontext.entityLayer when the entity layer is enabled. See Entities for the admin UI these methods power.
entityLayer.countStale()
Counts items whose entities were extracted with an out-of-date entity-type set — used for the admin “run backfill?” prompt.0 when the entity layer is disabled. When the signature column doesn’t exist yet, every item counts as stale.
entityLayer.backfill()
Re-extracts entities across existing items, inline and in batches.Limit the run to items whose entity-type signature is out of date.
Cap per run; items beyond it are reported in
skipped and left for the next run.This re-runs entity extraction only — it does not re-embed items.
entityLayer.extractItem()
Extracts and ingests entities for a single item. Powers the item detail page’s extraction test action.entityLayer.detachItem()
Removes all entity links from one item and prunes entities that end up orphaned.entityLayer.purgeType()
Deletes all entities of a given type; their chunk mentions cascade away.Table management
These are called byExuluDatabase.init() / platform database initialization — you rarely invoke them yourself.
createItemsTable()
Creates<id>_items with the built-in columns, your custom fields, the generated fts tsvector column (per configured language), and a GIN index on it.
createChunksTable()
Creates<id>_chunks with content, JSONB metadata, chunk_index, a pgvector embedding column sized from the embedding model’s declared dimensionality, a generated fts column, a GIN index, and an HNSW cosine index.
tableExists()
<id>_items exists.
chunksTableExists()
<id>_chunks exists.