agentskit.js
RAG

createRAG

One-liner RAG pipeline — chunk, embed, store, retrieve, search.

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: '.agentskit/vectors' }),
})

await rag.ingest([{ id: 'doc-1', content: longDoc }])
const hits = await rag.retrieve({
  query: 'How does token budgeting work?',
  messages: [],
})

ingest takes InputDocument[] — the text field is content, not text.

#API

MethodPurpose
ingest(docs)chunk + embed + store
retrieve({ query, messages })Retriever contract — uses query
search(query, { topK?, threshold? })vector search with optional overrides

retrieve and search both return RetrievedDocument[]. Use retrieve when you need the contract (runtime, rerank wrappers). Use search when you already have a query string.

#Options

  • chunkSize / chunkOverlap / split — passed to chunking. Defaults: chunkSize 512, chunkOverlap 50. split is an optional (text: string) => string[].
  • topK / threshold — defaults for search (and therefore retrieve).

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.