Added ability to filter based on score of similarity in a couple ways.

This commit is contained in:
2026-01-13 23:57:09 -05:00
parent 4dac36605b
commit b2c6898140
3 changed files with 25 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ public interface IQdrantService
{
Task InitializeCollectionAsync(CancellationToken cancellationToken = default);
Task StoreAddressAsync(Address address, float[] embedding, CancellationToken cancellationToken = default);
Task<List<AddressEmbedding>> SearchSimilarAddressesAsync(float[] queryEmbedding, int limit = 5, CancellationToken cancellationToken = default);
Task<List<AddressEmbedding>> SearchSimilarAddressesAsync(float[] queryEmbedding, int limit = 5, float scoreThreshold = 0.0f, CancellationToken cancellationToken = default);
}
public class QdrantService : IQdrantService
@@ -55,15 +55,16 @@ public class QdrantService : IQdrantService
await _client.UpsertAsync(_collectionName, new[] { point }, cancellationToken: cancellationToken);
}
public async Task<List<AddressEmbedding>> SearchSimilarAddressesAsync(float[] queryEmbedding, int limit = 5, CancellationToken cancellationToken = default)
public async Task<List<AddressEmbedding>> SearchSimilarAddressesAsync(float[] queryEmbedding, int limit = 5, float scoreThreshold = 0.0f, CancellationToken cancellationToken = default)
{
var results = await _client.SearchAsync(_collectionName, queryEmbedding, limit: (ulong)limit, cancellationToken: cancellationToken);
var results = await _client.SearchAsync(_collectionName, queryEmbedding, limit: (ulong)limit, scoreThreshold: scoreThreshold, cancellationToken: cancellationToken);
return results.Select(r => new AddressEmbedding
{
Id = Guid.Parse(r.Id.Uuid),
FullAddress = r.Payload["address"].StringValue,
Vector = Array.Empty<float>()
Vector = Array.Empty<float>(),
Score = r.Score
}).ToList();
}
}