agentskit.js
Cookbook

RAG in 15 lines

createRAG with a file vector store. Working retrieval in under a screen of code.

RAG does not require a vector database, a cluster, or a PhD. Start here, swap pieces later.

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

await rag.ingest([
  { id: 'streams', content: 'AgentsKit adapters emit streaming chunks.' },
])

const context = await rag.retrieve({
  query: 'how do streams work?',
  messages: [],
})

Tip

Swap fileVectorMemory for another VectorMemory implementation without changing the RAG pipeline.

Note

ingest embeds and stores every supplied chunk. Idempotency and replacement semantics belong to the injected vector store.

Explore nearby

✎ Edit this page on GitHubΒ·Found a problem? Open an issue β†’Β·How to contribute β†’
Ask the docs
Ask anything about AgentsKit. Answers come from the docs corpus and cite their sources.