Added ability to filter based on score of similarity in a couple ways.
This commit is contained in:
@@ -156,13 +156,29 @@ async Task SearchAddressesAsync(IEmbeddingService embeddingService, IQdrantServi
|
||||
return;
|
||||
}
|
||||
|
||||
Console.Write("Enter similarity threshold (0.0-1.0, lower = stricter, press Enter for 0.7): ");
|
||||
var thresholdInput = Console.ReadLine()?.Trim();
|
||||
float threshold = 0.7f;
|
||||
if (!string.IsNullOrEmpty(thresholdInput) && float.TryParse(thresholdInput, out var parsedThreshold))
|
||||
{
|
||||
threshold = Math.Clamp(parsedThreshold, 0f, 1f);
|
||||
}
|
||||
|
||||
Console.Write("Enter max results to return (press Enter for 5, or '2' for top 2 most similar): ");
|
||||
var limitInput = Console.ReadLine()?.Trim();
|
||||
int limit = 5;
|
||||
if (!string.IsNullOrEmpty(limitInput) && int.TryParse(limitInput, out var parsedLimit))
|
||||
{
|
||||
limit = Math.Max(1, parsedLimit);
|
||||
}
|
||||
|
||||
Console.WriteLine("Generating query embedding...");
|
||||
try
|
||||
{
|
||||
var queryEmbedding = await embeddingService.GenerateEmbeddingAsync(query);
|
||||
Console.WriteLine($"Searching for similar addresses...");
|
||||
Console.WriteLine($"Searching for similar addresses (threshold: {threshold:F2}, max results: {limit})...");
|
||||
|
||||
var results = await qdrantService.SearchSimilarAddressesAsync(queryEmbedding, limit: 5);
|
||||
var results = await qdrantService.SearchSimilarAddressesAsync(queryEmbedding, limit: limit, scoreThreshold: threshold);
|
||||
|
||||
if (results.Count == 0)
|
||||
{
|
||||
@@ -173,7 +189,7 @@ async Task SearchAddressesAsync(IEmbeddingService embeddingService, IQdrantServi
|
||||
Console.WriteLine($"\nFound {results.Count} similar address(es):");
|
||||
for (int i = 0; i < results.Count; i++)
|
||||
{
|
||||
Console.WriteLine($" {i + 1}. {results[i].FullAddress}");
|
||||
Console.WriteLine($" {i + 1}. {results[i].FullAddress} (Score: {results[i].Score:F4})");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user