SundayT1998/milvus-client/index does not have a README file

    IndexParamError

    pub suberror IndexParamError {
    OutOfRange(key~ : String, value~ : Int, expected~ : String)
    InvalidCombination(index_type~ : String, reason~ : String)
    InvalidArgument(reason~ : String)
    } derive(
    Debug
    )

    非法参数组合。上游把这类错误留给服务端,客户端要一次 RPC 往返才知道; 这里在构造期就拦下,错误信息带上参数名与取值范围。

    CreateIndexRequest

    pub(all) struct CreateIndexRequest {
    db_name : String
    collection_name : String
    field_name : String
    index_name : String
    extra_params : Array[(String, String)]
    } derive(Eq,
    Debug
    )

    CreateIndex 的入参。

    CreateIndexRequest::from_index

    fn CreateIndexRequest::from_index(collection_name : String, field_name : String, index : Index, db_name? : String) -> CreateIndexRequest raise IndexParamError

    由索引定义拼出 CreateIndex 入参。

    db_name 留空表示走连接的默认库:Milvus 的 db_name 为空时由服务端 落到默认 database,与传 "default" 等价但少一次显式依赖。

    DescribeIndexRequest

    pub(all) struct DescribeIndexRequest {
    db_name : String
    collection_name : String
    field_name : String
    index_name : String
    } derive(Eq,
    Debug
    )

    DescribeIndex 的入参。field_name 与 index_name 都留空表示「列全部」。

    DescribeIndexRequest::by_field

    fn DescribeIndexRequest::by_field(collection_name : String, field_name : String, db_name? : String) -> DescribeIndexRequest raise IndexParamError

    按字段名查该字段上的索引。

    DescribeIndexRequest::by_name

    fn DescribeIndexRequest::by_name(collection_name : String, index_name : String, db_name? : String) -> DescribeIndexRequest raise IndexParamError

    按索引名查一个索引。

    DescribeIndexRequest::list_all

    fn DescribeIndexRequest::list_all(collection_name : String, db_name? : String) -> DescribeIndexRequest raise IndexParamError

    列出某集合的全部索引。

    DropIndexRequest

    pub(all) struct DropIndexRequest {
    db_name : String
    collection_name : String
    index_name : String
    } derive(Eq,
    Debug
    )

    DropIndex 的入参。

    DropIndexRequest::new

    fn DropIndexRequest::new(collection_name : String, index_name : String, db_name? : String) -> DropIndexRequest raise IndexParamError

    拼出 DropIndex 入参。索引名必填:Milvus 不支持「删该集合的全部索引」, 想全删只能先 DescribeIndex 再逐个 drop,所以这里不提供空名入口。

    Index

    pub(all) struct Index {
    name : String
    metric_type : MetricType
    index_type : IndexType
    params : IndexParams
    }

    一个索引定义:可选名字、类型,以及构建参数。

    Index::index_type

    fn Index::index_type(self : Index) -> IndexType

    索引类型。

    Index::metric_type

    fn Index::metric_type(self : Index) -> MetricType

    度量类型。

    Index::name

    fn Index::name(self : Index) -> String

    索引名。

    Index::params

    fn Index::params(self : Index) -> IndexParams

    索引的构建参数(含 index_type / metric_type)。

    Index::with_extra_params

    fn Index::with_extra_params(self : Index, extra : IndexParams) -> Index

    合并额外构建参数,键名不做白名单,原样透传(服务端校验)。 index_type / metric_type 是保留键,静默忽略。

    Index::with_name

    fn Index::with_name(self : Index, name : String) -> Index

    设置索引名。

    IndexDescription

    pub(all) struct IndexDescription {
    index_name : String
    index_id : Int64
    params : Array[(String, String)]
    field_name : String
    indexed_rows : Int64
    total_rows : Int64
    pending_index_rows : Int64
    state : IndexState
    fail_reason : String
    } derive(Eq,
    Debug
    )

    DescribeIndex 返回的一条索引描述。

    IndexDescription::index_params

    fn IndexDescription::index_params(self : IndexDescription) -> IndexParams

    把回读的参数还原成 IndexParams,键名原样。

    IndexDescription::index_type

    fn IndexDescription::index_type(self : IndexDescription) -> IndexType?

    回读的索引类型。上游把 index_type 放在 params 里,不是独立字段; 返回 None 表示服务端没给这个键(老版本可能不返回)。

    IndexDescription::metric_type

    fn IndexDescription::metric_type(self : IndexDescription) -> MetricType?

    回读的度量类型。

    IndexDescription::progress

    fn IndexDescription::progress(self : IndexDescription) -> Double?

    构建进度:已完成行数 / 总行数。总行数为 0 时返回 None—— 集合还空着,除法没有意义,也不该假装进度是 0%。

    IndexParams

    pub(all) struct IndexParams {
    entries : Array[(String, String)]
    } derive(Eq)

    索引构建参数集合。键名即线上协议键名,原样透传。

    上游每个具体索引类型一个 struct 类型;这里统一成一个 map 承载, 因为最终产物都是 map<string,string>,分成十几个类型只会把 「哪些键对哪种索引有效」这一信息藏进类型名里,而校验仍要手写。
    impl Show for IndexParams

    IndexParams::from_pairs

    fn IndexParams::from_pairs(pairs : Array[(String, String)]) -> IndexParams

    从上游返回的键值对重建。

    IndexParams::get

    fn IndexParams::get(self : IndexParams, key : String) -> String?

    读取一个键。

    IndexParams::new

    空参数集。

    IndexParams::set

    fn IndexParams::set(self : IndexParams, key : String, value : String) -> Unit

    覆盖写入一个键:已存在则原地替换(保持位置),否则追加。

    IndexParams::set_default

    fn IndexParams::set_default(self : IndexParams, key : String, value : String) -> Unit

    只在该键未出现时写入。用于「默认值不该覆盖显式设置」的场景。

    IndexParams::set_int

    fn IndexParams::set_int(self : IndexParams, key : String, value : Int) -> Unit

    把整数值写入,便于调用方在能拿到类型的地方少写一次 to_string。

    IndexParams::size

    fn IndexParams::size(self : IndexParams) -> Int

    键数量。

    IndexParams::to_json

    fn IndexParams::to_json(self : IndexParams) -> String

    转成 JSON 对象字符串。Milvus 的 params 字段在某些入口接受 JSON 串, 这里保持上游 encoding/json 的紧凑格式(无空格),键保持插入序。

    只处理字符串值:上游 builder 产出的值全是字符串形式的数字或枚举名。

    IndexParams::to_pairs

    fn IndexParams::to_pairs(self : IndexParams) -> Array[(String, String)]

    转为 Milvus ExtraParams 需要的键值对序列。

    IndexState

    pub(all) enum IndexState {
    None
    Unissued
    InProgress
    Finished
    Failed
    Retry
    Unknown(Int)
    } derive(Eq,
    Debug
    )

    服务端索引构建状态,取自 common.IndexState。 序号必须与上游对齐:这是 wire 上的枚举值,不是客户端概念。

    IndexState::from_int

    fn IndexState::from_int(n : Int) -> IndexState

    反解上游枚举序号。

    IndexState::is_terminal

    fn IndexState::is_terminal(self : IndexState) -> Bool

    该状态是否表示构建已结束——成功或失败都算结束,再等下去没有意义。 上游 CreateIndexTask::Await 正是在这两个分支上停下的。

    IndexState::to_int

    fn IndexState::to_int(self : IndexState) -> Int

    上游枚举序号。

    IndexType

    pub(all) enum IndexType {
    Flat
    BinFlat
    IvfFlat
    BinIvfFlat
    IvfPQ
    IvfSQ8
    IvfRabitQ
    HNSW
    HNSWSQ
    HNSWPQ
    HNSWPRQ
    IvfHNSW
    AutoIndex
    DiskANN
    AISAQ
    SCANN
    MinHashLSH
    SparseInverted
    SparseWAND
    GpuIvfFlat
    GpuIvfPQ
    GpuCagra
    GpuBruteForce
    Trie
    Sorted
    Inverted
    Bitmap
    Ngram
    FmIndex
    RTree
    } derive(Eq,
    Debug
    )

    index_type 的字面量。与上游 index.IndexType 逐条对齐。

    IndexType::from_string

    fn IndexType::from_string(s : String) -> IndexType?

    反解上游字面量。

    IndexType::to_string

    fn IndexType::to_string(self : IndexType) -> String

    上游字面量。

    MetricType

    pub(all) enum MetricType {
    L2
    IP
    COSINE
    HAMMING
    JACCARD
    TANIMOTO
    Substructure
    Superstructure
    BM25
    MhJaccard
    MaxSim
    MaxSimCosine
    MaxSimL2
    MaxSimIP
    MaxSimHamming
    MaxSimJaccard
    } derive(Eq,
    Debug
    )

    距离度量类型。Milvus 服务端按字符串比对,故用 String 而非枚举序号承载。 上游同名常量在 entity.MetricType,index.MetricType 是它的别名。

    MetricType::from_string

    fn MetricType::from_string(s : String) -> MetricType?

    反解上游字面量;未知串返回 None,不猜测。

    MetricType::to_string

    fn MetricType::to_string(self : MetricType) -> String

    上游使用的字面量。改动这里就是改动线上协议,测试逐条锁住。

    MetricType::valid_for_float_vector

    fn MetricType::valid_for_float_vector(self : MetricType) -> Bool

    该度量是否可用于浮点向量(FloatVector / Float16Vector / BFloat16Vector)。 上游不显式校验这一步,服务端在 CreateIndex 时才拒绝; 客户端提前判能给出更清晰的错误,故单列但不放松服务端语义。

    check_float_vector_metric

    fn check_float_vector_metric(index : Index) -> Unit raise IndexParamError

    给浮点向量的索引补一道度量校验。

    Milvus 用 HAMMING 配 FloatVector 只会在服务端被拒(IllegalMetricType), 客户端提前判可以省一次往返。不改变服务端语义:这里放过的组合,服务端仍可能拒绝。

    create_index_path

    let create_index_path : String

    索引 RPC 的服务路径,取自 milvus.proto 的 MilvusService。 gRPC 方法名是 / + 全限定服务名 + / + 方法名。

    describe_index_path

    let describe_index_path : String

    见 create_index_path。

    drop_index_path

    let drop_index_path : String

    见 create_index_path。

    find_by_field

    fn find_by_field(descriptions : Array[IndexDescription], field_name : String) -> Array[IndexDescription]

    在响应里按字段名挑该字段上的全部索引。

    find_by_name

    fn find_by_name(descriptions : Array[IndexDescription], index_name : String) -> IndexDescription?

    在响应里按索引名挑一条。

    上游 DescribeIndex 用 for 循环找名字相等的一条,找不到就报 IndexNotFound; 这里同样不取「第一条」充数——多索引集合下那是错的。

    index_type_key

    let index_type_key : String

    index_type 的键名。

    metric_type_key

    let metric_type_key : String

    metric_type 的键名。

    new_auto_index

    fn new_auto_index(metric_type : MetricType) -> Index

    AUTOINDEX:把参数完全交给服务端调优。 上游 NewAutoIndex 只写 index_type 与 metric_type。

    new_flat_index

    fn new_flat_index(metric_type : MetricType) -> Index

    FLAT:暴力检索,只有 metric_type 与 index_type。

    new_generic_index

    fn new_generic_index(name : String, params : IndexParams) -> Index raise IndexParamError

    通用索引:调用方自己给全参数,index_type 从入参里取。 上游 NewGenericIndex 同名同义,留作「构建器还没覆盖的参数」的出口。

    new_hnsw_index

    fn new_hnsw_index(metric_type : MetricType, m? : Int, ef_construction? : Int) -> Index raise IndexParamError

    HNSW:图索引,M 是每层邻居数,efConstruction 是建图时的候选队列长度。

    上游默认值 M=16、efConstruction=200(Milvus 文档与 Go SDK 示例一致); 越界检查与 knowhere 的 CheckAndAdjust 对齐:M ≥ 2,efConstruction ≥ 1。

    new_ivf_flat_index

    fn new_ivf_flat_index(metric_type : MetricType, nlist? : Int) -> Index raise IndexParamError

    IVF_FLAT:倒排 + 原始向量,nlist 是聚类中心数。 上游 NewIvfFlatIndex 不校验,服务端要求 nlist ∈ [1, 65536]。