redis-vl-dotnet

VectorQuery

VectorQuery performs KNN search against one vector field.

Basic shape

var vectorQuery = VectorQuery.FromFloat32(
    fieldName: "plot_embedding",
    vector: queryVector,
    topK: 3,
    filter: Filter.Tag("genre").Eq("crime"),
    returnFields: ["title", "summary"],
    scoreAlias: "distance",
    runtimeOptions: new VectorKnnRuntimeOptions(efRuntime: 150),
    pagination: new QueryPagination(limit: 2));

var results = await index.SearchAsync(vectorQuery);

The canonical runnable reference is /examples/VectorSearchExample.

TopK window and paging

VectorQuery has two paging constraints:

  • topK must be greater than zero

  • pagination.Offset + pagination.Limit cannot exceed topK

That means topK defines the maximum retrieval window, and QueryPagination selects which slice of that window you want back.

The same example project shows a second-page request by keeping topK: 3 and changing the pagination to offset: 2, limit: 1.

Return fields, score aliases, and typed mapping

The library normalizes vector query projections:

  • leading @ markers are stripped from the vector field name and score alias

  • duplicate returnFields are removed

  • the score alias is automatically included in the returned fields

Map results into projection records when you want strong typing for both domain fields and the vector score:

var typedResults = await index.SearchAsync<MovieVectorHit>(
    VectorQuery.FromFloat32("plot_embedding", queryVector, 3, returnFields: ["title"], scoreAlias: "distance"));

Runtime vector options

Use VectorKnnRuntimeOptions to pass runtime tuning for the field’s algorithm:

  • HNSW fields: efRuntime (must be greater than zero) is translated into EF_RUNTIME query params

  • SVS-VAMANA fields: searchWindowSize, useSearchHistory (SvsSearchHistory.Auto/On/Off), and searchBufferCapacity are translated into SEARCH_WINDOW_SIZE, USE_SEARCH_HISTORY, and SEARCH_BUFFER_CAPACITY query params

Runtime knobs are validated against the field’s algorithm: EF_RUNTIME is rejected on non-HNSW fields, and the SVS-VAMANA knobs are rejected on non-SVS-VAMANA fields.

These are runtime search knobs, not schema metadata. Schema construction choices such as m, efConstruction, graphMaxDegree, and constructionWindowSize still live on the vector field definition.

Batch helpers

SearchBatchesAsync works for vector search too. When batchSize is larger than the remaining topK window, the final batch is automatically shrunk to stay inside topK.