Added ability to filter based on score of similarity in a couple ways.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user