diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 47211f9..41b43b4 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -14,7 +14,7 @@ jobs: matrix: # TODO: Test against latest previews too. This currently doesn't work because preview releases don't publish # a milvus-standalone-docker-compose.yml - milvus_version: [v2.2.11] + milvus_version: [v2.3.0] steps: - name: Checkout diff --git a/Milvus.Client.Tests/IndexTests.cs b/Milvus.Client.Tests/IndexTests.cs index 66f16cb..9f9520b 100644 --- a/Milvus.Client.Tests/IndexTests.cs +++ b/Milvus.Client.Tests/IndexTests.cs @@ -17,7 +17,7 @@ public async Task Create_vector_index_with_name() { await Collection.CreateIndexAsync( "float_vector", IndexType.Flat, SimilarityMetricType.L2, indexName: "float_vector_idx"); - await Collection.WaitForIndexBuildAsync("float_vector"); + await Collection.WaitForIndexBuildAsync("float_vector", "float_vector_idx"); } [Fact] @@ -46,10 +46,6 @@ public async Task Create_scalar_index() [InlineData(IndexType.IvfSq8, """{ "nlist": "8" }""")] [InlineData(IndexType.IvfPq, """{ "nlist": "8", "m": "4" }""")] [InlineData(IndexType.Hnsw, """{ "efConstruction": "8", "M": "4" }""")] - [InlineData(IndexType.Annoy, """{ "n_trees": "10" }""")] - [InlineData(IndexType.RhnswFlat, """{ "efConstruction": "8", "M": "4" }""")] - [InlineData(IndexType.RhnswPq, """{ "efConstruction": "8", "M": "4", "PQM": "4" }""")] - [InlineData(IndexType.RhnswSq, """{ "efConstruction": "8", "M": "4" }""")] [InlineData(IndexType.AutoIndex, """{ }""")] public async Task Index_types_float(IndexType indexType, string extraParamsString) { @@ -91,10 +87,7 @@ public async Task Similarity_metric_types(SimilarityMetricType similarityMetricT [Theory] [InlineData(SimilarityMetricType.Jaccard)] - [InlineData(SimilarityMetricType.Tanimoto)] [InlineData(SimilarityMetricType.Hamming)] - [InlineData(SimilarityMetricType.Superstructure)] - [InlineData(SimilarityMetricType.Substructure)] public async Task Similarity_metric_types_binary(SimilarityMetricType similarityMetricType) { await Collection.DropAsync(); @@ -111,6 +104,7 @@ await Client.CreateCollectionAsync( await Collection.WaitForIndexBuildAsync("binary_vector"); } +#pragma warning disable CS0618 // Type or member is obsolete [Fact] public async Task GetState() { @@ -123,17 +117,19 @@ public async Task GetState() } [Fact] - public async Task GetBuildProgress() + public async Task GetBuildProgress_with_name() { await Assert.ThrowsAsync(() => - Collection.GetIndexBuildProgressAsync("float_vector")); + Collection.GetIndexBuildProgressAsync("float_vector", indexName: "float_vector_idx")); - await Collection.CreateIndexAsync("float_vector", IndexType.Flat, SimilarityMetricType.L2); - await Collection.WaitForIndexBuildAsync("float_vector"); + await Collection.CreateIndexAsync( + "float_vector", IndexType.Flat, SimilarityMetricType.L2, indexName: "float_vector_idx"); + await Collection.WaitForIndexBuildAsync("float_vector", "float_vector_idx"); - var progress = await Collection.GetIndexBuildProgressAsync("float_vector"); + var progress = await Collection.GetIndexBuildProgressAsync("float_vector", "float_vector_idx"); Assert.Equal(progress.TotalRows, progress.IndexedRows); } +#pragma warning restore CS0618 // Type or member is obsolete [Fact] public async Task Describe() @@ -171,7 +167,9 @@ await Collection.CreateIndexAsync( await Collection.DropIndexAsync("float_vector", "float_vector_idx"); - Assert.Equal(IndexState.None, await Collection.GetIndexStateAsync("float_vector")); + MilvusException exception = await Assert.ThrowsAsync( + () => Collection.DescribeIndexAsync("float_vector")); + Assert.Equal(MilvusErrorCode.IndexNotExist, exception.ErrorCode); } public async Task InitializeAsync() diff --git a/Milvus.Client/Milvus.Client.csproj b/Milvus.Client/Milvus.Client.csproj index 1c6c3f1..8b52e53 100644 --- a/Milvus.Client/Milvus.Client.csproj +++ b/Milvus.Client/Milvus.Client.csproj @@ -31,6 +31,7 @@ + diff --git a/Milvus.Client/MilvusCollection.Index.cs b/Milvus.Client/MilvusCollection.Index.cs index 54818e5..69bdf10 100644 --- a/Milvus.Client/MilvusCollection.Index.cs +++ b/Milvus.Client/MilvusCollection.Index.cs @@ -158,10 +158,27 @@ await _client.InvokeAsync(_client.GrpcClient.DescribeIndexAsync, request, static { foreach (IndexDescription index in response.IndexDescriptions) { + IndexState state = index.State switch + { + Grpc.IndexState.None => IndexState.None, + Grpc.IndexState.Unissued => IndexState.Unissued, + Grpc.IndexState.InProgress => IndexState.InProgress, + Grpc.IndexState.Finished => IndexState.Finished, + Grpc.IndexState.Failed => IndexState.Failed, + Grpc.IndexState.Retry => IndexState.Retry, + + _ => throw new InvalidOperationException($"Unknown {nameof(Grpc.IndexState)}: {index.State}") + }; + indexes.Add(new MilvusIndexInfo( index.FieldName, index.IndexName, index.IndexID, + state, + index.IndexedRows, + index.TotalRows, + index.PendingIndexRows, + index.IndexStateFailReason, index.Params.ToDictionary(static p => p.Key, static p => p.Value))); } } @@ -177,7 +194,7 @@ await _client.InvokeAsync(_client.GrpcClient.DescribeIndexAsync, request, static /// /// The token to monitor for cancellation requests. The default value is . /// - /// + [Obsolete("Use DescribeIndex instead")] public async Task GetIndexStateAsync( string fieldName, string? indexName = null, @@ -221,6 +238,7 @@ await _client.InvokeAsync(_client.GrpcClient.GetIndexStateAsync, request, static /// /// An with the number of rows indexed and the total number of rows. /// + [Obsolete("Use DescribeIndex instead")] public async Task GetIndexBuildProgressAsync( string fieldName, string? indexName = null, @@ -268,9 +286,23 @@ public async Task WaitForIndexBuildAsync( await Utils.Poll( async () => { - IndexBuildProgress progress = await GetIndexBuildProgressAsync(fieldName, indexName, cancellationToken) - .ConfigureAwait(false); - return (progress.IsComplete, progress); + IList indexInfos = + await DescribeIndexAsync(fieldName, indexName, cancellationToken).ConfigureAwait(false); + + MilvusIndexInfo indexInfo = indexInfos.FirstOrDefault(i => i.FieldName == fieldName) ?? indexInfos[0]; + + var progress = new IndexBuildProgress(indexInfo.IndexedRows, indexInfo.TotalRows); + + return indexInfo.State switch + { + IndexState.Finished => (true, progress), + IndexState.InProgress => (false, progress), + + IndexState.Failed + => throw new MilvusException("Index creation failed: " + indexInfo.IndexStateFailReason), + + _ => throw new MilvusException("Index isn't building, state is " + indexInfo.State) + }; }, indexName is null ? $"Timeout when waiting for index on collection '{Name}' to build" diff --git a/Milvus.Client/MilvusErrorCode.cs b/Milvus.Client/MilvusErrorCode.cs index d21991d..243703c 100644 --- a/Milvus.Client/MilvusErrorCode.cs +++ b/Milvus.Client/MilvusErrorCode.cs @@ -68,7 +68,6 @@ public enum MilvusErrorCode /// Coord is switching from standby mode to active mode /// NotReadyCoordActivating = Grpc.ErrorCode.NotReadyCoordActivating, - NotFoundTsafer = Grpc.ErrorCode.NotFoundTsafer, /// /// Service availability. diff --git a/Milvus.Client/MilvusIndexInfo.cs b/Milvus.Client/MilvusIndexInfo.cs index 45185e3..f7f2180 100644 --- a/Milvus.Client/MilvusIndexInfo.cs +++ b/Milvus.Client/MilvusIndexInfo.cs @@ -9,11 +9,21 @@ internal MilvusIndexInfo( string fieldName, string indexName, long indexId, + IndexState state, + long indexedRows, + long totalRows, + long pendingIndexRows, + string? indexStateFailReason, IReadOnlyDictionary @params) { FieldName = fieldName; IndexName = indexName; IndexId = indexId; + State = state; + IndexedRows = indexedRows; + TotalRows = totalRows; + PendingIndexRows = pendingIndexRows; + IndexStateFailReason = indexStateFailReason; Params = @params; } @@ -32,6 +42,31 @@ internal MilvusIndexInfo( /// public long IndexId { get; } + /// + /// The state of the index. + /// + public IndexState State { get; } + + /// + /// The number of rows indexed by this index; + /// + public long IndexedRows { get; } + + /// + /// The total rows in the collection. + /// + public long TotalRows { get; } + + /// + /// The number of pending rows in the index. + /// + public long PendingIndexRows { get; } + + /// + /// If creation of the index failed, contains the reason for the failure. + /// + public string? IndexStateFailReason { get; } + /// /// Contains index_type, metric_type, params. /// diff --git a/Milvus.Client/Protos b/Milvus.Client/Protos index ea9f142..04a979a 160000 --- a/Milvus.Client/Protos +++ b/Milvus.Client/Protos @@ -1 +1 @@ -Subproject commit ea9f14251d7556dc47ac625dfeb4b1fc968509c0 +Subproject commit 04a979a79cdf370821d0c30a70828c995a3e781e diff --git a/Version.props b/Version.props index 0c3c135..a8fd0af 100644 --- a/Version.props +++ b/Version.props @@ -1,5 +1,5 @@ - 2.2.2 + 2.3.0 - \ No newline at end of file + diff --git a/global.json b/global.json index db83940..520716f 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.305", + "version": "8.0.201", "rollForward": "latestMajor" } }