agentskit.js

@agentskit/rag — for agents

Plug-and-play RAG. Chunking + ingest + retrieve + rerank + hybrid + eleven document loaders.

#Install

npm install @agentskit/rag

#Primary exports

  • createRAG({ embed, store, chunkSize, chunkOverlap, topK, threshold })ingest(docs) + retrieve(request) + search(query).
  • chunkText({ chunkSize, chunkOverlap, split }) — lower-level splitter.
  • createRerankedRetriever(base, { candidatePool, topK, rerank }) — pluggable reranker (BM25 default). See RAG reranking.
  • createHybridRetriever(base, { vectorWeight, bm25Weight }) — vector + BM25 hybrid.
  • bm25Score, bm25Rerank — standalone helpers.
  • voyageReranker(config) — Voyage AI reranker.
  • jinaReranker(config) — Jina AI reranker.
  • RagError / RagErrorCodes — typed error (extends AgentsKitError) thrown by loaders + rerankers; narrow on error.code (AK_RAG_LOAD_FAILED, AK_RAG_PEER_MISSING, AK_RAG_RERANK_FAILED).

#Document loaders

  • loadUrl, loadGitHubFile, loadGitHubTree, loadNotionPage, loadConfluencePage, loadGoogleDriveFile, loadPdf (BYO parser). See Doc loaders.
  • Cloud storage: loadS3, loadGcs, loadDropbox, loadOneDrive.

#Failure and cancellation contract

  • Loader request, response-body, pagination, and total-download failures throw RagError with AK_RAG_LOAD_FAILED. Tree loaders may return partial success only after at least one eligible document loaded.
  • Loader options accept signal?: AbortSignal; Voyage and Jina reranker options accept the same additive field.
  • Notion and OneDrive follow provider pagination and reject repeated or missing continuation cursors instead of returning truncated content.
  • Scoreless Retriever results keep their order. If any score is present, all scores must be finite and the result is ordered descending; malformed mixed score sets throw.
  • Hybrid retrieval min-max normalizes candidate scores and normalizes relative weights before blending.

#Minimal example

import { createRAG, loadGitHubTree } from '@agentskit/rag'
import { fileVectorMemory } from '@agentskit/memory'
import { openaiEmbedder } from '@agentskit/adapters'

const rag = createRAG({
  embed: openaiEmbedder({ apiKey }),
  store: fileVectorMemory({ path: './kb.json' }),
})

await rag.ingest(await loadGitHubTree('org', 'repo', { token }))
const hits = await rag.search('onboarding flow')

#Source

Explore nearby

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page

Ask the docs
Ask anything about AgentsKit. Answers come from the docs corpus and cite their sources.