@talosjs/rag package is a Retrieval-Augmented Generation toolkit. It turns your documents into searchable knowledge: extract PDFs to Markdown with automatic OCR fallback, embed the content via OpenRouter, store it in a LanceDB vector database, and retrieve the most relevant passages with hybrid search.
You define a typed vector database class, open a table, add records, and search. Every record carries an id, the searchable text, and a metadata object of your own typed fields.
What the package gives you
Retrieval is hybrid: full-text and vector search run together and are merged with RRF reranking, so you get both keyword precision and semantic recall. Themetadata shape you declare drives the types for records, filters, and selected fields, so a wrong field name or value type fails to compile. The RAG class handles the ingest side, extracting a PDF to Markdown and OCR’ing any page that needs it.
Storage is local: LanceDB keeps vectors on disk, with no separate database server to run. Filters combine field conditions with AND, OR, and NOT to narrow results, and databases register with a decorator so you can resolve them from the DI container.
The building blocks
Installation
The record shape
Every row in a table has the same three top-level fields:metadata with a DataType and the database carries it through everywhere — added records, search results, filters, and selected columns are all typed against it.
End-to-end example
How retrieval works
When you callsearch(), the table:
- Runs a vector search over the embedded
textand a full-text search over the same column. - Merges both result sets with an RRF reranker (Reciprocal Rank Fusion).
- Applies your
filterandselect, then returns the toplimitrecords, typed against yourmetadata.
Tables are created with three indexes on first
open(): a btree index on id, a full-text (FTS) index on text, and an IVF-PQ vector index on vector, so search stays fast from the start. See Vector Database for details.