|
2 | 2 |
|
3 | 3 | using System; |
4 | 4 | using System.Collections.Generic; |
| 5 | +using System.Globalization; |
5 | 6 | using System.Linq; |
| 7 | +using System.Net; |
| 8 | +using System.Net.Http; |
6 | 9 | using System.Threading; |
7 | 10 | using System.Threading.Tasks; |
8 | 11 | using Microsoft.SemanticKernel.AI.Embeddings; |
9 | 12 | using Microsoft.SemanticKernel.Connectors.Memory.Qdrant; |
10 | 13 | using Microsoft.SemanticKernel.Memory; |
11 | 14 | using Moq; |
| 15 | +using Moq.Protected; |
12 | 16 | using Xunit; |
13 | 17 |
|
14 | 18 | namespace SemanticKernel.Connectors.UnitTests.Memory.Qdrant; |
@@ -224,4 +228,82 @@ public async Task ItReturnsEmptyListIfNearestMatchesNotFoundAsync() |
224 | 228 | // Assert |
225 | 229 | Assert.Empty(similarityResults); |
226 | 230 | } |
| 231 | + |
| 232 | + [Fact] |
| 233 | + public async Task ScoredVectorSupportsIntegerIds() |
| 234 | + { |
| 235 | + // Arrange |
| 236 | + var payloadId = "payloadId"; |
| 237 | + var metadataId = "metadataId"; |
| 238 | + var expectedId = 100; |
| 239 | + |
| 240 | + var scoredPointJsonWithIntegerId = |
| 241 | + "{" + |
| 242 | + "\"result\": " + |
| 243 | + " [{" + |
| 244 | + "\"id\": " + expectedId + "," + |
| 245 | + "\"version\": 0," + |
| 246 | + "\"score\": null," + |
| 247 | + "\"payload\": {}," + |
| 248 | + "\"vector\": null " + |
| 249 | + "}]" + |
| 250 | + "}"; |
| 251 | + |
| 252 | + using (var httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(scoredPointJsonWithIntegerId) }) |
| 253 | + { |
| 254 | + var mockHttpMessageHandler = new Mock<HttpMessageHandler>(); |
| 255 | + mockHttpMessageHandler.Protected() |
| 256 | + .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()) |
| 257 | + .ReturnsAsync(httpResponseMessage); |
| 258 | + |
| 259 | + //Act |
| 260 | + using var httpClient = new HttpClient(mockHttpMessageHandler.Object); |
| 261 | + { |
| 262 | + var client = new QdrantVectorDbClient("http://localhost", 1536, null, httpClient); |
| 263 | + var result = await client.GetVectorByPayloadIdAsync(payloadId, metadataId); |
| 264 | + |
| 265 | + //Assert |
| 266 | + Assert.Equal<string>(result!.PointId, expectedId.ToString(CultureInfo.InvariantCulture)); |
| 267 | + } |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + [Fact] |
| 272 | + public async Task ScoredVectorSupportsStringIds() |
| 273 | + { |
| 274 | + // Arrange |
| 275 | + var payloadId = "payloadId"; |
| 276 | + var metadataId = "metadataId"; |
| 277 | + var expectedId = Guid.NewGuid().ToString(); |
| 278 | + |
| 279 | + var scoredPointJsonWithIntegerId = |
| 280 | + "{" + |
| 281 | + "\"result\": " + |
| 282 | + " [{" + |
| 283 | + "\"id\": \"" + expectedId + "\"," + |
| 284 | + "\"version\": 0," + |
| 285 | + "\"score\": null," + |
| 286 | + "\"payload\": {}," + |
| 287 | + "\"vector\": null " + |
| 288 | + "}]" + |
| 289 | + "}"; |
| 290 | + |
| 291 | + using (var httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(scoredPointJsonWithIntegerId) }) |
| 292 | + { |
| 293 | + var mockHttpMessageHandler = new Mock<HttpMessageHandler>(); |
| 294 | + mockHttpMessageHandler.Protected() |
| 295 | + .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()) |
| 296 | + .ReturnsAsync(httpResponseMessage); |
| 297 | + |
| 298 | + //Act |
| 299 | + using var httpClient = new HttpClient(mockHttpMessageHandler.Object); |
| 300 | + { |
| 301 | + var client = new QdrantVectorDbClient("http://localhost", 1536, null, httpClient); |
| 302 | + var result = await client.GetVectorByPayloadIdAsync(payloadId, metadataId); |
| 303 | + |
| 304 | + //Assert |
| 305 | + Assert.Equal<string>(result!.PointId, expectedId); |
| 306 | + } |
| 307 | + } |
| 308 | + } |
227 | 309 | } |
0 commit comments