milvus-logo
LFAI
< Docs
  • C#

SearchAsync()()

Perform a vector similarity search.

Invocation

await collection.SearchAsync<T>(vectorFieldName, vectors, metricType, limit, parameters = null, cancellationToken = default);

Parameters

ParameterDescriptionTypeRequired
vectorFieldNameThe name of the vector field to search in.stringTrue
vectorsThe set of vectors to send as input for the similarity search.IReadOnlyList<ReadOnlyMemory<T>>True
metricTypeMethod used to measure the distance between vectors during search. Must correspond to the metric type specified when building the index.SimilarityMetricTypeTrue
limitThe maximum number of records to return, also known as 'topk'. Must be between 1 and 16384.intTrue
parametersVarious additional optional parameters to configure the similarity search.SearchParametersFalse
cancellationTokenThe token to monitor for cancellation requests. The default value is CancellationToken.None.CancellationTokenFalse

Return

The results of the vector similarity search.

Example

var results = await milvusClient.GetCollection("book").SearchAsync(
    vectorFieldName: "book_intro",
    vectors: new ReadOnlyMemory<float>[] { new[] { 0.1f, 0.2f } },
    SimilarityMetricType.L2,
    // the sum of `offset` in `parameters` and `limit` should be less than 16384.
    limit: 10,
    new SearchParameters
    {
        OutputFields = { "title" },
        ConsistencyLevel = ConsistencyLevel.Strong,
        Offset = 5,
        ExtraParameters = { ["nprobe"] = "1024" }
    });
Feedback

Was this page helpful?