Skip to content
Retrieval SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

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 Retriever takes 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, Embedder and Reranker.
  • Measure it. evaluate scores any retriever with NDCG, recall and precision.

Install

npm install retrieval-sdk
pnpm add retrieval-sdk
yarn add retrieval-sdk
bun add retrieval-sdk
nub add retrieval-sdk
aube add retrieval-sdk

Quickstart

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.

Was this page helpful?