Repository navigation
Milvus: move the provider to Milvus.Client.V2 - #93
Conversation
Port the Microsoft.Extensions.VectorData Milvus provider from the legacy Milvus.Client to Milvus.Client.V2 3.0.0 (MilvusClientV2 and its request/response API). - Collections take a MilvusClientV2; the host-based registrations build a ConnectConfig from the host, port, database and API key or username/password. - Collection creation sends the schema, the vector and BM25 indexes in one CreateCollection call, then loads the collection and waits for it with LoadTimeout. - Each index is named after its field: Milvus.Client.V2 3.0.0 gives every unnamed index the same default name, and Milvus rejects the second one. - Upserts send rows (UpsertReq.RowsData); queries and searches read the returned columns back into rows. - Hybrid search uses AnnSearchReq with text input for BM25, ranked with RrfReranker(60). - gRPC failures now reach the error handler as MilvusException, with the gRPC status kept. Milvus.Client.V2 cannot take a caller-owned GrpcChannel: a client always owns its channel, and tests route calls through ConnectConfig.ChannelOptions instead.
|
@dotnet-policy-service agree |
|
A note for the maintainers, apart from the review. This PR changes more than a dependency: the public API moves from With
My view: this should not be merged until a |
I agree 100%, big thanks for flagging those issues @Laurianti ! |
|
Thanks! For the NativeAOT one I opened milvus-io/milvus-sdk-csharp#204. The empty-search fix (milvus-io/milvus-sdk-csharp#198) is already merged there and waits for a release. |
There was a problem hiding this comment.
I ran this PR (b2bc2a3) against Milvus standalone v2.6.25 with Milvus.Client.V2 3.0.1, which includes the fixes for the empty search (milvus-io/milvus-sdk-csharp#198) and for NativeAOT (milvus-io/milvus-sdk-csharp#204). With the suggestions of this review applied: Release build with no warnings, unit tests 129/129, conformance tests 256/256. Same results against Milvus standalone v3.0.6. NativeAOT and .NET Framework over TLS work too.
This PR changes the C# code in MEVD/src/Milvus, so the <Version> in Milvus.csproj needs a bump (.github/copilot-instructions.md). Since the public API changes, I would suggest 1.1.0-preview.
- Use Milvus.Client.V2 3.0.1, which fixes searches with no results (milvus-io/milvus-sdk-csharp#198) and search in trimmed and NativeAOT apps (milvus-io/milvus-sdk-csharp#204). - Throw when Milvus returns fewer rows than search hits, instead of returning records with only their key, with tests. - README: drop the IL2104/IL3053 note, which 3.0.1 no longer produces, and record the .NET Framework check with Milvus.Client.V2. - Bump the provider version to 1.1.0-preview: its public API changes.
|
Thanks @Laurianti for the thorough review and for getting milvus-io/milvus-sdk-csharp#204 fixed and released, and thanks @adamsitnik. I agree this shouldn't have gone in on 3.0.0. 279b6aa applies all the suggestions:
Locally: Release build with no warnings, unit tests 129/129. On the process point: understood. I should have opened an issue first for a change of this size. I'm happy to open one now if you'd like the discussion there. There's one workaround left in the provider: each index is named after its field. |
There was a problem hiding this comment.
🟡 Changes recommended
A positive LoadTimeout below one millisecond truncates to zero, which Milvus interprets as waiting forever, so EnsureCollectionExistsAsync can poll indefinitely unless canceled.
1 open issue
What changed in this PR
Migrates the Milvus vector-store provider to Milvus.Client.V2, adapting its SDK integration while retaining the existing vector-data operations and host-based registration signatures.
Changes:
- Adopts
MilvusClientV2and its request/response APIs for collection management, writes, queries, and hybrid search. - Updates schema/index creation and response mapping, with tests adapted for V2 client ownership and error handling.
- Updates migration guidance, bumps the provider to
1.1.0-preview, and pins SDK version3.0.1.
| File | Description |
|---|---|
| MEVD/test/Milvus.UnitTests/TestClients.cs | Adds shared V2 test-client factories. |
| MEVD/test/Milvus.UnitTests/MilvusSearchResponseTests.cs | Tests search-hit mapping and row-count validation. |
| MEVD/test/Milvus.UnitTests/MilvusMappingTests.cs | Updates mapping assertions to V2 types. |
| MEVD/test/Milvus.UnitTests/MilvusHybridSearchTests.cs | Uses V2 clients in hybrid-search tests. |
| MEVD/test/Milvus.UnitTests/MilvusFullTextTests.cs | Updates full-text schema tests for V2. |
| MEVD/test/Milvus.UnitTests/MilvusEnsureCollectionTests.cs | Adapts fake responses to V2 load-state polling. |
| MEVD/test/Milvus.UnitTests/MilvusDatabaseTests.cs | Uses V2 clients for database metadata tests. |
| MEVD/test/Milvus.UnitTests/MilvusCollectionTests.cs | Updates client registration and service assertions. |
| MEVD/test/Milvus.UnitTests/MilvusClientLifetimeTests.cs | Tests V2 ownership, disposal, and wrapped errors. |
| MEVD/test/Milvus.UnitTests/MilvusArrayTests.cs | Updates array-schema assertions to V2 types. |
| MEVD/test/Milvus.ConformanceTests/Support/MilvusTestStore.cs | Creates V2 clients for integration fixtures. |
| MEVD/test/Milvus.ConformanceTests/MilvusRoundTripTests.cs | Switches round-trip tests to V2 clients. |
| MEVD/test/Milvus.ConformanceTests/MilvusEnsureCollectionTests.cs | Uses V2 collection and index requests. |
| MEVD/test/Milvus.ConformanceTests/MilvusEmbeddingGenerationTests.cs | Updates SDK namespace imports. |
| MEVD/test/Milvus.ConformanceTests/MilvusDependencyInjectionTests.cs | Registers V2 clients in integration tests. |
| MEVD/test/Milvus.ConformanceTests/MilvusDatabaseTests.cs | Uses V2 database-management requests. |
| MEVD/src/Milvus/README.md | Updates SDK setup and platform guidance. |
| MEVD/src/Milvus/MilvusVectorStore.cs | Exposes V2 clients and lists collections through V2. |
| MEVD/src/Milvus/MilvusServiceCollectionExtensions.cs | Builds V2 connection configuration for registrations. |
| MEVD/src/Milvus/MilvusFieldMapping.cs | Converts V2 response columns into rows. |
| MEVD/src/Milvus/MilvusErrorHandler.cs | Uses the V2 exception type and updates explanatory comments. |
| MEVD/src/Milvus/MilvusDynamicCollection.cs | Accepts V2 clients for dynamic collections. |
| MEVD/src/Milvus/MilvusCollectionCreateMapping.cs | Maps V2 schemas and explicitly named indexes. |
| MEVD/src/Milvus/MilvusCollection.cs | Migrates collection operations and search-result handling. |
| MEVD/src/Milvus/Milvus.csproj | Changes SDK dependency and bumps provider version. |
| MEVD/src/Milvus/ClientWrapper.cs | Retains shared ownership using the V2 client type. |
| Directory.Packages.props | Pins Milvus.Client.V2 to 3.0.1. |
Review effort: Balanced
Milvus V2 defines TimeoutMs = 0 as waiting forever, so a valid finite timeout can leave EnsureCollectionExistsAsync polling indefinitely unless canceled. Adding Math.Ceiling resolve the issue
Milvus.Client.V2 takes the load timeout in whole milliseconds, where 0 means no timeout, and adds it to DateTime.UtcNow: LoadTimeout = TimeSpan.MaxValue threw ArgumentOutOfRangeException even when the collection loaded at once. Load without the SDK's wait and poll GetLoadState here, timed with a Stopwatch as Milvus.Client did, so any positive LoadTimeout works: one below a millisecond times out, TimeSpan.MaxValue waits until the load ends. Tests cover both.
@Laurianti please merge the PR once you believe it's ready |
|
Thanks! We're waiting for @Overvolted's LGTM, then I'll merge it. |
|
LGTM 👍🏼 |

Summary
This moves the Milvus provider (
CommunityToolkit.VectorData.Milvus, added in #77) from the legacyMilvus.ClienttoMilvus.Client.V23.0.0. The provider's behaviour and its MEVD surface stay the same. The SDK client type it takes changes fromMilvusClienttoMilvusClientV2.Related:
Why Milvus.Client.V2
V1 is in maintenance mode. The milvus-sdk-csharp README marks
Milvus.Clientas legacy and recommendsMilvus.Client.V2. Since the V2 release, new features and fixes land in V2. For example, the fix for decoding empty search results (fix: handle empty result output field placeholders milvus-io/milvus-sdk-csharp#198) is V2-only. Staying on V1 would leave the provider on a client that no longer grows.A client built for long-lived use. #139 lists the V1 problems V2 was written to fix:
RetryConfig); V1 makes a single attempt.MilvusErrorCode, andMilvusExceptioncarries the gRPC status).One configuration object. V1 has nine constructor overloads. V2 takes a single
ConnectConfigwith URI, credentials, database, timeouts, keep-alive, retry, logging and gRPC channel options. Users who bring their own client can now set retry and timeouts there.Request/response API that matches the other official SDKs. V2 mirrors the Java/C++/Rust SDKs (
CreateCollectionReq,SearchReq,HybridSearchReq, …). It also drops V1's stateful per-collection handles, which the provider no longer needs to hold.Room to grow. Several things this provider can't do today depend on V2:
OrderByforGetAsync(filter, …), from feat: fill MilvusClientV2 parity gaps (externalField, typed DQL params, resumable + element-filter iterators) milvus-io/milvus-sdk-csharp#190. It is merged on the SDK's main branch but not in a NuGet release yet.Timestamptzdate/time fields.Each would be its own follow-up PR once the provider is on V2.
Changes
MilvusVectorStore,MilvusCollection<TKey, TRecord>andMilvusDynamicCollectiontake aMilvusClientV2.GetService(typeof(MilvusClientV2))returns it.ConnectConfigfrom the host, port,https, database and the API key or username/password. Their signatures are unchanged.EnsureCollectionExistsAsynccreates the collection with its schema, BM25 functions and indexes in oneCreateCollectionAsynccall. It then loads the collection and waits up toLoadTimeout.Milvus.Client.V23.0.0 gives every unnamed index the same default name,_default_idx, and Milvus then rejects the second index of a collection: "at most one distinct index is allowed per field". Without this, collections with several vectors, or a vector plus full-text search, can't be created. I'll also propose the same default upstream in milvus-sdk-csharp.UpsertReq.RowsData, and the SDK maps nulls using the collection schema. Queries and searches read the returned columns back into rows.AnnSearchReqand one BM25AnnSearchReqwith text input, ranked withRrfReranker(60).Breaking changes
The package is still
1.0.0-preview, but callers who pass their own SDK client need to update:new MilvusClient(...)becomesnew MilvusClientV2(new ConnectConfig { Uri = ..., ApiKey = ..., Database = ... }). Host-based registrations need no change.GrpcChannel: a client always owns its channel. A custom handler (for exampleWinHttpHandleron .NET Framework) goes throughConnectConfig.ChannelOptionsinstead.VectorStoreExceptionfor a gRPC failure is now aMilvusExceptionthat carries the gRPC status, not anRpcException.Testing
Milvus.UnitTests: 127 passed. The fake gRPC handler now also answers V2'sGetLoadStatepoll.Milvus.ConformanceTestson .NET 10 against a Milvus 2.6 server: 256 passed. That run used the same provider code with newer test packages (Testcontainers 4.16, Microsoft.NET.Test.Sdk 18.12).MEVD.slnfsolution builds with 0 warnings and 0 errors.