Skip to content

RAG

RAG (Retrieval-Augmented Generation) lets your agent answer questions using your documents. Schift handles the entire pipeline:

Upload PDF/DOCX/TXT -> OCR -> Chunking -> Embedding -> Vector Index
|
Query -> Embed -> Search -> Rerank -> Context

You upload documents. Schift processes them. Your agent searches and answers.

import { Schift, RAG } from "@schift-io/sdk";
const schift = new Schift({ apiKey: "sch_..." });
const rag = new RAG({ bucket: "my-docs", topK: 5 }, schift.transport);
OptionTypeDefaultDescription
bucketstringrequiredSchift bucket ID
topKnumber5Number of results per search
const results = await rag.search("How do I reset my password?");
for (const r of results) {
console.log(r.text); // Matching passage
console.log(r.score); // Relevance score (0-1)
console.log(r.metadata); // Document metadata
}
const response = await rag.chat("How do I reset my password?");
console.log(response.answer); // LLM-generated answer
console.log(response.sources); // Source passages used

Pass the RAG instance to the Agent. It auto-registers as a tool named rag_search.

const agent = new Agent({
name: "Support Bot",
instructions: "Answer questions using the knowledge base.",
rag,
model: "gpt-4o-mini",
transport: schift.transport,
});
const result = await agent.run("How do I reset my password?");

The agent will call rag_search when it needs information from your documents.

Upload documents via the Schift dashboard or API:

// Via the Schift client
await schift.db.upload("my-docs", file);

Supported formats: PDF, DOCX, TXT, MD, HTML. Schift automatically runs OCR on scanned documents.

If you need a different tool name (e.g., multiple RAG sources):

const legalDocs = new RAG({ bucket: "legal" }, schift.transport);
const supportDocs = new RAG({ bucket: "support" }, schift.transport);
const agent = new Agent({
tools: [
legalDocs.asTool("search_legal_docs"),
supportDocs.asTool("search_support_docs"),
],
...
});