Skip to content

Getting started

RAGLite turns documents into a searchable index, then answers questions from it with any LLM. The TypeScript package needs Node.js 20 or later; the Python package needs Python 3.11 or later.

The core package is small. Add the SDK for each provider you use; Choosing providers lists them all.

Terminal window
npm install raglite-toolkit
npm install @huggingface/transformers # local embeddings (the default), no API key
npm install @ai-sdk/anthropic # Claude answers

If a package is missing, RAGLite throws a ConfigError that names the command to run.

import { Document } from "raglite-toolkit";
const doc = new Document("./policy.pdf", {
llm: { provider: "anthropic", apiKey: process.env.ANTHROPIC_API_KEY },
});
await doc.build(); // load → chunk → embed → save
const hits = await doc.search("refund policy", { topK: 3 });
for (const hit of hits) console.log(hit.score.toFixed(2), hit.metadata.source, hit.text);
const answer = await doc.ask("What is the refund policy?");
console.log(answer.text); // "Refunds are issued within 30 days [1]."
console.log(answer.citations); // the passages behind [1], [2], ...
  • build() reuses the saved index when nothing has changed, so calling it on every start is cheap. See How caching works.
  • A Document that was never built throws FileNotIndexedError from search() and ask(). A saved index from an earlier run is loaded without calling build().
  • Without an apiKey, each provider reads its usual environment variable, such as ANTHROPIC_API_KEY. See Choosing providers.

Supported files: PDF, DOCX, Markdown, TXT and JSON, plus web pages by URL. To index many files at once, see Collections.

No file needed: index a database row, an upload or CMS content. The id names the index (reuse it to reuse the index) and becomes each chunk’s source. Changed text is re-indexed on the next build().

const doc = Document.fromText("faq-42", faqText, { embeddings: { provider: "openai" } });
await doc.build();

Indexes are saved under ./.raglite, one folder per document, so two documents never overwrite each other. Set storeDir to keep them elsewhere, or use a vector database. Add .raglite/ to your .gitignore.

  • Choosing providers: embeddings and LLMs, API keys, running fully local.
  • Citations: pages and sections for each cited passage.
  • MCP server: give your documents to Claude Code, Cursor or VS Code.