FunctionChain

A named chain of post-processing stages applied to search results, usable at the top level and per ANN-search leg of SearchAsync() and HybridSearchAsync(). Related types (FunctionChainOp, FunctionChainExpr, FunctionChainArg, FunctionParamValue) are documented in the sections below.

public sealed class FunctionChain
{
    public FunctionChainStage Stage { get; set; }
    public string Name { get; set; } = "";
    public IList<FunctionChainOp> Ops { get; } = new List<FunctionChainOp>();
}

PARAMETERS:

  • Stage (FunctionChainStage) -

    The execution stage where this function chain runs. Must be set to a non-unspecified stage (e.g. FunctionChainStage.L2Rerank).

    The FunctionChainStage enum supports the following values:

    • Unspecified (0) - The stage is unspecified; the request is rejected.

    • Ingestion (1) - The chain runs at ingestion time.

    • PreProcess (2) - The chain runs before the vector search.

    • L0Rerank (3) - The chain reranks L0 candidates.

    • L1Rerank (4) - The chain reranks L1 candidates.

    • L2Rerank (5) - The chain reranks L2 candidates.

    • PostProcess (6) - The chain runs after all reranking.

  • Name (string) -

    An optional SDK/debug name of this function chain.

  • Ops (IList) -

    The ordered operations of this function chain, executed by the server in this order.

FunctionChainOp

A single operation of a FunctionChain pipeline. The Op name is a server-recognized operation name (e.g. "map", "sort", "limit"); the Map, Sort and Limit factories set a valid op, while the raw builder accepts any non-empty string so future server ops remain expressible.

public sealed class FunctionChainOp
{
    public const string OpMap = "map";
    public const string OpSort = "sort";
    public const string OpLimit = "limit";
    public string Op { get; set; } = "";
    public FunctionChainExpr? Expr { get; set; }
    public IList<string> Inputs { get; } = new List<string>();
    public IList<string> Outputs { get; } = new List<string>();
    public IDictionary<string, FunctionParamValue> Params { get; } = new Dictionary<string, FunctionParamValue>();
}

PARAMETERS:

  • Op (string) -

    The server-recognized operation name, e.g. "map", "sort" or "limit".

  • Expr (FunctionChainExpr?) -

    The expression evaluated by this operation, when it is an expression-based operation.

  • Inputs (IList) -

    The input columns consumed by this operation.

  • Outputs (IList) -

    The output columns produced by this operation.

  • Params (IDictionary) -

    The operation-level parameters keyed by name.

METHODS:

  • Map(string output, FunctionChainExpr expr) (static) -

    Creates a map operation computing the output column from expr.

  • Sort(string by, bool desc, string? tieBreakCol = null) (static) -

    Creates a sort operation sorting by the given column.

  • Limit(int limit, int offset = 0) (static) -

    Creates a limit operation keeping only limit results, skipping the given number of leading results.

FunctionChainExpr

A named function invocation used by a function-chain map operation. Mirrors pymilvus’s FunctionChainExpr / the Java SDK’s FunctionChainExpr.

public sealed class FunctionChainExpr
{
    public string Name { get; set; } = "";
    public IList<FunctionChainArg> Args { get; } = new List<FunctionChainArg>();
    public IDictionary<string, FunctionParamValue> Params { get; } = new Dictionary<string, FunctionParamValue>();
}

PARAMETERS:

  • Name (string) -

    The function implementation name, e.g. "expr", "sum" or "rerank_model".

  • Args (IList) -

    The ordered expression arguments, interpreted by the function implementation by position.

  • Params (IDictionary) -

    The expression-level keyword parameters.

FunctionChainArg

An argument of a function-chain expression: either a column reference (a collection field, temporary variable, or system name such as $score) or a literal value. Mirrors pymilvus’s FunctionChainExprArg / the Java SDK’s FunctionChainArg.

public sealed class FunctionChainArg
{
    public string? ColumnName { get; init; }
    public FunctionParamValue? LiteralValue { get; init; }
}

PARAMETERS:

  • ColumnName (string?) -

    The referenced column name, or null when LiteralValue is used.

  • LiteralValue (FunctionParamValue?) -

    The literal argument value, or null when ColumnName is used.

METHODS:

  • Column(string name) (static) -

    Creates a column-reference argument, e.g. "$score" or a field name.

  • Literal(object value) (static) -

    Creates a literal argument, converted via FunctionParamValue.From(object?).

FunctionParamValue

A dynamically-typed parameter value for function-chain arguments. Values can be built from scalars, strings, field references, and nested values via FunctionParamValue.From(...).

METHODS:

  • From(object? value) (static) -

    Creates a parameter value from a CLR value. Supported types mirror the Java SDK’s FunctionParamValue.from: bool, integral numbers (signed and unsigned, the latter range-checked to int64), float / double, string, byte[], and collections.

  • FromArray(IEnumerable<FunctionParamValue> values) (static) -

    Creates an array parameter value.

  • FromObject(IReadOnlyDictionary<string, FunctionParamValue> fields) (static) -

    Creates an object (map) parameter value.

Example

using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Dql;
using Milvus.Client.V2.Responses.Dql;
using Milvus.Client.V2.Types;

using var client = new MilvusClientV2(new ConnectConfig
{
    Uri = "localhost:19530",
    Username = "root",
    Password = "Milvus"
});

var chain = new FunctionChain
{
    Stage = FunctionChainStage.L2Rerank,
    Name = "rerank_chain"
};
chain.Ops.Add(FunctionChainOp.Sort("score", desc: true));
chain.Ops.Add(FunctionChainOp.Limit(5));

SearchResp results = await client.SearchAsync(new SearchReq
{
    CollectionName = "my_collection",
    VectorFieldName = "embedding",
    Vectors = [new[] { 0.1f, 0.2f, 0.3f, 0.4f }],
    Limit = 10,
    FunctionChains = { chain }
});

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?