Skip to content

Milvus: move the provider to Milvus.Client.V2 - #93

Merged
Laurianti merged 4 commits into
CommunityToolkit:mainfrom
N-E-W-T-O-N:milvus-v2-port
Nov 20, 2026
Merged

Laurianti merged 4 commits into
CommunityToolkit:mainfrom
N-E-W-T-O-N:milvus-v2-port

Conversation

@N-E-W-T-O-N

@N-E-W-T-O-N N-E-W-T-O-N commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This moves the Milvus provider (CommunityToolkit.VectorData.Milvus, added in #77) from the legacy Milvus.Client to Milvus.Client.V2 3.0.0. The provider's behaviour and its MEVD surface stay the same. The SDK client type it takes changes from MilvusClient to MilvusClientV2.

Related:

Why Milvus.Client.V2

  • V1 is in maintenance mode. The milvus-sdk-csharp README marks Milvus.Client as legacy and recommends Milvus.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:

    • V2 has built-in retry for transient errors such as rate limiting (RetryConfig); V1 makes a single attempt.
    • V2 has a thread-safe schema cache, where V1 keeps an unsynchronized mutation-timestamp dictionary.
    • V2 reports richer errors (MilvusErrorCode, and MilvusException carries the gRPC status).
    • V2 returns typed responses for every operation.
  • One configuration object. V1 has nine constructor overloads. V2 takes a single ConnectConfig with 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:

    Each would be its own follow-up PR once the provider is on V2.

Changes

  • MilvusVectorStore, MilvusCollection<TKey, TRecord> and MilvusDynamicCollection take a MilvusClientV2. GetService(typeof(MilvusClientV2)) returns it.
  • The host-based DI registrations build a ConnectConfig from the host, port, https, database and the API key or username/password. Their signatures are unchanged.
  • EnsureCollectionExistsAsync creates the collection with its schema, BM25 functions and indexes in one CreateCollectionAsync call. It then loads the collection and waits up to LoadTimeout.
  • Each index is named after its field. Milvus.Client.V2 3.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.
  • Upserts send rows through UpsertReq.RowsData, and the SDK maps nulls using the collection schema. Queries and searches read the returned columns back into rows.
  • Hybrid search sends one vector AnnSearchReq and one BM25 AnnSearchReq with text input, ranked with RrfReranker(60).
  • The provider README is updated for V2.

Breaking changes

The package is still 1.0.0-preview, but callers who pass their own SDK client need to update:

  • new MilvusClient(...) becomes new MilvusClientV2(new ConnectConfig { Uri = ..., ApiKey = ..., Database = ... }). Host-based registrations need no change.
  • V2 has no constructor that takes a caller-owned GrpcChannel: a client always owns its channel. A custom handler (for example WinHttpHandler on .NET Framework) goes through ConnectConfig.ChannelOptions instead.
  • The inner exception of a VectorStoreException for a gRPC failure is now a MilvusException that carries the gRPC status, not an RpcException.

Testing

  • Milvus.UnitTests: 127 passed. The fake gRPC handler now also answers V2's GetLoadState poll.
  • Milvus.ConformanceTests on .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).
  • The MEVD.slnf solution builds with 0 warnings and 0 errors.
  • Not tested: .NET Framework over TLS. The README now says it was verified with V1 only.

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.
@N-E-W-T-O-N

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@Laurianti Laurianti self-assigned this Nov 15, 2026

@Laurianti Laurianti left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced by the review below, after the Milvus.Client.V2 3.0.1 release.

@Laurianti

Copy link
Copy Markdown
Member

A note for the maintainers, apart from the review.

This PR changes more than a dependency: the public API moves from MilvusClient to MilvusClientV2, and the provider now behaves differently from main. By CONTRIBUTING.md, a change of this size starts as an issue that is discussed and approved before the PR. There is no issue in this repo for it, so the discussion is happening here.

With Milvus.Client.V2 3.0.0, two things that work on main (74935f4) stop working:

  • A search with no results throws. The fix is fix: handle empty result output field placeholders milvus-io/milvus-sdk-csharp#198, merged but not released. The review suggestions restore the workaround in the provider.
  • Search fails in trimmed and NativeAOT apps. The SDK serializes the search parameters with reflection-based JSON. The provider cannot work around this; only the app can, with JsonSerializerIsReflectionEnabledByDefault. Details are in the README thread of the review.

My view: this should not be merged until a Milvus.Client.V2 release fixes both. Until then main on Milvus.Client 2.6.0 has neither problem.

@adamsitnik

Copy link
Copy Markdown
Contributor

My view: this should not be merged until a Milvus.Client.V2 release fixes both. Until then main on Milvus.Client 2.6.0 has neither problem.

I agree 100%, big thanks for flagging those issues @Laurianti !

@Laurianti

Copy link
Copy Markdown
Member

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.

@Laurianti Laurianti left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Directory.Packages.props Resolved
Comment thread MEVD/src/Milvus/MilvusCollection.cs Resolved
Comment thread MEVD/src/Milvus/README.md Resolved
- 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.
@N-E-W-T-O-N

Copy link
Copy Markdown
Contributor Author

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. Milvus.Client.V2 3.0.1 still gives every unnamed index the same _default_idx name, so Milvus rejects the second index of a collection. That happens with several vectors, or with a vector plus full-text search. I have the SDK fix (default the name to the field, as the Java SDK does) and will propose it in milvus-sdk-csharp. The workaround can go once that's released.

@Laurianti Laurianti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I re-ran the tests on 279b6aa: build with no warnings, unit tests 129/129, conformance tests 256/256. The code matches what I tested for the previous review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 MilvusClientV2 and 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 version 3.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

Comment thread MEVD/src/Milvus/MilvusCollection.cs Resolved
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
Comment thread MEVD/src/Milvus/MilvusCollection.cs Resolved
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 Laurianti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I re-ran the tests on 7c77904: build with no warnings, unit tests 131/131, conformance tests 256/256.

@adamsitnik

Copy link
Copy Markdown
Contributor

Thanks! I re-ran the tests on 7c77904: build with no warnings, unit tests 131/131, conformance tests 256/256.

@Laurianti please merge the PR once you believe it's ready

@Laurianti

Copy link
Copy Markdown
Member

Thanks! We're waiting for @Overvolted's LGTM, then I'll merge it.

@Overvolted

Copy link
Copy Markdown
Contributor

LGTM 👍🏼

@Laurianti
Laurianti merged commit 268e370 into CommunityToolkit:main Nov 20, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants