feat(app): add get all addresses feature

This commit is contained in:
2026-01-14 17:50:00 -05:00
parent b2c6898140
commit 12fd2ef45e
2 changed files with 56 additions and 2 deletions

View File

@@ -60,12 +60,13 @@ while (true)
Console.WriteLine("Options:");
Console.WriteLine(" 1. Add a new address");
Console.WriteLine(" 2. Search for similar addresses");
Console.WriteLine(" 3. Exit");
Console.WriteLine(" 3. Get all addresses");
Console.WriteLine(" 4. Exit");
Console.Write("Select an option: ");
var option = Console.ReadLine()?.Trim();
if (option?.ToLower() == "exit" || option == "3")
if (option?.ToLower() == "exit" || option == "4")
{
Console.WriteLine("Goodbye!");
return;
@@ -79,6 +80,9 @@ while (true)
case "2":
await SearchAddressesAsync(embeddingService, qdrantService, appConfig);
break;
case "3":
await GetAllAddressesAsync(qdrantService);
break;
default:
Console.WriteLine("Invalid option. Please try again.");
break;
@@ -197,3 +201,34 @@ async Task SearchAddressesAsync(IEmbeddingService embeddingService, IQdrantServi
Console.WriteLine($"Error during search: {ex.Message}");
}
}
async Task GetAllAddressesAsync(IQdrantService? qdrantService)
{
if (qdrantService == null)
{
Console.WriteLine("Getting all addresses is not available because Qdrant is not connected.");
return;
}
try
{
Console.WriteLine("Retrieving all addresses...");
var addresses = await qdrantService.GetAllAddressesAsync();
if (addresses.Count == 0)
{
Console.WriteLine("No addresses found in the database.");
return;
}
Console.WriteLine($"\nFound {addresses.Count} address(es):");
for (int i = 0; i < addresses.Count; i++)
{
Console.WriteLine($" {i + 1}. {addresses[i].FullAddress}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error retrieving addresses: {ex.Message}");
}
}

View File

@@ -10,6 +10,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, float scoreThreshold = 0.0f, CancellationToken cancellationToken = default);
Task<List<AddressEmbedding>> GetAllAddressesAsync(CancellationToken cancellationToken = default);
}
public class QdrantService : IQdrantService
@@ -67,4 +68,22 @@ public class QdrantService : IQdrantService
Score = r.Score
}).ToList();
}
public async Task<List<AddressEmbedding>> GetAllAddressesAsync(CancellationToken cancellationToken = default)
{
var response = await _client.ScrollAsync(_collectionName, limit: 10000, cancellationToken: cancellationToken);
var addresses = new List<AddressEmbedding>();
foreach (var point in response.Result)
{
addresses.Add(new AddressEmbedding
{
Id = Guid.Parse(point.Id.Uuid),
FullAddress = point.Payload["address"].StringValue,
Vector = Array.Empty<float>(),
Score = 0f
});
}
return addresses;
}
}