Introduction
Retrieval SDK is provider-agnostic retrieval for TypeScript, with BM25, vector search, hybrid fusion, reranking and evaluation.
Retrieval SDK gives you search building blocks that work with any model or database.
- One contract. A
Retrievertakes a query and returns ranked hits. BM25, vector search, hybrid fusion and reranking are all retrievers, so they nest. - Zero dependencies. Models plug in through two small interfaces,
EmbedderandReranker. - Measure it.
evaluatescores any retriever with NDCG, recall and precision.
Install
npm install retrieval-sdkpnpm add retrieval-sdkyarn add retrieval-sdkbun add retrieval-sdknub add retrieval-sdkaube add retrieval-sdkQuickstart
import {
bm25,
hybrid,
memoryDocumentStore,
memoryVectorStore,
vectorSearch,
withRerank,
} from "retrieval-sdk";
import { cohereEmbedder, cohereReranker } from "retrieval-sdk/cohere";
const lexical = bm25();
const semantic = vectorSearch({
embedder: cohereEmbedder({ model: "embed-v4.0" }),
store: memoryVectorStore(),
});
await Promise.all([lexical.add(docs), semantic.add(docs)]);
const retriever = withRerank({
retriever: hybrid({ retrievers: [lexical, semantic] }),
reranker: cohereReranker({ model: "rerank-v3.5" }),
documents: memoryDocumentStore(docs),
});
const { hits } = await retriever.retrieve("reset my password", { topK: 10 });
// [{ id: "doc-7", score: 0.93 }, ...]
See Concepts for how the pieces fit together.
Credits
The API design takes inspiration from the AI SDK and Files SDK.