Skip to content

Commit

Permalink
Basic changes needed to get tests passing on Milvus 2.3 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Feb 20, 2024
1 parent c1d2689 commit 96550ae
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 12 additions & 14 deletions Milvus.Client.Tests/IndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand All @@ -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()
{
Expand All @@ -123,17 +117,19 @@ public async Task GetState()
}

[Fact]
public async Task GetBuildProgress()
public async Task GetBuildProgress_with_name()
{
await Assert.ThrowsAsync<MilvusException>(() =>
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()
Expand Down Expand Up @@ -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<MilvusException>(
() => Collection.DescribeIndexAsync("float_vector"));
Assert.Equal(MilvusErrorCode.IndexNotExist, exception.ErrorCode);
}

public async Task InitializeAsync()
Expand Down
1 change: 1 addition & 0 deletions Milvus.Client/Milvus.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Protobuf Include="Protos\proto\common.proto" GrpcServices="Client" Access="internal" />
<Protobuf Include="Protos\proto\schema.proto" GrpcServices="Client" ProtoRoot="Protos\proto" Access="internal" />
<Protobuf Include="Protos\proto\milvus.proto" GrpcServices="Client" ProtoRoot="Protos\proto" Access="internal" />
<Protobuf Include="Protos\proto\feder.proto" GrpcServices="Client" ProtoRoot="Protos\proto" Access="internal" />
</ItemGroup>

<ItemGroup>
Expand Down
40 changes: 36 additions & 4 deletions Milvus.Client/MilvusCollection.Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Expand All @@ -177,7 +194,7 @@ await _client.InvokeAsync(_client.GrpcClient.DescribeIndexAsync, request, static
/// <param name="cancellationToken">
/// The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None" />.
/// </param>
/// <returns></returns>
[Obsolete("Use DescribeIndex instead")]
public async Task<IndexState> GetIndexStateAsync(
string fieldName,
string? indexName = null,
Expand Down Expand Up @@ -221,6 +238,7 @@ await _client.InvokeAsync(_client.GrpcClient.GetIndexStateAsync, request, static
/// <returns>
/// An <see cref="IndexBuildProgress" /> with the number of rows indexed and the total number of rows.
/// </returns>
[Obsolete("Use DescribeIndex instead")]
public async Task<IndexBuildProgress> GetIndexBuildProgressAsync(
string fieldName,
string? indexName = null,
Expand Down Expand Up @@ -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<MilvusIndexInfo> 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"
Expand Down
1 change: 0 additions & 1 deletion Milvus.Client/MilvusErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public enum MilvusErrorCode
/// Coord is switching from standby mode to active mode
/// </summary>
NotReadyCoordActivating = Grpc.ErrorCode.NotReadyCoordActivating,
NotFoundTsafer = Grpc.ErrorCode.NotFoundTsafer,

/// <summary>
/// Service availability.
Expand Down
35 changes: 35 additions & 0 deletions Milvus.Client/MilvusIndexInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ internal MilvusIndexInfo(
string fieldName,
string indexName,
long indexId,
IndexState state,
long indexedRows,
long totalRows,
long pendingIndexRows,
string? indexStateFailReason,
IReadOnlyDictionary<string, string> @params)
{
FieldName = fieldName;
IndexName = indexName;
IndexId = indexId;
State = state;
IndexedRows = indexedRows;
TotalRows = totalRows;
PendingIndexRows = pendingIndexRows;
IndexStateFailReason = indexStateFailReason;
Params = @params;
}

Expand All @@ -32,6 +42,31 @@ internal MilvusIndexInfo(
/// </summary>
public long IndexId { get; }

/// <summary>
/// The state of the index.
/// </summary>
public IndexState State { get; }

/// <summary>
/// The number of rows indexed by this index;
/// </summary>
public long IndexedRows { get; }

/// <summary>
/// The total rows in the collection.
/// </summary>
public long TotalRows { get; }

/// <summary>
/// The number of pending rows in the index.
/// </summary>
public long PendingIndexRows { get; }

/// <summary>
/// If creation of the index failed, contains the reason for the failure.
/// </summary>
public string? IndexStateFailReason { get; }

/// <summary>
/// Contains index_type, metric_type, params.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>2.2.2</Version>
<Version>2.3.0</Version>
</PropertyGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.305",
"version": "8.0.201",
"rollForward": "latestMajor"
}
}

0 comments on commit 96550ae

Please sign in to comment.