Skip to content
AgentsKit
Packages

@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 Β· plain for 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.

#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