FunctionSchema

Describes a function in a collection schema, such as a BM25 full-text-search or text-embedding function.

public sealed class FunctionSchema
{
    public FunctionSchema(string name, FunctionType type, IEnumerable<string> inputFieldNames, IEnumerable<string> outputFieldNames, string description = "", long id = 0)

    public static FunctionSchema CreateBm25(string name, string inputFieldName, string outputFieldName, string description = "", IDictionary<string, string>? @params = null)

    public long Id { get; }
    public string Name { get; }
    public FunctionType Type { get; }
    public string Description { get; }
    public IList<string> InputFieldNames { get; }
    public IList<string> OutputFieldNames { get; }
    public IDictionary<string, string>? Params { get; }
}

PARAMETERS:

  • Id (long) -

    The ID of the function.

  • Name (string) -

    The name of the function.

  • Type (FunctionType) -

    The type of the function. See FunctionType.

  • Description (string) -

    A description of the function.

  • InputFieldNames (IList) -

    The names of the input fields.

  • OutputFieldNames (IList) -

    The names of the output fields.

  • Params (IDictionary?) -

    Optional function parameters sent to the server, e.g. BM25 settings. Defaults to null.

METHODS:

  • FunctionSchema(string name, FunctionType type, IEnumerable<string> inputFieldNames, IEnumerable<string> outputFieldNames, string description = "", long id = 0) -

    Initializes a new instance of the FunctionSchema class.

  • CreateBm25(string name, string inputFieldName, string outputFieldName, string description = "", IDictionary<string, string>? @params = null) (static) -

    Creates a BM25 full-text-search function. inputFieldName is the name of the input field and outputFieldName is the name of the output field.

Example

using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Collection;
using Milvus.Client.V2.Types;

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

var schema = new CollectionSchema { Name = "my_collection" };
schema.Fields.Add(new FieldSchema("id", DataType.Int64, isPrimaryKey: true, autoId: true));
schema.Fields.Add(FieldSchema.CreateVarchar("text", maxLength: 1024, enableAnalyzer: true));
schema.Fields.Add(FieldSchema.CreateSparseFloatVector("sparse"));

schema.Functions.Add(FunctionSchema.CreateBm25(
    name: "bm25",
    inputFieldName: "text",
    outputFieldName: "sparse"));

await client.CreateCollectionAsync(new CreateCollectionReq
{
    CollectionName = "my_collection",
    Schema = schema
});

Try Managed Milvus for Free

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

Get Started
Feedback

Was this page helpful?