MaxSim takes each query vector’s best match among a document’s vectors, then adds those matches to score the document. This example uses hand-written vectors; no multi-vector model is bundled.
dotnet add package RecursiveAI.OneIndex --prereleaseRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneIndex; using OneIndex.Vectors; using var index = SearchIndex.InMemory<Passage>(); index.Upsert([ new() { Id = "both", Tokens = [[1, 0], [0, 1]] }, new() { Id = "one", Tokens = [[1, 0]] }, new() { Id = "opposite", Tokens = [[-1, 0], [0, -1]] } ]); index.Commit(); float[][] query = [[1, 0], [0, 1]]; var hits = MaxSim.Search( index.Search(), p => p.Tokens, query, k: 3); foreach (var hit in hits) Console.WriteLine( $"{hit.Hit.Id}: {hit.Score:F1}"); public class Passage { [SearchId] public string Id { get; set; } = ""; [MultiVector(Dimensions = 2)] public float[][]? Tokens { get; set; } }
both: 2.0 one: 1.0 opposite: 0.0
The download pins OneIndex to 0.4.0-preview.2; the package’s source generator builds the mapping from the attributed class.
A row with the wrong dimension, NaN or infinity is rejected at Upsert with ArgumentException.
Unzip the example, then dotnet run.
Variations
Rerank the same candidates instead of scanning them directly. Replace the var hits statement in the snippet at the top:
var hits = MaxSim.Rerank( index.Search().Execute(), p => p.Tokens, query, take: 2);
both: 2.0 one: 1.0
Related recipes
The short answer
Use a [MultiVector] property to store token vectors on a document and MaxSim.Search to score a query’s token vectors against them. MaxSim is late interaction: it compares token vectors at query time rather than reducing each document to a single vector. OneIndex supplies storage and scoring, not a trained multi-vector encoder. The example deliberately supplies small vectors so you can see exactly why a document wins.
How do you search multiple vectors per document in C#?
Declare the property as float[][]? and give [MultiVector] the dimension of each row. Each outer-array entry represents a token; each inner array holds that token’s vector. A document can have a different number of tokens from another document, but every row must have the declared dimension. The package’s source generator creates the mapping from the attributed class when the project builds; no separate mapping file is needed.
In the program above, both has a vector for each of the query’s two directions. one has just the first direction. opposite has neither direction. The result is a document ranking, not a list of individual token matches. A high-scoring document appears once even when several of its token vectors match.
Commit makes the inserted documents visible to the search. The in-memory index is enough for this demonstration; use the same mapped class with a directory-backed index when the documents must survive the process. See the multi-vector documentation for the encoder interface and stored representation.
How does multi-vector search ranking work?
For each query token, MaxSim finds the largest cosine similarity against any token in the document. It adds those best similarities to get the document score. Vectors are normalized before comparison. The result is not an average and is not a probability. In this example the two independent directions each contribute one to both, producing 2.0.
The same document token can be the best match for more than one query token. This is not a one-to-one assignment. An empty token set on either side scores zero. That makes it important to understand your encoder’s output and to compare scores within the same query rather than treating a fixed threshold as a universal confidence level.
Can I use multi-vector search for semantic search in C#?
Yes, when your application supplies an appropriate IMultiVectorEncoder. The toy vectors here demonstrate retrieval mechanics; they do not encode English meaning. Use the same encoder and dimensions for documents and queries, and pass the correct document or query role. OneIndex also supports encoding a null multi-vector property from a text property declared with From.
Choose an exact scan for a small filtered candidate set. The documented scan ceiling is SearchQuery<T>.MaxResultWindow, or 10,000 candidates. There is no approximate multi-vector index. For a larger collection, retrieve candidates with a first-stage search and rerank only those candidates with MaxSim. That changes the question from “which document wins across the whole corpus?” to “which candidate wins among those retrieved?” A relevant document missing from the first stage cannot be recovered by reranking.