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

    Unary

    type Unary = async (String, Bytes) -> Bytes raise
    RpcError

    一次 unary 调用的形状:给路径和已编码的 protobuf body,拿回已解码前的 响应字节。

    把它抽成函数值而不是直接依赖 @transport/native,是因为模块 preferred_target = "wasm":client 这层必须在 wasm / js 下编得过, 而真连 socket 的实现是 native 专属的(见 client/native)。

    ClientError

    pub suberror ClientError {
    Transport(
    RpcError
    )
    Server(
    MerError
    )
    Schema(String)
    Encode(String)
    Decode(String)
    }

    一次调用失败。四种来源分开,是因为上层的处置不一样: 传输问题可以重试,服务端拒绝要看错误码,schema 不合说明本地模型过时, 编解码失败说明客户端有 bug。
    impl Show for ClientError

    ClientError::code

    fn ClientError::code(self : ClientError) -> Int

    拿服务端错误码;不是服务端拒绝就返回 @errors.unexpected_code。

    ClientError::is_deadline_exceeded

    fn ClientError::is_deadline_exceeded(self : ClientError) -> Bool

    这次失败是不是超时。

    ClientError::is_retryable

    fn ClientError::is_retryable(self : ClientError) -> Bool

    服务端是否把这次失败标成可重试。 与 @errors.is_retryable_err 一致:只看服务端下发的 retriable, 不做本地猜测。

    ClientError::is_transport

    fn ClientError::is_transport(self : ClientError) -> Bool

    传输层是否还能用。Client 的方法里,只有这一类才值得原样重试。

    ClientError::server_error

    底层错误对象,便于上层用 @errors.same_code 之类的判等。

    IteratorError

    pub(all) suberror IteratorError {
    EndOfIterator
    Closed
    Setup(String)
    Rpc(Bool, Bool, String)
    } derive(
    Debug
    )

    迭代器相关的失败。

    EndOfIterator 是正常收尾而不是故障 —— 单独一类,因为调用方的处置 与其余几种完全不同:其余几种要么重试要么放弃,它只是停下来。

    IteratorError::is_closed

    fn IteratorError::is_closed(self : IteratorError) -> Bool

    已经关掉的迭代器再取下一批。

    IteratorError::is_end_of_iterator

    fn IteratorError::is_end_of_iterator(self : IteratorError) -> Bool

    EndOfIterator 是正常收尾,值得单拎出来让调用方 while 到它为止。

    IteratorError::is_retryable

    fn IteratorError::is_retryable(self : IteratorError) -> Bool

    这次失败值不值得重试。传输层失败按 ClientError 的口径看, 服务端拒绝则只看服务端下发的 retriable,不做本地猜测。

    IteratorError::is_transport_failure

    fn IteratorError::is_transport_failure(self : IteratorError) -> Bool

    这次失败是不是传输层的(可以原样重试的那一类)。 非 RPC 失败一律为 false。

    Client

    pub struct Client {
    config :
    Config

    call : async (String, Bytes) -> Bytes raise
    RpcError

    }

    连到 Milvus 的客户端。

    config 只用来取 dbName、超时、metadata 之类的默认值;真正把字 节发出去的是 call。

    Client::config

    客户端持有的配置。

    Client::create_collection

    async fn Client::create_collection(self : Client, option : CreateCollectionOption) -> Unit raise ClientError

    建集合。schema 不合法会在发出请求之前就报 ClientError::Schema。

    上游还在这里断言 Validate() error(客户端预检)。本移植把这一步 显式化:schema 走一遍 @entity.CollectionSchema::validate, 快速建表也走,因为合成出来的表同样可能不合法(比如 dim 为 0)。

    Client::create_index

    async fn Client::create_index(self : Client, option : CreateIndexOption) -> Unit raise ClientError

    给字段建索引。

    @index 里装配好的 index_type / metric_type 与其余构建参数一并 作为 extra_params 发出去,与上游 CreateIndex 的组包方式一致。

    Client::create_partition

    async fn Client::create_partition(self : Client, option : CreatePartitionOption) -> Unit raise ClientError

    建一个分区。分区是集合内的写入分组,检索时可按 partition_names 收窄。

    Client::delete

    async fn Client::delete(self : Client, option : DeleteOption) -> MutationResult raise ClientError

    删。MutationResult.delete_count 是服务端实际删掉的条数。

    Client::describe_collection

    async fn Client::describe_collection(self : Client, option : DescribeCollectionOption) -> CollectionDescription raise ClientError

    查集合元信息。

    Client::describe_index

    查集合上的索引。返回的每条都带服务端回读的参数与构建状态。

    Client::drop_collection

    async fn Client::drop_collection(self : Client, option : DropCollectionOption) -> Unit raise ClientError

    删集合,连带它的数据一起删。

    Client::drop_index

    async fn Client::drop_index(self : Client, option : DropIndexOption) -> Unit raise ClientError

    删掉一个索引。

    Client::drop_partition

    async fn Client::drop_partition(self : Client, option : DropPartitionOption) -> Unit raise ClientError

    删分区,连带里面的数据一起删。这是不可逆的。

    Client::flush

    async fn Client::flush(self : Client, option : FlushOption) -> FlushTask raise ClientError

    把集合的已插入数据刷成持久化 segment。

    Flush 只触发;真正落盘要等 FlushTask::wait。返回的任务里带上 服务端给的 segment id 与 flush 时间戳,wait 拿它们去 GetFlushState。

    Client::get_flush_state

    async fn Client::get_flush_state(self : Client, option : GetFlushStateOption) -> Bool raise ClientError

    查这些 segment 是否已落盘。FlushTask::is_flushed 是它的糖。

    Client::get_load_state

    async fn Client::get_load_state(self : Client, option : GetLoadStateOption) -> LoadState raise ClientError

    查集合 / 分区的加载状态。

    与上游一致:状态是 Loading 时顺带查一次进度,这样调用方拿到的 progress 在加载中才有意义;其余状态进度留 0。

    Client::has_collection

    async fn Client::has_collection(self : Client, option : DescribeCollectionOption) -> Bool raise ClientError

    集合是否存在。

    上游用 DescribeCollection 实现,把 ErrCollectionNotFound 当成 「不存在」而不是失败 —— 别指望用 HasCollection RPC, 上游的 HasCollection 也是这么走的。

    Client::has_partition

    async fn Client::has_partition(self : Client, option : HasPartitionOption) -> Bool raise ClientError

    分区是否存在。

    与 HasCollection 不同,上游这里用的是真 HasPartition RPC (返回 BoolResponse),不是「Describe 然后接 not-found」。

    Client::insert

    async fn Client::insert(self : Client, option : WriteOption) -> MutationResult raise ClientError

    插入。返回服务端生成的主键(auto_id 打开时才有)与写入计数。

    Client::list_collections

    async fn Client::list_collections(self : Client, option : ListCollectionsOption) -> Array[String] raise ClientError

    列出库里的集合名。

    Client::list_partitions

    async fn Client::list_partitions(self : Client, option : ListPartitionsOption) -> Array[String] raise ClientError

    列出集合的全部分区名,含默认分区 _default。

    Client::load_collection

    async fn Client::load_collection(self : Client, option : LoadCollectionOption) -> LoadTask raise ClientError

    加载集合。返回的 LoadTask 可以用 wait 等到加载完成, 也可以拿 progress 自己轮询。

    Client::load_partitions

    async fn Client::load_partitions(self : Client, option : LoadPartitionsOption) -> LoadTask raise ClientError

    加载分区。返回的 LoadTask 只等这些分区。

    Client::new

    挂上一条已有的连接。call 通常是 @native.Client::unary 的部分应用。

    Client::query

    async fn Client::query(self : Client, option : QueryOption) -> QueryResult raise ClientError

    查询。

    与上游一致:响应里带了 output_fields 就优先用响应的那份 (服务端可能因为 * 通配或动态字段补出更多列),否则回落到请求里的。

    Client::query_iterator

    async fn Client::query_iterator(self : Client, option : QueryIteratorOption) -> QueryIterator raise IteratorError

    建立查询迭代器。这一步会先 DescribeCollection 拿 schema, 所以集合不存在、或主键不可排序,都在 next 之前就失败。

    Client::release_collection

    async fn Client::release_collection(self : Client, option : ReleaseCollectionOption) -> Unit raise ClientError

    把集合从查询节点卸载。卸载后检索会报错,这是判据。

    Client::release_partitions

    async fn Client::release_partitions(self : Client, option : ReleasePartitionsOption) -> Unit raise ClientError

    卸载分区。

    Client::search

    async fn Client::search(self : Client, option : SearchOption) -> SearchResult raise ClientError

    检索。

    Client::search_iterator

    async fn Client::search_iterator(self : Client, option : SearchIteratorOption) -> SearchIterator raise IteratorError

    建立检索迭代器。

    先 DescribeCollection 拿集合 ID —— V2 协议要求翻页请求带上它; 这一步也顺带把「集合存在吗」问掉了。

    Client::upsert

    async fn Client::upsert(self : Client, option : WriteOption) -> MutationResult raise ClientError

    插入或更新。

    与上游一致:upsert 的主键必须由调用方给出(哪怕 schema 是 auto_id), 因为主键就是查找键。

    CollectionDescription

    pub(all) struct CollectionDescription {
    name : String
    id : Int64
    schema :
    CollectionSchema

    physical_channels : Array[String]
    virtual_channels : Array[String]
    consistency_level : ConsistencyLevel
    shard_num : Int
    properties : Array[(String, String)]
    update_timestamp : UInt64
    } derive(
    Debug
    )

    集合的元信息。对应上游 entity.Collection 里 SDK 层面的那几项。

    CollectionLoadState

    pub(all) enum CollectionLoadState {
    NotExist
    NotLoad
    Loading
    Loaded
    Unknown(Int)
    } derive(Eq,
    Debug
    )

    加载档位。序号与 common.LoadState 对齐,to_int / from_int 是 wire 上的枚举值,不是客户端概念。

    CollectionLoadState::from_int

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

    CollectionLoadState::from_proto

    从生成的 proto 枚举翻过来。

    CollectionLoadState::is_loaded

    fn CollectionLoadState::is_loaded(self : CollectionLoadState) -> Bool

    加载完成的判据:Loaded 即成功,其余都还没到。

    CollectionLoadState::to_int

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

    ConsistencyLevel

    pub(all) enum ConsistencyLevel {
    Strong
    Session
    Bounded
    Eventually
    Customized
    } derive(Eq,
    Debug
    )

    Milvus 的一致性等级。与 common.ConsistencyLevel 逐条对齐。

    ConsistencyLevel::from_int

    fn ConsistencyLevel::from_int(value : Int) -> ConsistencyLevel

    反解 proto 枚举值。越界一律退回 Bounded(下游的默认值), 因为协议未来加档时旧客户端只能按默认档处理。

    ConsistencyLevel::to_int

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

    上游字面量 / proto 枚举值。

    CreateCollectionOption

    pub(all) struct CreateCollectionOption {
    name : String
    shard_num : Int
    schema :
    CollectionSchema
    ?
    dim : Int
    auto_id : Bool
    enable_dynamic_schema : Bool
    pk_field_name : String
    vector_field_name : String
    varchar_pk : Bool
    varchar_pk_max_length : Int
    consistency_level : ConsistencyLevel
    properties : Array[(String, String)]
    num_partitions : Int64
    }

    建集合的入参。对应上游 createCollectionOption。

    schema 为 None 时就是「快速建表」:按 dim 合成一张 主键 + 向量字段的默认表,字段名与上游 SimpleCreateCollectionOptions 一致(id / vector)。

    CreateCollectionOption::with_auto_id

    fn CreateCollectionOption::with_auto_id(self : CreateCollectionOption, auto_id : Bool) -> CreateCollectionOption

    CreateCollectionOption::with_consistency_level

    CreateCollectionOption::with_dynamic_schema

    fn CreateCollectionOption::with_dynamic_schema(self : CreateCollectionOption, enable? : Bool) -> CreateCollectionOption

    CreateCollectionOption::with_num_partitions

    fn CreateCollectionOption::with_num_partitions(self : CreateCollectionOption, num_partitions : Int64) -> CreateCollectionOption

    CreateCollectionOption::with_pk_field_name

    fn CreateCollectionOption::with_pk_field_name(self : CreateCollectionOption, name : String) -> CreateCollectionOption

    CreateCollectionOption::with_property

    fn CreateCollectionOption::with_property(self : CreateCollectionOption, key : String, value : String) -> CreateCollectionOption

    追加一条集合属性。同名键覆盖已有的。

    CreateCollectionOption::with_shard_num

    fn CreateCollectionOption::with_shard_num(self : CreateCollectionOption, shard_num : Int) -> CreateCollectionOption

    CreateCollectionOption::with_varchar_pk

    fn CreateCollectionOption::with_varchar_pk(self : CreateCollectionOption, varchar_pk : Bool, max_length : Int) -> CreateCollectionOption

    CreateCollectionOption::with_vector_field_name

    fn CreateCollectionOption::with_vector_field_name(self : CreateCollectionOption, name : String) -> CreateCollectionOption

    CreateIndexOption

    pub(all) struct CreateIndexOption {
    collection_name : String
    field_name : String
    index :
    Index

    }

    建索引的入参。

    CreatePartitionOption

    pub(all) struct CreatePartitionOption {
    collection_name : String
    partition_name : String
    }

    建分区的入参。对应上游 createPartitionOpt。

    DeleteOption

    pub(all) struct DeleteOption {
    collection_name : String
    partition_name : String
    expr : String
    consistency_level : ConsistencyLevel?
    }

    删除的入参。

    上游用一个统一的 deleteOption,表达式和一致性等级二选一地填。 这里把「用主键删」和「用表达式删」分开成两个构造函数, 因为主键那一支要拼表达式(见 pks_expr),跟手写表达式不是一回事。

    DeleteOption::with_consistency_level

    fn DeleteOption::with_consistency_level(self : DeleteOption, level : ConsistencyLevel) -> DeleteOption

    DeleteOption::with_partition

    fn DeleteOption::with_partition(self : DeleteOption, partition_name : String) -> DeleteOption

    DescribeCollectionOption

    pub(all) struct DescribeCollectionOption {
    name : String
    }

    描述集合的入参。

    DescribeIndexOption

    pub(all) struct DescribeIndexOption {
    collection_name : String
    field_name : String
    index_name : String
    }

    描述索引的入参。field_name / index_name 都留空表示列全部。

    DescribeIndexOption::with_field_name

    fn DescribeIndexOption::with_field_name(self : DescribeIndexOption, field_name : String) -> DescribeIndexOption

    DescribeIndexOption::with_index_name

    fn DescribeIndexOption::with_index_name(self : DescribeIndexOption, index_name : String) -> DescribeIndexOption

    DropCollectionOption

    pub(all) struct DropCollectionOption {
    name : String
    }

    删集合的入参。

    DropIndexOption

    pub(all) struct DropIndexOption {
    collection_name : String
    index_name : String
    }

    删索引的入参。Milvus 要求给出索引名,空串会被服务端拒绝。

    DropPartitionOption

    pub(all) struct DropPartitionOption {
    collection_name : String
    partition_name : String
    }

    删分区的入参。

    FlushOption

    pub(all) struct FlushOption {
    collection_name : String
    check_interval_millis : Int
    }

    flush 的入参。对应上游 flushOption:一次只 flush 一个集合 (FlushRequest.collection_names 是 repeated,但上游只塞一个)。

    FlushOption::with_check_interval_millis

    fn FlushOption::with_check_interval_millis(self : FlushOption, millis : Int) -> FlushOption

    FlushTask

    pub struct FlushTask {
    client : Client
    collection_name : String
    segment_ids : Array[Int64]
    flushed_segment_ids : Array[Int64]
    flush_timestamp : UInt64
    interval_millis : Int
    }

    flush 任务。拿着 Flush 响应里那段属于本集合的信息, Await 到落盘完成。

    FlushTask::collection_name

    fn FlushTask::collection_name(self : FlushTask) -> String

    FlushTask::flush_timestamp

    fn FlushTask::flush_timestamp(self : FlushTask) -> UInt64

    FlushTask::flushed_segment_ids

    fn FlushTask::flushed_segment_ids(self : FlushTask) -> Array[Int64]

    FlushTask::is_flushed

    async fn FlushTask::is_flushed(self : FlushTask) -> Bool raise ClientError

    查一次落盘状态。不等待。

    FlushTask::segment_ids

    fn FlushTask::segment_ids(self : FlushTask) -> Array[Int64]

    FlushTask::wait

    async fn FlushTask::wait(self : FlushTask) -> Unit raise ClientError

    轮询到落盘完成,与上游 FlushTask.Await 一致:先等一个间隔再查第一次。

    GetFlushStateOption

    pub(all) struct GetFlushStateOption {
    collection_name : String
    segment_ids : Array[Int64]
    flush_timestamp : UInt64
    }

    GetFlushState 的入参。上层拿 FlushTask 里的字段直接查时用这个。

    GetLoadStateOption

    pub(all) struct GetLoadStateOption {
    collection_name : String
    partition_names : Array[String]
    }

    查加载状态的入参。

    HasPartitionOption

    pub(all) struct HasPartitionOption {
    collection_name : String
    partition_name : String
    }

    查分区是否存在的入参。

    IteratorKey

    type IteratorKey derive(
    Debug
    )

    翻页游标的列名与类型。

    ListCollectionsOption

    pub(all) struct ListCollectionsOption {
    show_loaded : Bool
    }

    列集合的入参。上游就一个空请求,这里保留一个类型, 以便将来加 type / db_name 时不动调用点。

    ListPartitionsOption

    pub(all) struct ListPartitionsOption {
    collection_name : String
    }

    列分区的入参。上游就一个集合名,type 固定 All。

    LoadCollectionOption

    pub(all) struct LoadCollectionOption {
    collection_name : String
    replica_number : Int
    resource_groups : Array[String]
    load_fields : Array[String]
    skip_load_dynamic_field : Bool
    load_params : Array[(String, String)]
    refresh : Bool
    check_interval_millis : Int
    }

    加载集合的入参。对应上游 loadCollectionOption。

    LoadCollectionOption::with_check_interval_millis

    fn LoadCollectionOption::with_check_interval_millis(self : LoadCollectionOption, millis : Int) -> LoadCollectionOption

    LoadCollectionOption::with_load_fields

    fn LoadCollectionOption::with_load_fields(self : LoadCollectionOption, load_fields : Array[String]) -> LoadCollectionOption

    LoadCollectionOption::with_load_param

    fn LoadCollectionOption::with_load_param(self : LoadCollectionOption, key : String, value : String) -> LoadCollectionOption

    追加一条加载参数。同名键覆盖已有的。

    LoadCollectionOption::with_refresh

    fn LoadCollectionOption::with_refresh(self : LoadCollectionOption, refresh? : Bool) -> LoadCollectionOption

    LoadCollectionOption::with_replica

    fn LoadCollectionOption::with_replica(self : LoadCollectionOption, replica_number : Int) -> LoadCollectionOption

    LoadCollectionOption::with_replica_number

    fn LoadCollectionOption::with_replica_number(self : LoadCollectionOption, replica_number : Int) -> LoadCollectionOption

    with_replica 的别名。上游 Go 侧叫 WithReplica, 早先的集成自检按 with_replica_number 写,两个都留着少一次改名。

    LoadCollectionOption::with_resource_groups

    fn LoadCollectionOption::with_resource_groups(self : LoadCollectionOption, resource_groups : Array[String]) -> LoadCollectionOption

    LoadCollectionOption::with_skip_load_dynamic_field

    fn LoadCollectionOption::with_skip_load_dynamic_field(self : LoadCollectionOption, skip? : Bool) -> LoadCollectionOption

    LoadPartitionsOption

    pub(all) struct LoadPartitionsOption {
    collection_name : String
    partition_names : Array[String]
    replica_number : Int
    resource_groups : Array[String]
    load_fields : Array[String]
    skip_load_dynamic_field : Bool
    load_params : Array[(String, String)]
    refresh : Bool
    check_interval_millis : Int
    }

    加载分区的入参。字段与 LoadCollectionOption 一一对应,只是多了分区名。

    LoadPartitionsOption::with_check_interval_millis

    fn LoadPartitionsOption::with_check_interval_millis(self : LoadPartitionsOption, millis : Int) -> LoadPartitionsOption

    LoadPartitionsOption::with_load_fields

    fn LoadPartitionsOption::with_load_fields(self : LoadPartitionsOption, load_fields : Array[String]) -> LoadPartitionsOption

    LoadPartitionsOption::with_load_param

    fn LoadPartitionsOption::with_load_param(self : LoadPartitionsOption, key : String, value : String) -> LoadPartitionsOption

    追加一条加载参数。同名键覆盖已有的。

    LoadPartitionsOption::with_refresh

    fn LoadPartitionsOption::with_refresh(self : LoadPartitionsOption, refresh? : Bool) -> LoadPartitionsOption

    LoadPartitionsOption::with_replica

    fn LoadPartitionsOption::with_replica(self : LoadPartitionsOption, replica_number : Int) -> LoadPartitionsOption

    LoadPartitionsOption::with_replica_number

    fn LoadPartitionsOption::with_replica_number(self : LoadPartitionsOption, replica_number : Int) -> LoadPartitionsOption

    with_replica 的别名,理由同 LoadCollectionOption::with_replica_number。

    LoadPartitionsOption::with_resource_groups

    fn LoadPartitionsOption::with_resource_groups(self : LoadPartitionsOption, resource_groups : Array[String]) -> LoadPartitionsOption

    LoadPartitionsOption::with_skip_load_dynamic_field

    fn LoadPartitionsOption::with_skip_load_dynamic_field(self : LoadPartitionsOption, skip? : Bool) -> LoadPartitionsOption

    LoadState

    pub(all) struct LoadState {
    state : CollectionLoadState
    progress : Int64
    } derive(Eq,
    Debug
    )

    集合 / 分区的加载状态。对应上游 entity.LoadState。

    LoadTask

    pub struct LoadTask {
    client : Client
    collection_name : String
    partition_names : Array[String]
    interval_millis : Int
    refresh : Bool
    }

    加载任务。上游 LoadTask:拿着集合名与轮询间隔,Await 到加载完成。

    LoadTask::collection_name

    fn LoadTask::collection_name(self : LoadTask) -> String

    LoadTask::is_loaded

    async fn LoadTask::is_loaded(self : LoadTask) -> Bool raise ClientError

    这块数据现在能不能查。refresh 模式下看的是 refresh_progress。

    LoadTask::partition_names

    fn LoadTask::partition_names(self : LoadTask) -> Array[String]

    LoadTask::progress

    async fn LoadTask::progress(self : LoadTask) -> Int64 raise ClientError

    查一次加载进度(0–100)。不等待。

    LoadTask::wait

    async fn LoadTask::wait(self : LoadTask) -> Unit raise ClientError

    轮询到加载完成。间隔取 check_interval_millis,与上游 LoadTask.Await 一致:先等一个间隔再查第一次。

    上游靠 ctx.Done() 退出;本移植里取消是 @async.sleep 抛出的, 按 Code::Cancelled 归到 Transport 一类,调用方仍可用 @async.with_timeout 之类的外层机制收口。

    MutationResult

    pub(all) struct MutationResult {
    ids :
    ColumnValue
    ?
    insert_count : Int64
    delete_count : Int64
    upsert_count : Int64
    timestamp : UInt64
    } derive(
    Debug
    )

    一次写入的结果。与上游 InsertResult / UpsertResult / DeleteResult 合并成一条:三个 RPC 返回的都是同一个 MutationResult。

    MutationResult::has_ids

    fn MutationResult::has_ids(self : MutationResult) -> Bool

    结果里没有主键(比如 delete)时是 None。

    QueryCursor

    type QueryCursor derive(
    Debug
    )

    主键游标的两种形态。整数主键与字符串主键的翻页表达式不同, 类型在建立迭代器时从 schema 定下来,往后只走对应那一支。

    QueryCursorKind

    type QueryCursorKind derive(Eq,
    Debug
    )

    主键能被表达式排序的两个类型。上游只认 Int64 与 VarChar, 其余的(Uuid 之类)在建立迭代器时就报错,而不是翻出个错序的结果。

    QueryIterator

    pub struct QueryIterator {
    // private fields
    }

    查询迭代器。逐批问,靠主键游标往后挪。

    字段私有:next / close / is_closed 之外没有别的用法, 把游标暴露出去只会让调用方有办法把状态搞乱。

    QueryIterator::close

    fn QueryIterator::close(self : QueryIterator) -> Unit

    关掉迭代器:之后的 next 报 EndOfIterator/Closed。

    查询迭代器在服务端没有会话 —— 状态全在客户端,没有东西要释放。 保留 close 是为了让调用方的 defer 对两条迭代器一视同仁, 也为了把「已经翻完了」这件事显式记下来。

    不声明 raise:这里真的没有会失败的动作。SearchIterator::close 会 返回 Bool(服务端侧关成没关成),查询迭代器没有对应物,所以这里就是 一个纯净的收尾,调用方用 defer 挂上也不必有 try。

    QueryIterator::is_closed

    fn QueryIterator::is_closed(self : QueryIterator) -> Bool

    迭代器还能不能取下一批。close 之后为假,翻完之后也为假。

    QueryIterator::next

    async fn QueryIterator::next(iterator : QueryIterator) -> QueryResult raise IteratorError

    取下一批。到末尾报 EndOfIterator,关掉了报 Closed。

    每次请求都问 batch_size 行,服务端给多少就回多少;不做跨批截断, 上限只控制「还发不发下一次请求」(见文件头第 2 条)。

    QueryIteratorOption

    pub(all) struct QueryIteratorOption {
    collection_name : String
    partition_names : Array[String]
    expr : String
    output_fields : Array[String]
    batch_size : Int
    limit : Int64
    consistency_level : ConsistencyLevel?
    } derive(
    Debug
    )

    查询迭代器的入参。对应上游 queryIteratorOption。

    batch_size 是每批行数,limit 是整体上限(iterator_unlimited 表示 取到空为止)。output_fields 里一定会有主键 —— 翻页靠它做游标, 调用方没写也会被补上,与上游一致。

    QueryIteratorOption::with_batch_size

    fn QueryIteratorOption::with_batch_size(self : QueryIteratorOption, batch_size : Int) -> QueryIteratorOption

    QueryIteratorOption::with_consistency_level

    fn QueryIteratorOption::with_consistency_level(self : QueryIteratorOption, level : ConsistencyLevel) -> QueryIteratorOption

    QueryIteratorOption::with_filter

    fn QueryIteratorOption::with_filter(self : QueryIteratorOption, expr : String) -> QueryIteratorOption

    QueryIteratorOption::with_limit

    fn QueryIteratorOption::with_limit(self : QueryIteratorOption, limit : Int64) -> QueryIteratorOption

    整体上限。负数按「无限」处理,与上游 WithIteratorLimit 一致。

    QueryIteratorOption::with_output_fields

    fn QueryIteratorOption::with_output_fields(self : QueryIteratorOption, output_fields : Array[String]) -> QueryIteratorOption

    QueryIteratorOption::with_partitions

    fn QueryIteratorOption::with_partitions(self : QueryIteratorOption, partition_names : Array[String]) -> QueryIteratorOption

    QueryOption

    pub(all) struct QueryOption {
    collection_name : String
    partition_names : Array[String]
    expr : String
    output_fields : Array[String]
    query_params : Array[(String, String)]
    consistency_level : ConsistencyLevel?
    }

    查询的入参。对应上游 queryOption。

    QueryOption::with_consistency_level

    fn QueryOption::with_consistency_level(self : QueryOption, level : ConsistencyLevel) -> QueryOption

    QueryOption::with_filter

    fn QueryOption::with_filter(self : QueryOption, expr : String) -> QueryOption

    QueryOption::with_int64_ids

    fn QueryOption::with_int64_ids(self : QueryOption, field_name : String, ids : Array[Int64]) -> QueryOption

    按主键查。与上游 WithIDs 一致,主键被拼进表达式而不是单独传 — 服务端没有「按主键批量取」的字段,只有 expr。

    QueryOption::with_limit

    fn QueryOption::with_limit(self : QueryOption, limit : Int) -> QueryOption

    QueryOption::with_offset

    fn QueryOption::with_offset(self : QueryOption, offset : Int) -> QueryOption

    QueryOption::with_order_by_fields

    fn QueryOption::with_order_by_fields(self : QueryOption, fields : Array[String]) -> QueryOption

    排序字段。每项写作 name 或 name:asc / name:desc, 缺省升序;服务端要求带排序字段时必须显式给 limit。

    QueryOption::with_output_fields

    fn QueryOption::with_output_fields(self : QueryOption, output_fields : Array[String]) -> QueryOption

    QueryOption::with_partitions

    fn QueryOption::with_partitions(self : QueryOption, partition_names : Array[String]) -> QueryOption

    QueryOption::with_string_ids

    fn QueryOption::with_string_ids(self : QueryOption, field_name : String, ids : Array[String]) -> QueryOption

    QueryResult

    pub(all) struct QueryResult {
    columns : Array[
    Column
    ]
    names : Array[String]
    } derive(
    Debug
    )

    一次查询的结果:按输出字段摊成的列,外加列名。

    上游返回带 schema 的 ResultSet,字段的 DataType 也留在列上; 这里保留 @column.ColumnValue 的 FieldData.type_ 信息, 由 QueryResult::column 按名取。

    QueryResult::column

    按字段名取一列。

    QueryResult::has_column

    fn QueryResult::has_column(self : QueryResult, name : String) -> Bool

    true 表示结果里没有这一列 —— 与「列存在但全是 null」不同, 后者也返回 Some。

    QueryResult::len

    fn QueryResult::len(self : QueryResult) -> Int

    结果行数。没有列时是 0。

    RawSearchResult

    type RawSearchResult derive(
    Debug
    )

    一次检索的原始响应 + 解好的命中。

    迭代器两条都要:命中给调用方,SearchResultData 上的 search_iterator_v2_results 是翻下一页的凭据,SearchResult 装不下它。

    包内可见,不对外 —— 外面拿到的是 SearchResult,需要续页凭据的是 迭代器,而它在同一个包里。

    ReleaseCollectionOption

    pub(all) struct ReleaseCollectionOption {
    collection_name : String
    }

    卸载集合的入参。

    ReleasePartitionsOption

    pub(all) struct ReleasePartitionsOption {
    collection_name : String
    partition_names : Array[String]
    }

    卸载分区的入参。

    SearchCursor

    type SearchCursor derive(
    Debug
    )

    服务端侧游标的状态:上一批的 token 与最后一条命中的距离下界。 两者都原样带回给服务端,客户端不解释它们。

    SearchHit

    pub(all) struct SearchHit {
    id : String
    string_id : Bool
    score : Float
    fields : Map[String,
    ColumnValue
    ]
    } derive(
    Debug
    )

    一条命中。id 是主键的文本形式:整数主键与字符串主键都收敛到 String,因为 Hit 的消费方几乎总是拿它去查行,而不是做算术。

    string_id 只对字符串主键为真,用来区分「主键就是 "12"」和 「整数主键 12」。

    SearchIterator

    pub struct SearchIterator {
    // private fields
    }

    检索迭代器。

    服务端侧会话,所以 close 不只是打个标记:会发一次空检索把游标收掉, 免得服务端为没人再读的会话留着资源。

    SearchIterator::close

    async fn SearchIterator::close(iterator : SearchIterator) -> Bool

    关掉迭代器。

    服务端侧的游标不会自己过期,所以这里补一次空检索让服务端把那个 session 收掉,顺便把本地状态钉成「已关」。

    空检索失败不往上抛:调用方多半是在 defer 里关的,这时候再报一个 「关不掉」也救不回来,反倒会把原本的错误盖掉。返回值告诉调用方这次 关闭是干净收尾(true)还是服务端侧没关成(false)。

    SearchIterator::is_closed

    fn SearchIterator::is_closed(self : SearchIterator) -> Bool

    迭代器是不是已经收尾。

    SearchIterator::next

    async fn SearchIterator::next(iterator : SearchIterator) -> SearchResult raise IteratorError

    取下一批。到末尾报 EndOfIterator,关掉了报 Closed。

    末尾的判定是「服务端回了零条命中」—— 搜索是距离序,取空即到底。

    SearchIteratorOption

    pub(all) struct SearchIteratorOption {
    base : SearchOption
    batch_size : Int
    limit : Int64
    }

    检索迭代器的入参。上游是 searchIteratorOption(内嵌 searchOption 再加批大小与上限),这里照着嵌一个 SearchOption。

    SearchIteratorOption::with_anns_field

    fn SearchIteratorOption::with_anns_field(self : SearchIteratorOption, anns_field : String) -> SearchIteratorOption

    SearchIteratorOption::with_batch_size

    fn SearchIteratorOption::with_batch_size(self : SearchIteratorOption, batch_size : Int) -> SearchIteratorOption

    SearchIteratorOption::with_consistency_level

    SearchIteratorOption::with_filter

    fn SearchIteratorOption::with_filter(self : SearchIteratorOption, expr : String) -> SearchIteratorOption

    SearchIteratorOption::with_ignore_growing

    fn SearchIteratorOption::with_ignore_growing(self : SearchIteratorOption, ignore_growing? : Bool) -> SearchIteratorOption

    SearchIteratorOption::with_limit

    fn SearchIteratorOption::with_limit(self : SearchIteratorOption, limit : Int64) -> SearchIteratorOption

    整体上限。负数按「无限」处理。

    SearchIteratorOption::with_metric_type

    SearchIteratorOption::with_output_fields

    fn SearchIteratorOption::with_output_fields(self : SearchIteratorOption, output_fields : Array[String]) -> SearchIteratorOption

    SearchIteratorOption::with_partitions

    fn SearchIteratorOption::with_partitions(self : SearchIteratorOption, partition_names : Array[String]) -> SearchIteratorOption

    SearchIteratorOption::with_search_param

    fn SearchIteratorOption::with_search_param(self : SearchIteratorOption, key : String, value : String) -> SearchIteratorOption

    补一条 search_params。迭代器自己的键(iterator 之类)允许被覆盖 —— 上游也是这个顺序:后写的赢。

    SearchOption

    pub(all) struct SearchOption {
    collection_name : String
    partition_names : Array[String]
    anns_field : String
    limit : Int
    vectors : Array[
    ColumnValue
    ]
    expr : String
    output_fields : Array[String]
    metric_type :
    MetricType
    ?
    search_params : Array[(String, String)]
    offset : Int
    ignore_growing : Bool
    round_decimal : Int
    consistency_level : ConsistencyLevel?
    }

    检索的入参。对应上游 searchOption + AnnRequest 里本移植覆盖的那部分。

    SearchOption::with_anns_field

    fn SearchOption::with_anns_field(self : SearchOption, anns_field : String) -> SearchOption

    SearchOption::with_consistency_level

    fn SearchOption::with_consistency_level(self : SearchOption, level : ConsistencyLevel) -> SearchOption

    SearchOption::with_filter

    fn SearchOption::with_filter(self : SearchOption, expr : String) -> SearchOption

    SearchOption::with_ignore_growing

    fn SearchOption::with_ignore_growing(self : SearchOption, ignore_growing? : Bool) -> SearchOption

    SearchOption::with_metric_type

    SearchOption::with_offset

    fn SearchOption::with_offset(self : SearchOption, offset : Int) -> SearchOption

    SearchOption::with_output_fields

    fn SearchOption::with_output_fields(self : SearchOption, output_fields : Array[String]) -> SearchOption

    SearchOption::with_partitions

    fn SearchOption::with_partitions(self : SearchOption, partition_names : Array[String]) -> SearchOption

    SearchOption::with_round_decimal

    fn SearchOption::with_round_decimal(self : SearchOption, round_decimal : Int) -> SearchOption

    SearchOption::with_search_param

    fn SearchOption::with_search_param(self : SearchOption, key : String, value : String) -> SearchOption

    SearchResult

    pub(all) struct SearchResult {
    hits : Array[SearchHit]
    } derive(
    Debug
    )

    一次 query 的全部命中,按分数降序(服务端保证的距离序)。

    WriteColumn

    pub(all) struct WriteColumn {
    name : String
    value :
    ColumnValue

    }

    写入用的一列。名字加数据,等价于上游 column.Column 里写入侧用到的那部分。

    复用 @column.ColumnValue 而不是另造一套枚举,是为了让回读的 Column 能被原样改一改名字写回去(改列名重插入这种用法)。

    WriteColumn::data_type

    这一列的 @schema.DataType。

    WriteColumn::len

    fn WriteColumn::len(self : WriteColumn) -> Int

    这一列的行数。

    WriteColumn::to_field_data

    一列 → 一条 FieldData。

    动态字段(JSON)要带上 is_dynamic,否则服务端会把它当成 schema 里 不存在的列拒绝。这里靠名字判断:@column 侧回读动态字段时也是用 FieldData.is_dynamic 标记的,写侧没有别的信号可用。

    nullable 为真时写一条全 1 的 valid_data:调用方给的是实体数组, 目前没有「某行是 null」的表示,写成全 1 与「全部有值」等价, 但显式声明可空位图后服务端不会把空列当坏数据。

    WriteOption

    pub(all) struct WriteOption {
    collection_name : String
    partition_name : String
    columns : Array[WriteColumn]
    partial_update : Bool
    }

    写一批列的共同入参:集合名 + 可选分区。

    upsert 多一个 partial_update:上游 WithPartialUpdate 打开后, 服务端只覆盖请求里出现的字段,其余保持原值。

    WriteOption::with_partial_update

    fn WriteOption::with_partial_update(self : WriteOption, partial_update? : Bool) -> WriteOption

    只在 upsert 上有意义;insert 上设了不会报错,只是被忽略。

    WriteOption::with_partition

    fn WriteOption::with_partition(self : WriteOption, partition_name : String) -> WriteOption

    column_error_message

    fn column_error_message(err :
    ColumnError
    ) -> String

    @column.ColumnError 的文本。它在 @column 里只 derive 了 Debug, 包外拿不到内部字符串,所以这里按构造器解出来。

    column_value_type_name

    fn column_value_type_name(value :
    ColumnValue
    ) -> String

    @column.ColumnValue 的类型名。@column 没有把它暴露出来, 而包外的报错文本需要一个能定位的说法。

    create_collection_path

    let create_collection_path : String

    create_index_path

    let create_index_path : String

    create_partition_path

    let create_partition_path : String

    data_type_from_proto

    @schema.DataType → @entity.DataType?。

    认不出的值(协议比本地新)返回 None,由调用方决定是跳过这个字段还是 报错 —— 静默当成某个已知类型会把未知字段读歪。

    data_type_to_proto

    @entity.DataType → @schema.DataType。

    生成的枚举把 JSON / UUID 拼成全大写,与上游 proto 一致; @entity 侧用惯常的 Json / Uuid。两边新增类型时这里都要动。

    default_consistency_level

    let default_consistency_level : ConsistencyLevel

    上游 entity.DefaultConsistencyLevel:Bounded。

    default_flush_check_interval_millis

    let default_flush_check_interval_millis : Int

    上游 NewFlushOption 的默认轮询间隔。

    default_load_check_interval_millis

    let default_load_check_interval_millis : Int

    上游 NewLoadCollectionOption 的默认轮询间隔。

    delete_by_int64_ids

    fn delete_by_int64_ids(collection_name : String, field_name : String, ids : Array[Int64]) -> DeleteOption

    按主键删。与上游 WithInt64IDs 一致,拼成 pk in [...]。

    delete_by_string_ids

    fn delete_by_string_ids(collection_name : String, field_name : String, ids : Array[String]) -> DeleteOption

    按字符串主键删。与上游 WithStringIDs 一致,每个值加双引号。

    delete_path

    let delete_path : String

    describe_collection_path

    let describe_collection_path : String

    describe_index_path

    let describe_index_path : String

    drop_collection_path

    let drop_collection_path : String

    drop_index_path

    let drop_index_path : String

    drop_partition_path

    let drop_partition_path : String

    entity_schema_message

    fn entity_schema_message(err :
    SchemaError
    ) -> String

    @entity.SchemaError 的文本。它在 @entity 里只 derive 了 Eq, Debug, 包外拿不到内部字符串,所以这里按 Debug 展开取出来。 校验错误是给人看的,包一层 Debug(...) 也比只写「schema 不合法」强。

    field_from_proto

    @schema.FieldSchema → @entity.Field。

    生成物的 element_type 是必填枚举、缺省 None,所以这里用 data_type_from_proto(...) 之后再判断是否真的设了元素类型。

    field_to_proto

    一个 @entity.Field → @schema.FieldSchema。

    dim / max_length 不是 FieldSchema 的字段:服务端从 type_params 里读,所以这里也把它俩合并进 type_params,顺序是 dim 在前。

    flush_path

    let flush_path : String

    get_flush_state_path

    let get_flush_state_path : String

    get_load_state_path

    let get_load_state_path : String

    get_loading_progress_path

    let get_loading_progress_path : String

    has_collection_path

    let has_collection_path : String

    has_partition_path

    let has_partition_path : String

    insert_path

    let insert_path : String

    iterator_batch_size_key

    let iterator_batch_size_key : String

    iterator_collection_id_key

    let iterator_collection_id_key : String

    iterator_key

    let iterator_key : String

    search_params 里与迭代器相关的键。字面量与上游逐条对齐。

    iterator 与 search_iter_v2 告诉服务端「这是翻页请求」; search_iter_id / search_iter_last_bound 是上一批回给我们的续页凭据, 原样带回去就行;collection_id 是 V2 协议要求的集合 ID。

    iterator_search_id_key

    let iterator_search_id_key : String

    iterator_search_last_bound_key

    let iterator_search_last_bound_key : String

    iterator_search_v2_key

    let iterator_search_v2_key : String

    iterator_unlimited

    let iterator_unlimited : Int64

    迭代器上限的「无限」写法。上游 Unlimited = -1。

    load_collection_path

    let load_collection_path : String

    load_partitions_path

    let load_partitions_path : String

    new_create_collection_option

    fn new_create_collection_option(name : String, schema :
    CollectionSchema
    ) -> CreateCollectionOption

    上游 NewCreateCollectionOption:拿一张自定义 schema 建表。 默认分片数 1、一致性 Bounded。

    new_create_index_option

    fn new_create_index_option(collection_name : String, field_name : String, index :
    Index
    ) -> CreateIndexOption

    new_create_partition_option

    fn new_create_partition_option(collection_name : String, partition_name : String) -> CreatePartitionOption

    new_delete_option

    fn new_delete_option(collection_name : String, expr : String) -> DeleteOption

    按表达式删,比如 age > 30。

    new_describe_collection_option

    fn new_describe_collection_option(name : String) -> DescribeCollectionOption

    new_describe_index_option

    fn new_describe_index_option(collection_name : String) -> DescribeIndexOption

    new_drop_collection_option

    fn new_drop_collection_option(name : String) -> DropCollectionOption

    new_drop_index_option

    fn new_drop_index_option(collection_name : String, index_name : String) -> DropIndexOption

    new_drop_partition_option

    fn new_drop_partition_option(collection_name : String, partition_name : String) -> DropPartitionOption

    new_flush_option

    fn new_flush_option(collection_name : String) -> FlushOption

    new_get_flush_state_option

    fn new_get_flush_state_option(collection_name : String, segment_ids : Array[Int64], flush_timestamp : UInt64) -> GetFlushStateOption

    new_get_load_state_option

    fn new_get_load_state_option(collection_name : String, partition_names? : Array[String]) -> GetLoadStateOption

    new_has_partition_option

    fn new_has_partition_option(collection_name : String, partition_name : String) -> HasPartitionOption

    new_list_collections_option

    fn new_list_collections_option() -> ListCollectionsOption

    new_list_partitions_option

    fn new_list_partitions_option(collection_name : String) -> ListPartitionsOption

    new_load_collection_option

    fn new_load_collection_option(collection_name : String) -> LoadCollectionOption

    new_load_partitions_option

    fn new_load_partitions_option(collection_name : String, partition_names : Array[String]) -> LoadPartitionsOption

    new_query_iterator_option

    fn new_query_iterator_option(collection_name : String) -> QueryIteratorOption

    上游 NewQueryIteratorOption:批大小 1000、上限无限、一致性用默认档。

    new_query_option

    fn new_query_option(collection_name : String) -> QueryOption

    上游 NewQueryOption:默认一致性 Bounded,其余空。

    query_params 不预置任何键——尤其不预置 limit。默认 limit 是适配层 的概念,上游由 CheckAndSetLimit 在发请求前补齐,本移植的编排里没有 这一层,所以「没给 limit」就是真的不发;要限制行数就显式 with_limit。 别在这里悄悄塞一个 16384 假装对齐上游,那只是把「没实现适配层」这件事 藏起来,顺手给出一个错的因果。

    new_release_collection_option

    fn new_release_collection_option(collection_name : String) -> ReleaseCollectionOption

    new_release_partitions_option

    fn new_release_partitions_option(collection_name : String, partition_names : Array[String]) -> ReleasePartitionsOption

    new_search_iterator_option

    fn new_search_iterator_option(collection_name : String, limit : Int, vectors : Array[
    ColumnValue
    ]) -> SearchIteratorOption

    上游 NewSearchIteratorOption:批大小 1000、上限无限,并把 iterator=true / search_iter_v2=true 一并塞进 search_params。

    vectors 的写法与 new_search_option 同一套:每个元素是一次查询, 所以搜索迭代器的入参必须恰好一个元素(nq = 1)。

    上游给的初始 topk 是 1000,但那在每次 next 里都会被批大小覆盖, 这里直接不放那个数 —— 少一个会被改写的东西。

    new_search_option

    fn new_search_option(collection_name : String, limit : Int, vectors : Array[
    ColumnValue
    ]) -> SearchOption

    记一个查询向量。每个元素是「一行」,也就是说: FloatVector(dim, [v1, v2]) 表示 nq = 2、每行 dim 维。

    new_write_option

    fn new_write_option(collection_name : String, columns : Array[WriteColumn]) -> WriteOption

    上游 NewColumnBasedInsertOption:给集合名和列,不指定分区 (空分区名落到默认分区 _default)。

    query_param_limit

    let query_param_limit : String

    query_params 里服务端认的键。字面量与上游逐条对齐。

    query_param_offset

    let query_param_offset : String

    query_param_order_by_fields

    let query_param_order_by_fields : String

    query_path

    let query_path : String

    release_collection_path

    let release_collection_path : String

    release_partitions_path

    let release_partitions_path : String

    schema_to_proto

    @entity.CollectionSchema → @schema.CollectionSchema。

    name 单独传:@entity.CollectionSchema 里没有集合名这一项, 上游也是把名字留在 CreateCollectionOption 上再补进 proto。

    search_param_anns_field

    let search_param_anns_field : String

    search_params 里服务端认的键。字面量与上游逐条对齐。

    search_param_ignore_growing

    let search_param_ignore_growing : String

    search_param_metric_type

    let search_param_metric_type : String

    search_param_offset

    let search_param_offset : String

    search_param_params

    let search_param_params : String

    search_param_round_decimal

    let search_param_round_decimal : String

    search_param_topk

    let search_param_topk : String

    search_path

    let search_path : String

    serialize_collection_schema

    fn serialize_collection_schema(name : String, schema :
    CollectionSchema
    ) -> Bytes raise ClientError

    编码 CreateCollectionRequest.schema 那个 bytes 字段。

    service_name

    let service_name : String

    Milvus 的 gRPC 服务全名。

    show_collections_path

    let show_collections_path : String

    show_partitions_path

    let show_partitions_path : String

    simple_create_collection_option

    fn simple_create_collection_option(name : String, dim : Int) -> CreateCollectionOption

    上游 SimpleCreateCollectionOptions:只给名字和维度,其余按默认。

    upsert_path

    let upsert_path : String