FieldSchema
Defines the schema of a single field in a CollectionSchema.
public sealed class FieldSchema
{
public FieldSchema(string name, DataType dataType, bool isPrimaryKey = false, bool autoId = false, bool isPartitionKey = false, string description = "")
public static FieldSchema CreateVarchar(string name, int maxLength, bool isPrimaryKey = false, bool autoId = false, bool isPartitionKey = false, string description = "", bool nullable = false, string? defaultValue = null, bool enableAnalyzer = false, IReadOnlyDictionary<string, object>? analyzerParams = null, bool enableMatch = false, IReadOnlyDictionary<string, object>? multiAnalyzerParams = null)
public static FieldSchema CreateFloatVector(string name, int dimension, string description = "")
public static FieldSchema CreateSparseFloatVector(string name, string description = "")
public string Name { get; }
public DataType DataType { get; }
public bool IsPrimaryKey { get; }
public bool AutoId { get; }
public bool IsPartitionKey { get; }
public string Description { get; }
public int? MaxLength { get; set; }
public int? Dimension { get; set; }
public int? MaxCapacity { get; set; }
public DataType? ElementDataType { get; set; }
public bool Nullable { get; set; }
public object? DefaultValue { get; set; }
public bool EnableAnalyzer { get; set; }
public IReadOnlyDictionary<string, object>? AnalyzerParams { get; set; }
public bool EnableMatch { get; set; }
public IReadOnlyDictionary<string, object>? MultiAnalyzerParams { get; set; }
public bool IsFunctionOutput { get; internal set; }
public bool IsClusteringKey { get; set; }
public bool IsDynamic { get; internal set; }
public long FieldId { get; internal set; }
public IReadOnlyDictionary<string, string>? RawTypeParams { get; internal set; }
public IDictionary<string, string> TypeParams { get; }
}
PARAMETERS:
Name(string) -The field name.
DataType(DataType) -The data type of the field. See DataType.
IsPrimaryKey(bool) -Whether the field is the primary key of the collection.
AutoId(bool) -Whether primary key values are automatically generated by Milvus.
IsPartitionKey(bool) -Whether the field is a partition key.
Description(string) -An optional description for the field.
MaxLength(int?) -The maximum length of a
VarCharfield.Dimension(int?) -The dimensionality of a vector field.
MaxCapacity(int?) -The maximum capacity of an array field.
ElementDataType(DataType?) -The element data type of an array field. See DataType.
Nullable(bool) -Whether the field is nullable.
DefaultValue(object?) -The default value for the field.
EnableAnalyzer(bool) -Whether the analyzer is enabled for this field (BM25 full-text search input fields).
AnalyzerParams(IReadOnlyDictionary? ) -The analyzer parameters, e.g.
new Dictionary<string, object> { ["type"] = "english" }. Mutually exclusive withMultiAnalyzerParams.EnableMatch(bool) -Whether match (BM25 keyword) search is enabled for this field.
MultiAnalyzerParams(IReadOnlyDictionary? ) -The multi-language analyzer parameters for the field. Mutually exclusive with
AnalyzerParams.IsFunctionOutput(bool) -Whether this field is the output of a function (e.g. a BM25 sparse vector field).
IsClusteringKey(bool) -Whether this field is a clustering key.
IsDynamic(bool) -Whether this field is the dynamic (
$meta) field. Only populated when the schema is read back viaDescribeCollection.FieldId(long) -The server-assigned field id, populated when the schema is read back via
DescribeCollection.RawTypeParams(IReadOnlyDictionary? ) -The raw
type_paramskey-value map as returned byDescribeCollection, preserving any keys the SDK does not parse into typed properties.TypeParams(IDictionary) - Additional per-field
type_paramsto send when creating the collection. Keys that map to a typed property (e.g.max_length,dim) are ignored in favor of the typed property.
METHODS:
FieldSchema(string name, DataType dataType, bool isPrimaryKey = false, bool autoId = false, bool isPartitionKey = false, string description = "")-Creates a new field schema. See DataType.
CreateVarchar(...)(static) -Creates a new
VarCharfield schema.maxLengthis the maximum length of the varchar field and must be greater than zero. See DataType.CreateFloatVector(...)(static) -Creates a new
FloatVectorfield schema.dimensionis the dimensionality of the vector and must be at least 2. See DataType.CreateSparseFloatVector(...)(static) -Creates a new
SparseFloatVectorfield schema. See DataType.
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("title", maxLength: 256, nullable: true, defaultValue: "untitled"));
schema.Fields.Add(FieldSchema.CreateVarchar("body", maxLength: 1024, enableAnalyzer: true,
analyzerParams: new Dictionary<string, object> { ["type"] = "english" }));
schema.Fields.Add(FieldSchema.CreateFloatVector("embedding", dimension: 128));
await client.CreateCollectionAsync(new CreateCollectionReq
{
CollectionName = "my_collection",
Schema = schema
});