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?");from raglite import DocumentCollection
collection = DocumentCollection(["./docs", "./faq.md", "https://example.com/pricing"], { "llm": {"provider": "openai"},})collection.add_source("./handbook.pdf")
result = collection.build()print(f"{result.totalDocuments} documents, {result.totalChunks} chunks")
hits = collection.search("refund policy", top_k=5)answer = 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.
Folders
Section titled “Folders”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,.venvand.raglite) andnode_modulesare skipped.
Glob patterns such as ./docs/*.md are not expanded. Pass a folder, or a list of files.
The build result
Section titled “The build result”| 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.
Vector stores
Section titled “Vector stores”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.
Other methods
Section titled “Other methods”| 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 |