Skip to main content
The @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. The metadata 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

Embeddings are generated through OpenRouter, so set your API key in the environment:

The record shape

Every row in a table has the same three top-level fields:
You describe 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 call search(), the table:
  1. Runs a vector search over the embedded text and a full-text search over the same column.
  2. Merges both result sets with an RRF reranker (Reciprocal Rank Fusion).
  3. Applies your filter and select, then returns the top limit records, typed against your metadata.
This hybrid approach catches results that pure keyword search misses (semantic matches) and results that pure vector search ranks poorly (exact terms, names, codes).
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.