RAG
createRAG
One-liner RAG pipeline — chunk, embed, store, retrieve, search.
import { createRAG } from '@agentskit/rag'
import { openaiEmbedder } from '@agentskit/adapters'
import { fileVectorMemory } from '@agentskit/memory'
const rag = createRAG({
embed: openaiEmbedder({ apiKey: process.env.OPENAI_API_KEY! }),
store: fileVectorMemory({ path: '.agentskit/vectors' }),
})
await rag.ingest([{ id: 'doc-1', content: longDoc }])
const hits = await rag.retrieve({
query: 'How does token budgeting work?',
messages: [],
})ingest takes InputDocument[] — the text field is content, not text.
#API
| Method | Purpose |
|---|---|
ingest(docs) | chunk + embed + store |
retrieve({ query, messages }) | Retriever contract — uses query |
search(query, { topK?, threshold? }) | vector search with optional overrides |
retrieve and search both return RetrievedDocument[]. Use retrieve when you need the contract (runtime, rerank wrappers). Use search when you already have a query string.
#Options
chunkSize/chunkOverlap/split— passed to chunking. Defaults:chunkSize512,chunkOverlap50.splitis an optional(text: string) => string[].topK/threshold— defaults forsearch(and thereforeretrieve).