MultiVectorRetriever<T>

Models & Types · AiDotNet.RetrievalAugmentedGeneration.Retrievers

Retrieves documents by matching against multiple vector representations per document for improved precision.

Inheritance: RetrieverBase<T> → MultiVectorRetriever<T>

For Beginners

Think of this like having multiple “angles” to describe the same book:

Regular retrieval:

  • Each book has ONE summary
  • Search compares your question to that ONE summary

Multi-vector retrieval:

  • Each book has MULTIPLE summaries (intro, chapters, conclusion, key topics)
  • Search compares your question to ALL summaries
  • Returns books that match ANY of their summaries

For example, searching “neural networks” in a machine learning textbook:

  • Chapter 1 summary: “Introduction to AI and data”
  • Chapter 5 summary: “Deep learning and neural networks” ← MATCH!
  • Chapter 10 summary: “Practical applications”
var documentStore = new InMemoryDocumentStore<double>(vectorDimension: 768);
// StubEmbeddingModel hashes text, so its similarities carry no meaning; it only keeps this example
// self-contained. Use a trained embedding model for retrieval that ranks by relevance.
var embeddingModel = new StubEmbeddingModel<double>(embeddingDimension: 768);
// One stored vector per section, with ids of the form "docId_vector_N" so they group back to their document.
// Each vector embeds its section but stores the whole book, so the document returned for a group is the book.
string[] sections = { "Introduction to quantum computing", "Qubits and superposition",
"Quantum gates", "Error correction", "Applications in chemistry and cryptography" };
string book = string.Join(" ", sections);
for (int i = 0; i < sections.Length; i++)
documentStore.Add(new VectorDocument<double>(
new Document<double>($"quantum-book_vector_{i}", book),
embeddingModel.Embed(sections[i])));

var retriever = new MultiVectorRetriever<double>(
documentStore,
vectorsPerDocument: 5, // 5 vectors per document
aggregationMethod: MultiVectorAggregation.Max, // Use best match
queryEmbedder: new EmbeddingModelQueryEmbedder<double>(embeddingModel) // same space as the documents
);

var results = retriever.Retrieve("quantum computing applications", topK: 5);
// Finds documents where ANY of the 5 vectors match your query well

Why use MultiVectorRetriever:

  • Better for long documents with multiple topics
  • Captures diverse aspects of complex content
  • Improves recall (finds more relevant matches)
  • Ideal for technical papers, books, reports

When NOT to use it:

  • Short documents (single vector is sufficient and faster)
  • Storage-constrained systems (requires 3-5x more storage)
  • Real-time systems (slower than single-vector retrieval)
  • Documents with uniform content (no benefit from multiple vectors)

How It Works

MultiVectorRetriever represents each document with multiple embedding vectors instead of a single one, enabling capture of different semantic aspects (summaries, key sentences, topics) within the same document. This approach is particularly effective for long documents with diverse content or when queries might match different parts of a document. The retriever generates scores from each vector representation and aggregates them using configurable methods (max, mean, weighted) to produce a final relevance score. This technique improves both precision and recall compared to single-vector retrieval, especially for complex documents.

Constructors

Constructor Summary
MultiVectorRetriever(IDocumentStore<T> documentStore, int vectorsPerDocument, MultiVectorAggregation aggregationMethod, IQueryEmbedder<T> queryEmbedder) Initializes a new instance of the MultiVectorRetriever class.