Skip to content

Commit

Permalink
chore: change ListIndexesAsync return to a list of IndexInfo (#515)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nand4011 authored Nov 8, 2023
1 parent 714c46b commit 1c8c61f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/Momento.Sdk/Internal/VectorIndexControlClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -69,7 +70,8 @@ public async Task<ListIndexesResponse> 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<string>(response.IndexNames)));
new ListIndexesResponse.Success(
new List<IndexInfo>(response.IndexNames.Select(n => new IndexInfo(n)))));
}
catch (Exception e)
{
Expand Down
39 changes: 39 additions & 0 deletions src/Momento.Sdk/Responses/Vector/IndexInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Momento.Sdk.Responses.Vector;

/// <summary>
/// Information about a vector index.
/// </summary>
public class IndexInfo
{
/// <summary>
/// The name of the index.
/// </summary>
public string Name { get; }

/// <summary>
/// Constructs an IndexInfo.
/// </summary>
/// <param name="name">The name of the index.</param>
public IndexInfo(string name)
{
Name = name;
}

/// <inheritdoc />
public override bool Equals(object obj)
{
return obj is IndexInfo other && Name == other.Name;
}

/// <inheritdoc />
public override int GetHashCode()
{
return Name.GetHashCode();
}

/// <inheritdoc />
public override string ToString()
{
return $"IndexInfo {{ Name = {Name} }}";
}
}
14 changes: 7 additions & 7 deletions src/Momento.Sdk/Responses/Vector/ListIndexesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Momento.Sdk.Responses.Vector;
/// <code>
/// if (response is ListIndexesResponse.Success successResponse)
/// {
/// return successResponse.IndexNames;
/// return successResponse.Indexes;
/// }
/// else if (response is ListIndexesResponse.Error errorResponse)
/// {
Expand All @@ -34,21 +34,21 @@ public abstract class ListIndexesResponse
public class Success : ListIndexesResponse
{
/// <summary>
/// The list of vector available to the user.
/// The list of information about the vector indexes available to the user.
/// </summary>
public List<string> IndexNames { get; }
public List<IndexInfo> Indexes { get; }

/// <include file="../../docs.xml" path='docs/class[@name="Success"]/description/*' />
/// <param name="indexNames">the list of index names</param>
public Success(List<string> indexNames)
/// <param name="indexes">the list of index information</param>
public Success(List<IndexInfo> indexes)
{
IndexNames = indexNames;
Indexes = indexes;
}

/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: {string.Join(", ", IndexNames)}";
return $"{base.ToString()}: {string.Join(", ", Indexes)}";
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Threading.Tasks;
using Momento.Sdk.Responses.Vector;

Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 1c8c61f

Please sign in to comment.