Skip to main content
@bijectionhq/library-retrieval finds cited passages in an app’s own facts, files and held texts. retrieval({ … }) returns a subtree you place in your tree. It runs as your app, its tables are your tables at the corpus label, and its embedding calls spend your model receiver’s meter.
bijection/knowledge.ts
Place desk, the tables (notes, manuals, answers), openai, the roles and docs in the app tree. After each deploy, an operator calls docs.control.sync.

Options

A source over an app table follows the table’s change log (table.changes.since(version)). A source with search also ranks that table’s own declared text index, exactly at the head. Files are read through bounded parsers: CSV, JSON, XML, message/rfc822 and UTF-8 text/*. Other types yield no text; extract them with external compute into a fact and index that fact.

Held texts

source() declares a source the instance holds itself, one text per app key. Use it for text that lives nowhere else in your app: TextState is { title, generation, state, chunks, embedded, pending, failed, refusal, revision }, with state one of waiting, embedding, failed and ready. A failed embedding request keeps a refusal with its code and message. Use refusalText from @bijectionhq/bijection/client to display it. texts.put and texts.retract refuse UnknownSource, NotHeld (a source over an app table), InvalidKey and InvalidText.

Retrieve from code

docs.retrieve is a target. Submit it with a continuation. Every option is required, and null takes its default:
The result is a Retrieved:
A citation is { source, table, id, revision, file, chunk, chunker, start, end, digest }. The answering frame rereads the source under current authority. Its exact read version is both revision and cut. To replay a passage while that version is retained, reopen the fact and any cited File under current authority. Match the File ID, SHA-256, size and media type, then run the named extractor and chunker and verify the range and digest.

Ask from a client

asks.insert takes the same arguments, submits retrieve and returns the ask’s key. asks.get reads it back: { args, asked, result }, where result is the Retrieved once settled. Only the asker reads an ask, and it lives a day. Each read checks that the cited passages still match source content the asker can read.
bijection/app.ts
bijection/client.ts
In React, hold the insert with useMutation(app.docs.asks.insert) and the answer with useWatch(app.docs.asks.get, ask === null ? null : { ask }).

As an agent tool

Give the instance the agents app’s engine.deliver, and offer a deferred tool that starts a retrieval for the call. The Retrieved is delivered to the turn:
The corpus and the transcript should share a label, so the delivery commits under the transcript. The result includes as many complete cited passages as fit in one tool message.

Operate the index

Labels and erasure

Chunks and vectors are under the corpus label, so they carry its protection, and the embedding receiver must clear that label. A change whose after is null in a source’s log (a delete, an expiry or an erasure) retracts the fact’s chunks and vectors in every generation when the worker lands it. The worker also revisits independently retired Files. The answer path checks facts and Files before returning passages.