From 0209ecf9db9e3aec2c114cf58402769e0a3f5a3f Mon Sep 17 00:00:00 2001 From: Nate Anderson Date: Wed, 8 Nov 2023 14:51:55 -0800 Subject: [PATCH] chore: change ListIndexesAsync return to a list of IndexInfo Change the data that ListIndexesAsync returns from a list of index names to a list of IndexInfo object containing the names. We will add more fields in the future. --- .../Internal/VectorIndexControlClient.cs | 4 +- src/Momento.Sdk/Responses/Vector/IndexInfo.cs | 39 +++++++++++++++++++ .../Responses/Vector/ListIndexesResponse.cs | 14 +++---- .../VectorIndexControlTest.cs | 3 +- 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 src/Momento.Sdk/Responses/Vector/IndexInfo.cs diff --git a/src/Momento.Sdk/Internal/VectorIndexControlClient.cs b/src/Momento.Sdk/Internal/VectorIndexControlClient.cs index 4d2f066a..ba149917 100644 --- a/src/Momento.Sdk/Internal/VectorIndexControlClient.cs +++ b/src/Momento.Sdk/Internal/VectorIndexControlClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Grpc.Core; using Microsoft.Extensions.Logging; @@ -69,7 +70,8 @@ public async Task ListIndexesAsync() var request = new _ListIndexesRequest(); var response = await grpcManager.Client.ListIndexesAsync(request, new CallOptions(deadline: CalculateDeadline())); return _logger.LogTraceGenericRequestSuccess("listVectorIndexes", - new ListIndexesResponse.Success(new List(response.IndexNames))); + new ListIndexesResponse.Success( + new List(response.IndexNames.Select(n => new IndexInfo(n))))); } catch (Exception e) { diff --git a/src/Momento.Sdk/Responses/Vector/IndexInfo.cs b/src/Momento.Sdk/Responses/Vector/IndexInfo.cs new file mode 100644 index 00000000..f3ae12eb --- /dev/null +++ b/src/Momento.Sdk/Responses/Vector/IndexInfo.cs @@ -0,0 +1,39 @@ +namespace Momento.Sdk.Responses.Vector; + +/// +/// Information about a vector index. +/// +public class IndexInfo +{ + /// + /// The name of the index. + /// + public string Name { get; } + + /// + /// Constructs an IndexInfo. + /// + /// The name of the index. + public IndexInfo(string name) + { + Name = name; + } + + /// + public override bool Equals(object obj) + { + return obj is IndexInfo other && Name == other.Name; + } + + /// + public override int GetHashCode() + { + return Name.GetHashCode(); + } + + /// + public override string ToString() + { + return $"IndexInfo {{ Name = {Name} }}"; + } +} \ No newline at end of file diff --git a/src/Momento.Sdk/Responses/Vector/ListIndexesResponse.cs b/src/Momento.Sdk/Responses/Vector/ListIndexesResponse.cs index 9d6793e6..f6fc2bcf 100644 --- a/src/Momento.Sdk/Responses/Vector/ListIndexesResponse.cs +++ b/src/Momento.Sdk/Responses/Vector/ListIndexesResponse.cs @@ -16,7 +16,7 @@ namespace Momento.Sdk.Responses.Vector; /// /// if (response is ListIndexesResponse.Success successResponse) /// { -/// return successResponse.IndexNames; +/// return successResponse.Indexes; /// } /// else if (response is ListIndexesResponse.Error errorResponse) /// { @@ -34,21 +34,21 @@ public abstract class ListIndexesResponse public class Success : ListIndexesResponse { /// - /// The list of vector available to the user. + /// The list of information about the vector indexes available to the user. /// - public List IndexNames { get; } + public List Indexes { get; } /// - /// the list of index names - public Success(List indexNames) + /// the list of index information + public Success(List indexes) { - IndexNames = indexNames; + Indexes = indexes; } /// public override string ToString() { - return $"{base.ToString()}: {string.Join(", ", IndexNames)}"; + return $"{base.ToString()}: {string.Join(", ", Indexes)}"; } } diff --git a/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs b/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs index b0ca0621..ad2435e7 100644 --- a/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs +++ b/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs @@ -1,3 +1,4 @@ +using System.Linq; using System.Threading.Tasks; using Momento.Sdk.Responses.Vector; @@ -26,7 +27,7 @@ public async Task CreateListDelete_HappyPath() var listResponse = await vectorIndexClient.ListIndexesAsync(); Assert.True(listResponse is ListIndexesResponse.Success, $"Unexpected response: {listResponse}"); var listOk = (ListIndexesResponse.Success)listResponse; - Assert.Contains(listOk.IndexNames, name => name == indexName); + Assert.Contains(listOk.Indexes.Select(i => i.Name), name => name == indexName); } finally {