Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change ListIndexesAsync return to a list of IndexInfo #515

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading