Skip to content

Commit

Permalink
Remove 'vector' from request/response classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nand4011 committed Oct 31, 2023
1 parent 078b735 commit bb410f3
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 173 deletions.
52 changes: 26 additions & 26 deletions src/Momento.Sdk/IPreviewVectorIndexClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public interface IPreviewVectorIndexClient : IDisposable
/// is resolved to a type-safe object of one of
/// the following subtypes:
/// <list type="bullet">
/// <item><description>CreateVectorIndexResponse.Success</description></item>
/// <item><description>CreateVectorIndexResponse.AlreadyExists</description></item>
/// <item><description>CreateVectorIndexResponse.Error</description></item>
/// <item><description>CreateIndexResponse.Success</description></item>
/// <item><description>CreateIndexResponse.AlreadyExists</description></item>
/// <item><description>CreateIndexResponse.Error</description></item>
/// </list>
/// Pattern matching can be used to operate on the appropriate subtype.
/// For example:
/// <code>
/// if (response is CreateVectorIndexResponse.Error errorResponse)
/// if (response is CreateIndexResponse.Error errorResponse)
/// {
/// // handle error as appropriate
/// }
Expand All @@ -58,7 +58,7 @@ public interface IPreviewVectorIndexClient : IDisposable
/// </list>
/// </remarks>
/// </returns>
public Task<CreateVectorIndexResponse> CreateIndexAsync(string indexName, long numDimensions, SimilarityMetric similarityMetric = SimilarityMetric.CosineSimilarity);
public Task<CreateIndexResponse> CreateIndexAsync(string indexName, long numDimensions, SimilarityMetric similarityMetric = SimilarityMetric.CosineSimilarity);

/// <summary>
/// Lists all vector indexes.
Expand All @@ -68,19 +68,19 @@ public interface IPreviewVectorIndexClient : IDisposable
/// response object is resolved to a type-safe object of one of
/// the following subtypes:
/// <list type="bullet">
/// <item><description>ListVectorIndexesResponse.Success</description></item>
/// <item><description>ListVectorIndexesResponse.Error</description></item>
/// <item><description>ListIndexesResponse.Success</description></item>
/// <item><description>ListIndexesResponse.Error</description></item>
/// </list>
/// Pattern matching can be used to operate on the appropriate subtype.
/// For example:
/// <code>
/// if (response is ListVectorIndexesResponse.Error errorResponse)
/// if (response is ListIndexesResponse.Error errorResponse)
/// {
/// // handle error as appropriate
/// }
/// </code>
/// </returns>
public Task<ListVectorIndexesResponse> ListIndexesAsync();
public Task<ListIndexesResponse> ListIndexesAsync();

/// <summary>
/// Deletes a vector index and all the vectors within it.
Expand All @@ -91,19 +91,19 @@ public interface IPreviewVectorIndexClient : IDisposable
/// response object is resolved to a type-safe object of one of
/// the following subtypes:
/// <list type="bullet">
/// <item><description>DeleteVectorIndexResponse.Success</description></item>
/// <item><description>DeleteVectorIndexResponse.Error</description></item>
/// <item><description>DeleteIndexResponse.Success</description></item>
/// <item><description>DeleteIndexResponse.Error</description></item>
/// </list>
/// Pattern matching can be used to operate on the appropriate subtype.
/// For example:
/// <code>
/// if (response is DeleteVectorIndexResponse.Error errorResponse)
/// if (response is DeleteIndexResponse.Error errorResponse)
/// {
/// // handle error as appropriate
/// }
/// </code>
///</returns>
public Task<DeleteVectorIndexResponse> DeleteIndexesAsync(string indexName);
public Task<DeleteIndexResponse> DeleteIndexesAsync(string indexName);

/// <summary>
/// Upserts a batch of items into a vector index.
Expand All @@ -117,20 +117,20 @@ public interface IPreviewVectorIndexClient : IDisposable
/// response object is resolved to a type-safe object of one of
/// the following subtypes:
/// <list type="bullet">
/// <item><description>VectorUpsertItemBatchResponse.Success</description></item>
/// <item><description>VectorUpsertItemBatchResponse.Error</description></item>
/// <item><description>UpsertItemBatchResponse.Success</description></item>
/// <item><description>UpsertItemBatchResponse.Error</description></item>
/// </list>
/// Pattern matching can be used to operate on the appropriate subtype.
/// For example:
/// <code>
/// if (response is VectorUpsertItemBatchResponse.Error errorResponse)
/// if (response is UpsertItemBatchResponse.Error errorResponse)
/// {
/// // handle error as appropriate
/// }
/// </code>
///</returns>
public Task<VectorUpsertItemBatchResponse> UpsertItemBatchAsync(string indexName,
IEnumerable<VectorIndexItem> items);
public Task<UpsertItemBatchResponse> UpsertItemBatchAsync(string indexName,
IEnumerable<Item> items);

/// <summary>
/// Deletes all items with the given IDs from the index.
Expand All @@ -142,19 +142,19 @@ public Task<VectorUpsertItemBatchResponse> UpsertItemBatchAsync(string indexName
/// response object is resolved to a type-safe object of one of
/// the following subtypes:
/// <list type="bullet">
/// <item><description>VectorDeleteItemBatchResponse.Success</description></item>
/// <item><description>VectorDeleteItemBatchResponse.Error</description></item>
/// <item><description>DeleteItemBatchResponse.Success</description></item>
/// <item><description>DeleteItemBatchResponse.Error</description></item>
/// </list>
/// Pattern matching can be used to operate on the appropriate subtype.
/// For example:
/// <code>
/// if (response is VectorDeleteItemBatchResponse.Error errorResponse)
/// if (response is DeleteItemBatchResponse.Error errorResponse)
/// {
/// // handle error as appropriate
/// }
/// </code>
///</returns>
public Task<VectorDeleteItemBatchResponse> DeleteItemBatchAsync(string indexName, IEnumerable<string> ids);
public Task<DeleteItemBatchResponse> DeleteItemBatchAsync(string indexName, IEnumerable<string> ids);

/// <summary>
/// Searches for the most similar vectors to the query vector in the index.
Expand All @@ -170,18 +170,18 @@ public Task<VectorUpsertItemBatchResponse> UpsertItemBatchAsync(string indexName
/// response object is resolved to a type-safe object of one of
/// the following subtypes:
/// <list type="bullet">
/// <item><description>VectorDeleteItemBatchResponse.Success</description></item>
/// <item><description>VectorDeleteItemBatchResponse.Error</description></item>
/// <item><description>DeleteItemBatchResponse.Success</description></item>
/// <item><description>DeleteItemBatchResponse.Error</description></item>
/// </list>
/// Pattern matching can be used to operate on the appropriate subtype.
/// For example:
/// <code>
/// if (response is VectorDeleteItemBatchResponse.Error errorResponse)
/// if (response is DeleteItemBatchResponse.Error errorResponse)
/// {
/// // handle error as appropriate
/// }
/// </code>
///</returns>
public Task<VectorSearchResponse> SearchAsync(string indexName, IEnumerable<float> queryVector, int topK = 10,
public Task<SearchResponse> SearchAsync(string indexName, IEnumerable<float> queryVector, int topK = 10,
MetadataFields? metadataFields = null);
}
20 changes: 10 additions & 10 deletions src/Momento.Sdk/Internal/VectorIndexControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public VectorIndexControlClient(ILoggerFactory loggerFactory, string authToken,
_exceptionMapper = new CacheExceptionMapper(loggerFactory);
}

public async Task<CreateVectorIndexResponse> CreateIndexAsync(string indexName, long numDimensions, SimilarityMetric similarityMetric)
public async Task<CreateIndexResponse> CreateIndexAsync(string indexName, long numDimensions, SimilarityMetric similarityMetric)
{
try
{
Expand All @@ -49,47 +49,47 @@ public async Task<CreateVectorIndexResponse> CreateIndexAsync(string indexName,
}

await grpcManager.Client.CreateIndexAsync(request, new CallOptions(deadline: CalculateDeadline()));
return _logger.LogTraceVectorIndexRequestSuccess("createVectorIndex", indexName, new CreateVectorIndexResponse.Success());
return _logger.LogTraceVectorIndexRequestSuccess("createVectorIndex", indexName, new CreateIndexResponse.Success());
}
catch (Exception e)
{
if (e is RpcException { StatusCode: StatusCode.AlreadyExists })
{
return _logger.LogTraceVectorIndexRequestSuccess("createVectorIndex", indexName, new CreateVectorIndexResponse.AlreadyExists());
return _logger.LogTraceVectorIndexRequestSuccess("createVectorIndex", indexName, new CreateIndexResponse.AlreadyExists());
}
return _logger.LogTraceVectorIndexRequestError("createVectorIndex", indexName, new CreateVectorIndexResponse.Error(_exceptionMapper.Convert(e)));
return _logger.LogTraceVectorIndexRequestError("createVectorIndex", indexName, new CreateIndexResponse.Error(_exceptionMapper.Convert(e)));
}
}

public async Task<ListVectorIndexesResponse> ListIndexesAsync()
public async Task<ListIndexesResponse> ListIndexesAsync()
{
try
{
_logger.LogTraceExecutingGenericRequest("listVectorIndexes");
var request = new _ListIndexesRequest();
var response = await grpcManager.Client.ListIndexesAsync(request, new CallOptions(deadline: CalculateDeadline()));
return _logger.LogTraceGenericRequestSuccess("listVectorIndexes",
new ListVectorIndexesResponse.Success(new List<string>(response.IndexNames)));
new ListIndexesResponse.Success(new List<string>(response.IndexNames)));
}
catch (Exception e)
{
return _logger.LogTraceGenericRequestError("listVectorIndexes", new ListVectorIndexesResponse.Error(_exceptionMapper.Convert(e)));
return _logger.LogTraceGenericRequestError("listVectorIndexes", new ListIndexesResponse.Error(_exceptionMapper.Convert(e)));
}
}

public async Task<DeleteVectorIndexResponse> DeleteIndexAsync(string indexName)
public async Task<DeleteIndexResponse> DeleteIndexAsync(string indexName)
{
try
{
_logger.LogTraceVectorIndexRequest("deleteVectorIndex", indexName);
CheckValidIndexName(indexName);
var request = new _DeleteIndexRequest() { IndexName = indexName };
await grpcManager.Client.DeleteIndexAsync(request, new CallOptions(deadline: CalculateDeadline()));
return _logger.LogTraceVectorIndexRequestSuccess("createVectorIndex", indexName, new DeleteVectorIndexResponse.Success());
return _logger.LogTraceVectorIndexRequestSuccess("createVectorIndex", indexName, new DeleteIndexResponse.Success());
}
catch (Exception e)
{
return _logger.LogTraceVectorIndexRequestError("createVectorIndex", indexName, new DeleteVectorIndexResponse.Error(_exceptionMapper.Convert(e)));
return _logger.LogTraceVectorIndexRequestError("createVectorIndex", indexName, new DeleteIndexResponse.Error(_exceptionMapper.Convert(e)));
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/Momento.Sdk/Internal/VectorIndexDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public VectorIndexDataClient(IVectorIndexConfiguration config, string authToken,
_exceptionMapper = new CacheExceptionMapper(config.LoggerFactory);
}

public async Task<VectorUpsertItemBatchResponse> UpsertItemBatchAsync(string indexName,
IEnumerable<VectorIndexItem> items)
public async Task<UpsertItemBatchResponse> UpsertItemBatchAsync(string indexName,
IEnumerable<Item> items)
{
try
{
Expand All @@ -39,16 +39,16 @@ public async Task<VectorUpsertItemBatchResponse> UpsertItemBatchAsync(string ind

await grpcManager.Client.UpsertItemBatchAsync(request, new CallOptions(deadline: CalculateDeadline()));
return _logger.LogTraceVectorIndexRequestSuccess("upsertItemBatch", indexName,
new VectorUpsertItemBatchResponse.Success());
new UpsertItemBatchResponse.Success());
}
catch (Exception e)
{
return _logger.LogTraceVectorIndexRequestError("upsertItemBatch", indexName,
new VectorUpsertItemBatchResponse.Error(_exceptionMapper.Convert(e)));
new UpsertItemBatchResponse.Error(_exceptionMapper.Convert(e)));
}
}

public async Task<VectorDeleteItemBatchResponse> DeleteItemBatchAsync(string indexName, IEnumerable<string> ids)
public async Task<DeleteItemBatchResponse> DeleteItemBatchAsync(string indexName, IEnumerable<string> ids)
{
try
{
Expand All @@ -58,16 +58,16 @@ public async Task<VectorDeleteItemBatchResponse> DeleteItemBatchAsync(string ind

await grpcManager.Client.DeleteItemBatchAsync(request, new CallOptions(deadline: CalculateDeadline()));
return _logger.LogTraceVectorIndexRequestSuccess("deleteItemBatch", indexName,
new VectorDeleteItemBatchResponse.Success());
new DeleteItemBatchResponse.Success());
}
catch (Exception e)
{
return _logger.LogTraceVectorIndexRequestError("deleteItemBatch", indexName,
new VectorDeleteItemBatchResponse.Error(_exceptionMapper.Convert(e)));
new DeleteItemBatchResponse.Error(_exceptionMapper.Convert(e)));
}
}

public async Task<VectorSearchResponse> SearchAsync(string indexName, IEnumerable<float> queryVector, int topK,
public async Task<SearchResponse> SearchAsync(string indexName, IEnumerable<float> queryVector, int topK,
MetadataFields? metadataFields)
{
try
Expand Down Expand Up @@ -98,16 +98,16 @@ public async Task<VectorSearchResponse> SearchAsync(string indexName, IEnumerabl
await grpcManager.Client.SearchAsync(request, new CallOptions(deadline: CalculateDeadline()));
var searchHits = response.Hits.Select(Convert).ToList();
return _logger.LogTraceVectorIndexRequestSuccess("search", indexName,
new VectorSearchResponse.Success(searchHits));
new SearchResponse.Success(searchHits));
}
catch (Exception e)
{
return _logger.LogTraceVectorIndexRequestError("search", indexName,
new VectorSearchResponse.Error(_exceptionMapper.Convert(e)));
new SearchResponse.Error(_exceptionMapper.Convert(e)));
}
}

private static _Item Convert(VectorIndexItem item)
private static _Item Convert(Item item)
{
return new _Item
{
Expand Down
14 changes: 7 additions & 7 deletions src/Momento.Sdk/PreviewVectorIndexClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,39 @@ public PreviewVectorIndexClient(IVectorIndexConfiguration config, ICredentialPro
}

/// <inheritdoc />
public async Task<CreateVectorIndexResponse> CreateIndexAsync(string indexName, long numDimensions,
public async Task<CreateIndexResponse> CreateIndexAsync(string indexName, long numDimensions,
SimilarityMetric similarityMetric = SimilarityMetric.CosineSimilarity)
{
return await controlClient.CreateIndexAsync(indexName, numDimensions, similarityMetric);
}

/// <inheritdoc />
public async Task<ListVectorIndexesResponse> ListIndexesAsync()
public async Task<ListIndexesResponse> ListIndexesAsync()
{
return await controlClient.ListIndexesAsync();
}

/// <inheritdoc />
public async Task<DeleteVectorIndexResponse> DeleteIndexesAsync(string indexName)
public async Task<DeleteIndexResponse> DeleteIndexesAsync(string indexName)
{
return await controlClient.DeleteIndexAsync(indexName);
}

/// <inheritdoc />
public async Task<VectorUpsertItemBatchResponse> UpsertItemBatchAsync(string indexName,
IEnumerable<VectorIndexItem> items)
public async Task<UpsertItemBatchResponse> UpsertItemBatchAsync(string indexName,
IEnumerable<Item> items)
{
return await dataClient.UpsertItemBatchAsync(indexName, items);
}

/// <inheritdoc />
public async Task<VectorDeleteItemBatchResponse> DeleteItemBatchAsync(string indexName, IEnumerable<string> ids)
public async Task<DeleteItemBatchResponse> DeleteItemBatchAsync(string indexName, IEnumerable<string> ids)
{
return await dataClient.DeleteItemBatchAsync(indexName, ids);
}

/// <inheritdoc />
public async Task<VectorSearchResponse> SearchAsync(string indexName, IEnumerable<float> queryVector,
public async Task<SearchResponse> SearchAsync(string indexName, IEnumerable<float> queryVector,
int topK = 10, MetadataFields? metadataFields = null)
{
return await dataClient.SearchAsync(indexName, queryVector, topK, metadataFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
namespace Momento.Sdk.Requests.Vector;

/// <summary>
/// A item in a vector index. Contains an ID, the vector, and any associated metadata.
/// An item in a vector index. Contains an ID, the vector, and any associated metadata.
/// </summary>
public class VectorIndexItem
public class Item
{
/// <summary>
/// Constructs a VectorIndexItem with no metadata.
/// Constructs a Item with no metadata.
/// </summary>
/// <param name="id">the ID of the vector.</param>
/// <param name="vector">the vector.</param>
public VectorIndexItem(string id, List<float> vector)
public Item(string id, List<float> vector)
{
Id = id;
Vector = vector;
Metadata = new Dictionary<string, MetadataValue>();
}

/// <summary>
/// Constructs a VectorIndexItem.
/// Constructs a Item.
/// </summary>
/// <param name="id">the ID of the vector.</param>
/// <param name="vector">the vector.</param>
/// <param name="metadata">Metadata associated with the vector.</param>
public VectorIndexItem(string id, List<float> vector, Dictionary<string, MetadataValue> metadata)
public Item(string id, List<float> vector, Dictionary<string, MetadataValue> metadata)
{
Id = id;
Vector = vector;
Expand Down
Loading

0 comments on commit bb410f3

Please sign in to comment.