-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Update Qdrant Memory Connector to new Text Search Design (#9076)
### Motivation and Context Closes #6733 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Roger Barreto <[email protected]>
- Loading branch information
1 parent
fba0aba
commit 69b9fc4
Showing
3 changed files
with
163 additions
and
27 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
dotnet/src/IntegrationTests/Connectors/Memory/Qdrant/QdrantTextSearchTests.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,93 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.SemanticKernel.Connectors.Qdrant; | ||
using Microsoft.SemanticKernel.Data; | ||
using SemanticKernel.IntegrationTests.Data; | ||
using Xunit; | ||
using static SemanticKernel.IntegrationTests.Connectors.Memory.Qdrant.QdrantVectorStoreFixture; | ||
|
||
namespace SemanticKernel.IntegrationTests.Connectors.Memory.Qdrant; | ||
|
||
/// <summary> | ||
/// Integration tests for using <see cref="QdrantVectorStore"/> with <see cref="ITextSearch"/>. | ||
/// </summary> | ||
[Collection("QdrantVectorStoreCollection")] | ||
public class QdrantTextSearchTests(QdrantVectorStoreFixture fixture) : BaseVectorStoreTextSearchTests | ||
{ | ||
/// <inheritdoc/> | ||
public override Task<ITextSearch> CreateTextSearchAsync() | ||
{ | ||
if (this.VectorStore is null) | ||
{ | ||
this.EmbeddingGenerator = fixture.EmbeddingGenerator; | ||
this.VectorStore = new QdrantVectorStore(fixture.QdrantClient); | ||
} | ||
|
||
var options = new QdrantVectorStoreRecordCollectionOptions<HotelInfo> | ||
{ | ||
HasNamedVectors = true, | ||
VectorStoreRecordDefinition = fixture.HotelVectorStoreRecordDefinition, | ||
}; | ||
var vectorSearch = new QdrantVectorStoreRecordCollection<HotelInfo>(fixture.QdrantClient, "namedVectorsHotels", options); | ||
var stringMapper = new HotelInfoTextSearchStringMapper(); | ||
var resultMapper = new HotelInfoTextSearchResultMapper(); | ||
|
||
var result = new VectorStoreTextSearch<HotelInfo>(vectorSearch, this.EmbeddingGenerator!, stringMapper, resultMapper); | ||
return Task.FromResult<ITextSearch>(result); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string GetQuery() => "Find a great hotel"; | ||
|
||
/// <inheritdoc/> | ||
public override TextSearchFilter GetTextSearchFilter() => new TextSearchFilter().Equality("HotelName", "My Hotel 11"); | ||
|
||
/// <inheritdoc/> | ||
public override bool VerifySearchResults(object[] results, string query, TextSearchFilter? filter = null) | ||
{ | ||
Assert.NotNull(results); | ||
Assert.NotEmpty(results); | ||
Assert.Equal(filter is null ? 4 : 1, results.Length); | ||
foreach (var result in results) | ||
{ | ||
Assert.NotNull(result); | ||
Assert.IsType<HotelInfo>(result); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// String mapper which converts a Hotel to a string. | ||
/// </summary> | ||
protected sealed class HotelInfoTextSearchStringMapper : ITextSearchStringMapper | ||
{ | ||
/// <inheritdoc /> | ||
public string MapFromResultToString(object result) | ||
{ | ||
if (result is HotelInfo hotel) | ||
{ | ||
return $"{hotel.HotelName} {hotel.Description}"; | ||
} | ||
throw new ArgumentException("Invalid result type."); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Result mapper which converts a Hotel to a TextSearchResult. | ||
/// </summary> | ||
protected sealed class HotelInfoTextSearchResultMapper : ITextSearchResultMapper | ||
{ | ||
/// <inheritdoc /> | ||
public TextSearchResult MapFromResultToTextSearchResult(object result) | ||
{ | ||
if (result is HotelInfo hotel) | ||
{ | ||
return new TextSearchResult(name: hotel.HotelName, value: hotel.Description, link: $"id://{hotel.HotelId}"); | ||
} | ||
throw new ArgumentException("Invalid result type."); | ||
} | ||
} | ||
} |
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