mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 10:15:43 +00:00
issue: #49163 ## Summary Brings the Go SDK (`client/v2`) struct array feature to parity with pymilvus and fixes several client-side correctness issues found in the master surface. **New capabilities** - Vector-array column types for struct sub-fields: `ColumnFloatVectorArray`, `ColumnFloat16VectorArray`, `ColumnBFloat16VectorArray`, `ColumnBinaryVectorArray`, `ColumnInt8VectorArray` (new `client/column/vector_array.go`). Response decoding goes through a shared generic helper with nil-row + length-multiple-of-width validation. - EmbeddingList search types: `entity.FloatVectorArray` + new `Float16VectorArray` / `BFloat16VectorArray` / `BinaryVectorArray` / `Int8VectorArray`, each dispatched to the correct `PlaceholderType_EmbList*` in `vector2Placeholder`. Unblocks MAX_SIM / embedding-list search against struct-array vector sub-fields from Go. - Row-based insert helper `(*columnBasedDataOption).WithStructArrayColumn(name, *entity.StructSchema, []map[string]any)` that infers sub-column types from the schema. **Correctness fixes** - `WithStructArrayColumn` now records construction errors on a `deferredErr` field and surfaces them through `InsertRequest` / `UpsertRequest` instead of panicking in the builder chain. - `StructSchema.Validate(parent)` + `Schema.Validate()` mirror pymilvus `StructFieldSchema._check_fields` (reject nested `ARRAY` / `ARRAY_OF_VECTOR` / `STRUCT` sub-fields, `primary_key`, `partition_key`, `clustering_key`, `nullable`, `auto_id`, `dynamic`, `default_value`, nested struct schema). `Client.CreateCollection` calls `Validate()` via interface assertion so bad schemas are rejected before the RPC. - `columnStructArray.Len()` requires equal lengths across sub-fields and panics loudly on drift, preventing silently malformed insert payloads. - `columnStructArray.AppendValue` is now atomic: on sub-field error, earlier sub-columns are rolled back to their pre-call length via `Slice()` so the struct stays in lock-step. - `parseVectorArrayData` validates nil `VectorField` rows, checks `len(payload) % width == 0` and rejects `dim % 8 != 0` for binary vectors. The 5 per-type branches are deduplicated via a generic `splitVectorArrayRows` helper. ## Test plan - [x] `go test -tags dynamic,test -gcflags="all=-N -l" -count=1 ./...` in `client/` (all green): new unit tests in `entity/vectors_test.go`, `entity/field_test.go`, `column/struct_test.go`, `milvusclient/write_option_test.go` cover each behavior above. - [x] End-to-end smoke test against a live Milvus server (`chaos-testing/struct-array-test`, image `feat-rest-v2-struct-array-20260420-0c5a964`) covering: - [x] `Schema.Validate()` rejects a nested-struct sub-field - [x] `Client.CreateCollection` pre-flight rejects the same schema before the RPC - [x] Valid schema create / `DescribeCollection` round-trip preserves `max_capacity` on sub-fields and correctly unwraps `ArrayOfVector` back to `FloatVector` with `dim` preserved - [x] `Insert` via `WithStructArrayColumn` with mixed scalar + vector sub-fields - [x] Builder no longer panics; missing-key deferred error surfaces on `InsertRequest` - [x] `Flush` / `CreateIndex(vec)` / `CreateIndex("clips[clip_emb]")` (MAX_SIM_COSINE) / `LoadCollection` - [x] `Query` with `filter=id<3` returns expected rows - [x] `Search` with `entity.FloatVectorArray` (EmbList Float placeholder) returns hits on `anns_field="clips[clip_emb]"` - [x] Integration test cases under `tests/go_client/testcases/` (struct_array / struct_array_element_*) — added as new test harness; requires a struct-array-capable server to exercise. --------- Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Go MilvusClient
Go MilvusClient for Milvus. To contribute code to this project, please read our contribution guidelines first.
Getting started
Prerequisites
Go 1.24.12 or higher
Install Milvus Go SDK
-
Use
go getto install the latest version of the Milvus Go SDK and dependencies:go get -u github.com/milvus-io/milvus/client/v2 -
Include the Go MilvusClient in your application:
import "github.com/milvus-io/milvus/client/v2/milvusclient" //...other snippet ... ctx, cancel := context.WithCancel(context.Background()) defer cancel() milvusAddr := "YOUR_MILVUS_ENDPOINT" cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{ Address: milvusAddr, }) if err != nil { // handle error } // Do your work with milvus client
API Documentation
Refer to https://milvus.io/api-reference/go/v2.5.x/About.md for the Go SDK API documentation.
Code format
The Go source code is formatted using gci & gofumpt. Please run make lint-fix before sumbit a PR.