A minimal RAG (Retrieval Augmented Generation) library for the Vercel AI SDK. Semantic search over documents with SQLite or in-memory storage.
- Chunking — Configurable text chunking with overlap
- Vector stores — SQLite (persistent) or in-memory
- Embeddings — Uses AI SDK
embed/embedManywith any compatible model - Retrieval — Semantic search with optional caching
- AI SDK integration —
createRetrieverandcreateRagMiddlewarefor use withgenerateText/streamText
bun add zenrag @openrouter/ai-sdk-providerimport { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { ZenRag } from "zenrag";
const openrouter = createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY! });
const embeddingModel = openrouter.textEmbeddingModel("openai/text-embedding-3-small");
const rag = new ZenRag({
embeddingModel,
filePath: "./knowledge.db",
topK: 5,
});
await rag.addDocuments([
"Your document content here...",
"Another document...",
]);
const docs = await rag.retrieve("search query");ZenRag— Main RAG classSqliteStore/MemoryStore— Vector store implementationscreateRetriever(rag)— Returns a retriever function for AI SDKcreateRagMiddleware(rag, options)— Middleware for RAG in AI pipelineschunkText,createChunker— Chunking utilities
MIT