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(InputDocument[]) + retrieve({ query, messages }) + search(query, { topK?, threshold? }). InputDocument uses content, not text. Chunk defaults: 512 / 50.
  • chunkText(text, { chunkSize, chunkOverlap, split? }) — lower-level splitter. split is (text: string) => string[].
  • createRerankedRetriever(base, { candidatePool, topK, rerank }) — pluggable reranker (BM25 default). See RAG reranking.
  • createHybridRetriever(base, { vectorWeight?, bm25Weight?, topK?, candidatePool? }) — vector + BM25 hybrid; defaults to 0.6 / 0.4, 20 candidates, and 5 results.
  • 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(url) — raw response text as InputDocument.content. loadGitHubFile(owner, repo, path, opts), loadGitHubTree(owner, repo, { filter?, ... }), loadNotionPage(pageId, { token }), loadConfluencePage(pageId, { baseUrl, token?, authorization? }), loadGoogleDriveFile(fileId, { accessToken }), loadPdf(url, { parsePdf }). All return InputDocument[]. 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-vectors' }),
})

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.