@gnldev/rag
v0.5.0
Published
Vector store + RAG tool for AI SDK agents. Used as a tool, it becomes replayable/exactly-once RAG with @gnldev/durable.
Maintainers
Readme
@gnldev/rag
Vector store + RAG tool for AI SDK agents. Used as a tool inside runDurable, it's automatically
replayable (thanks to durableTool the retrieval is journaled: on resume it comes back from the record
instead of running again).
Install:
pnpm add @gnldev/rag— or use it from a repo clone:pnpm install && pnpm -r build.
npm i @gnldev/rag # peer: @gnldev/durable, ai, zodimport { InMemoryVectorStore, indexDocuments, createRagTool, llmReranker } from '@gnldev/rag';
const store = new InMemoryVectorStore();
await indexDocuments(store, embed, [{ id: 'p1', text: 'Return policy: 30 days…' }]);
const searchPolicy = createRagTool({
store, embed, topK: 3,
rerank: llmReranker({ model }), rerankTopK: 2, // optional LLM reranker
});
await runDurable({ runId: 'r1', journal, model, tools: { searchPolicy }, prompt: '…' });API
InMemoryVectorStore·indexDocuments(store, embed, docs)·VectorStoreinterface (plug in your own backend)createRagTool({ store, embed, topK?, rerank?, rerankTopK?, description? })→ AI SDK toolllmReranker({ model })→RerankerSemanticMemory— vector-based recall (memory integration)
How it works
Since RAG is a tool, it naturally fits into the durable agent loop: retrieval + rerank are journaled once
and replayed rather than repeated. For cross-run reuse, it can be combined with @gnldev/cache.
License
Apache-2.0 — see LICENSE.
