Skip to content

Retriever

A retriever in vectorstores is what is used to fetch Nodes from an index using a query string.

  • VectorIndexRetriever will fetch the top-k most similar nodes. Ideal for dense retrieval to find most relevant nodes.
const retriever = vectorIndex.asRetriever({
similarityTopK: 3,
});
// Fetch nodes!
const nodesWithScore = await retriever.retrieve({ query: "query string" });

The score returned with each node varies based on the retrieval mode:

  • Vector search: Scores (0.0 to 1.0) represent cosine similarity.
  • BM25 search: Scores are unbounded and represent keyword relevance.
  • Hybrid search: Scores are based on Reciprocal Rank Fusion (RRF) and are typically small (e.g., ~0.016 for rank 1).

For more details on search modes and scoring, see the Vector Stores documentation.