Skip to content

Collections

A DocumentCollection indexes many sources and searches them as one. Each source is a file, a folder (scanned recursively) or a web URL.

import { DocumentCollection } from "raglite-toolkit";
const collection = new DocumentCollection(["./docs", "./faq.md", "https://example.com/pricing"], {
llm: { provider: "openai" },
});
collection.addSource("./handbook.pdf");
const result = await collection.build();
console.log(`${result.totalDocuments} documents, ${result.totalChunks} chunks`);
const hits = await collection.search("refund policy", { topK: 5 });
const answer = await collection.ask("What is the refund policy?");

Each file gets its own index, so build() re-embeds only the files that changed. Search results from every document are merged by score; in hybrid mode the lists are merged first, then fused once.

A folder is scanned recursively for supported files (PDF, DOCX, Markdown, TXT, JSON).

  • Unsupported and empty files are skipped and reported in errors.
  • Hidden files and folders (such as .git, .venv and .raglite) and node_modules are skipped.

Glob patterns such as ./docs/*.md are not expanded. Pass a folder, or a list of files.

Field Meaning
totalDocuments Documents in the collection
totalChunks Chunks across all documents
cachedDocuments Documents whose saved index was reused
newDocuments Documents indexed in this build
errors { source, error } for each source that failed

One broken file does not stop the build: it is reported in errors and the rest are indexed. A search fails only when every document fails.

Collections work with every vector store. Pass a provider config such as { provider: "qdrant", ... }, not a VectorStore instance: an instance has one namespace, and every document would overwrite the others. RAGLite throws a ConfigError if you try.

TypeScript Python Does
askStream() ask_stream() Streams the answer. See Streaming
asTool() as_tool() A search tool for agents. See Agent tools
serve() serve() A REST API. See REST API
getDocuments() get_documents() The Document for each source
chunkCount chunk_count Chunks across all documents