-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add MVI SearchAndFetchVectors method (#517)
Add a new version of the MVI search method that returns the vectors with the hits. Paramaterize the search integration tests so that they cover both search methods.
- Loading branch information
Showing
7 changed files
with
414 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Momento.Sdk/Responses/Vector/SearchAndFetchVectorsResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Momento.Sdk.Exceptions; | ||
|
||
namespace Momento.Sdk.Responses.Vector; | ||
|
||
/// <summary> | ||
/// Parent response type for a list vector indexes request. The | ||
/// response object is resolved to a type-safe object of one of | ||
/// the following subtypes: | ||
/// <list type="bullet"> | ||
/// <item><description>SearchAndFetchVectorsResponse.Success</description></item> | ||
/// <item><description>SearchAndFetchVectorsResponse.Error</description></item> | ||
/// </list> | ||
/// Pattern matching can be used to operate on the appropriate subtype. | ||
/// For example: | ||
/// <code> | ||
/// if (response is SearchAndFetchVectorsResponse.Success successResponse) | ||
/// { | ||
/// return successResponse.Hits; | ||
/// } | ||
/// else if (response is SearchAndFetchVectorsResponse.Error errorResponse) | ||
/// { | ||
/// // handle error as appropriate | ||
/// } | ||
/// else | ||
/// { | ||
/// // handle unexpected response | ||
/// } | ||
/// </code> | ||
/// </summary> | ||
public abstract class SearchAndFetchVectorsResponse | ||
{ | ||
/// <include file="../../docs.xml" path='docs/class[@name="Success"]/description/*' /> | ||
public class Success : SearchAndFetchVectorsResponse | ||
{ | ||
/// <summary> | ||
/// The list of hits returned by the search. | ||
/// </summary> | ||
public List<SearchAndFetchVectorsHit> Hits { get; } | ||
|
||
/// <include file="../../docs.xml" path='docs/class[@name="Success"]/description/*' /> | ||
/// <param name="hits">the search results</param> | ||
public Success(List<SearchAndFetchVectorsHit> hits) | ||
{ | ||
Hits = hits; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
var displayedHits = Hits.Take(5).Select(hit => $"{hit.Id} ({hit.Score})"); | ||
return $"{base.ToString()}: {string.Join(", ", displayedHits)}..."; | ||
} | ||
|
||
} | ||
|
||
/// <include file="../../docs.xml" path='docs/class[@name="Error"]/description/*' /> | ||
public class Error : SearchAndFetchVectorsResponse, IError | ||
{ | ||
/// <include file="../../docs.xml" path='docs/class[@name="Error"]/constructor/*' /> | ||
public Error(SdkException error) | ||
{ | ||
InnerException = error; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public SdkException InnerException { get; } | ||
|
||
/// <inheritdoc /> | ||
public MomentoErrorCode ErrorCode => InnerException.ErrorCode; | ||
|
||
/// <inheritdoc /> | ||
public string Message => $"{InnerException.MessageWrapper}: {InnerException.Message}"; | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return $"{base.ToString()}: {Message}"; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.