@agentskit/rag

Plug-and-play retrieval-augmented generation: chunk documents, embed them, and retrieve the right context at query time.

Tags: ai · agents · llm · agentskit · rag · retrieval · vector-search · embeddings · ai-agents · semantic-search · knowledge-base
How this fits the ecosystem
@agentskit/rag is the retrieval layer: load documents, chunk them, embed them, rerank results, and feed precise context back to agents.
- AgentsKit: compose it with the other packages in this repo to build agents from small, swappable parts.
- Registry: look for ready agents and templates that already use this layer at registry.agentskit.io.
- Playbook: learn the production patterns behind this layer at playbook.agentskit.io.
- AKOS: run the same concepts with enterprise deployment, governance, and observability at akos.agentskit.io.
Docs: package guide · agent handoff
Why rag
- Your data, your agent — no fine-tuning required; ingest plain text and query with natural language
- Composable stack — uses any
EmbedFn and any VectorMemory from @agentskit/adapters and @agentskit/memory; swap either layer without touching RAG logic
- Retriever-ready —
createRAG() returns a Retriever you pass to @agentskit/runtime or useChat so context is injected automatically
- Tune chunking without a PhD —
chunkSize, chunkOverlap, or a custom split function — three knobs that cover 95% of use cases
Install
npm install @agentskit/rag @agentskit/memory @agentskit/adapters
Quick example
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: './vectors' }),
})
await rag.ingest([
{ id: 'doc-1', content: 'AgentsKit is a JavaScript agent toolkit...' },
])
const docs = await rag.search('How does AgentsKit work?', { topK: 5 })
With runtime (retriever)
Pass the RAG instance as retriever so the runtime injects retrieved context into the task:
import { createRuntime } from '@agentskit/runtime'
import { openai } from '@agentskit/adapters'
const runtime = createRuntime({
adapter: openai({ apiKey: process.env.OPENAI_API_KEY!, model: 'gpt-4o' }),
retriever: rag,
})
const result = await runtime.run('Explain the AgentsKit architecture based on ingested docs')
console.log(result.content)
You can also call rag.retrieve({ query, messages }) to satisfy the core Retriever contract (for example from a custom controller).
Features
createRAG({ embed, store }) — single entry point for ingest + retrieve.
rag.ingest(docs) — chunk, embed, and store documents.
rag.search(query, { topK }) — semantic similarity search.
rag.retrieve({ query, messages }) — Retriever contract v1 for runtime/controller injection.
- Configurable chunking:
chunkSize, chunkOverlap, custom split.
- Works with any
EmbedFn and any VectorMemory.
- Rerankers:
createRerankedRetriever (Cohere Rerank, BGE, BM25 default), createHybridRetriever (vector + BM25 blend), standalone bm25Score. Recipe.
- Document loaders:
loadUrl, loadGitHubFile, loadGitHubTree, loadNotionPage, loadConfluencePage, loadGoogleDriveFile, loadPdf (BYO parser). Recipe.
Ecosystem
Contributors
License
MIT — see LICENSE.
Docs
Full documentation · GitHub