RAG
What is RAG?
Section titled “What is 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 -> ContextYou 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);| Option | Type | Default | Description |
|---|---|---|---|
bucket | string | required | Schift bucket ID |
topK | number | 5 | Number of results per search |
Searching
Section titled “Searching”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}Chat (Search + LLM Answer)
Section titled “Chat (Search + LLM Answer)”const response = await rag.chat("How do I reset my password?");
console.log(response.answer); // LLM-generated answerconsole.log(response.sources); // Source passages usedUsing RAG with an Agent
Section titled “Using RAG with an Agent”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.
Uploading Documents
Section titled “Uploading Documents”Upload documents via the Schift dashboard or API:
// Via the Schift clientawait schift.db.upload("my-docs", file);Supported formats: PDF, DOCX, TXT, MD, HTML. Schift automatically runs OCR on scanned documents.
Custom Tool Name
Section titled “Custom Tool Name”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"), ], ...});