@agentskit/rag
Plug-and-play RAG. Chunk, embed, retrieve, rerank, hybrid, and document loaders.
#When to reach for it
- You want retrieval-augmented generation in a few lines.
- You need rerankers (BM25, Voyage, Jina, or a custom function) or hybrid vector+keyword search.
- You want document loaders for URL / GitHub / Notion / Confluence / Google Drive / PDF / S3 / GCS / Dropbox / OneDrive.
#Install
npm install @agentskit/rag#Hello world
import { createRAG } from '@agentskit/rag'
import { fileVectorMemory } from '@agentskit/memory'
import { openaiEmbedder } from '@agentskit/adapters'
const rag = createRAG({
embed: openaiEmbedder({ apiKey: process.env.OPENAI_API_KEY! }),
store: fileVectorMemory({ path: './kb-vectors' }),
})
await rag.ingest([{ content: 'AgentsKit is a toolkit for AI agents.', source: 'intro' }])
const hits = await rag.search('what is agentskit')#Surface
createRAG({ embed, store, chunkSize, chunkOverlap, topK, threshold }).chunkTextβ standalone splitter.@agentskit/rag/markdownβparseNoteΒ·splitFrontmatterΒ·extractWikilinksΒ·stripWikilinksΒ·sectionsΒ·findSectionΒ·parseTableΒ·normalizeΒ·plainfor Markdown notes (frontmatter, wikilinks, heading sections, GitHub tables).createRerankedRetrieverΒ·createHybridRetrieverΒ·bm25ScoreΒ·bm25Rerank.- Loaders:
loadUrlΒ·loadGitHubFileΒ·loadGitHubTreeΒ·loadNotionPageΒ·loadConfluencePageΒ·loadGoogleDriveFileΒ·loadPdfΒ·loadS3Β·loadGcsΒ·loadDropboxΒ·loadOneDrive.
Remote loaders use a finite timeout and response-size limit by default. Configure
timeoutMs, maxResponseBytes, and signal when needed. loadUrl requires an
HTTPS origin in allowedOrigins and rejects redirects.
#Recipes
#Stability
- Version:
1.0.0 - Tier: beta
- Contract: evolving
- Roadmap: see packages roadmap for what this package needs to reach v1.0.
#Related
#Source
npm: @agentskit/rag Β· repo: packages/rag
#Partition-bound retrieval
createPartitionedRAG composes createRAG without changing the core Retriever
contract or existing createRAG behavior. Bind each instance to a non-empty
partition at construction:
import { createPartitionedRAG } from '@agentskit/rag'
const rag = createPartitionedRAG({
store,
embed,
partition: 'team-a',
topK: 5,
overfetchFactor: 4,
onDiagnostics: diagnostics => console.warn(diagnostics),
})
await rag.ingest([{ id: 'guide', content: 'Team A guide' }])
const hits = await rag.retrieve({ query: 'guide' })Ingest overrides the reserved _akPartition metadata field and namespaces chunk
IDs with a JSON tuple, so identical document IDs in different partitions do not
overwrite or delete each other's chunks. Document metadata, including
documentId, remains available. Returned chunk IDs are opaque namespaced IDs.
Every search forwards a core VectorFilter equality predicate and verifies
partition metadata locally, rejecting foreign or missing metadata even when a
store ignores filters. The wrapper makes one store search, requests at most
topK * overfetchFactor candidates, examines at most that many, and returns at
most topK matches. The factor is an integer from 1 to 16 (default 4); unsafe
candidate limits throw. Per-call search limits and thresholds still work.
The required onDiagnostics callback runs for every successful store search,
including empty results, with partition, requestedTopK, candidateLimit,
examined, rejected, returned, and recall: 'potentially-reduced'. This is
conservative: bounded over-fetch can miss matching chunks, and a store can
internally filter a bounded global candidate pool without revealing exclusions
(as fileVectorMemory does). Short results never justify returning another
partition's chunks. Callback exceptions reject the search.
Stores must faithfully preserve chunk metadata and IDs. Missing metadata fails closed, but fabricated or incorrectly reassigned partition metadata cannot be detected. This is retrieval isolation, not an authorization boundary against untrusted writers or stores. Use physically separate stores or a backend with trusted partition enforcement when that boundary or exhaustive recall is needed. Backend-internal over-fetch is outside the wrapper's candidate bound.
Explore nearby
- PeerPackages overview
Every AgentsKit package at a glance β what it does, when to reach for it, where to read the deep dive.
- PeerRoadmap
Per-package stability status, current version, and what each package needs to reach v1.0.
- Peer@agentskit/core
Shared contract layer β TypeScript types, headless chat controller, stream helpers. Zero-dep, under 10 KB gzipped.