From 12fd2ef45e752131687f4a4c38eecf820896bd58 Mon Sep 17 00:00:00 2001 From: vidane Date: Wed, 14 Jan 2026 17:50:00 -0500 Subject: [PATCH] feat(app): add get all addresses feature --- VectorSearchApp/Program.cs | 39 +++++++++++++++++++++-- VectorSearchApp/Services/QdrantService.cs | 19 +++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/VectorSearchApp/Program.cs b/VectorSearchApp/Program.cs index 9b72bc9..fa362ac 100644 --- a/VectorSearchApp/Program.cs +++ b/VectorSearchApp/Program.cs @@ -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; @@ -196,4 +200,35 @@ 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}"); + } } \ No newline at end of file diff --git a/VectorSearchApp/Services/QdrantService.cs b/VectorSearchApp/Services/QdrantService.cs index d257a7f..154aac1 100644 --- a/VectorSearchApp/Services/QdrantService.cs +++ b/VectorSearchApp/Services/QdrantService.cs @@ -10,6 +10,7 @@ public interface IQdrantService Task InitializeCollectionAsync(CancellationToken cancellationToken = default); Task StoreAddressAsync(Address address, float[] embedding, CancellationToken cancellationToken = default); Task> SearchSimilarAddressesAsync(float[] queryEmbedding, int limit = 5, float scoreThreshold = 0.0f, CancellationToken cancellationToken = default); + Task> GetAllAddressesAsync(CancellationToken cancellationToken = default); } public class QdrantService : IQdrantService @@ -67,4 +68,22 @@ public class QdrantService : IQdrantService Score = r.Score }).ToList(); } + + public async Task> GetAllAddressesAsync(CancellationToken cancellationToken = default) + { + var response = await _client.ScrollAsync(_collectionName, limit: 10000, cancellationToken: cancellationToken); + + var addresses = new List(); + foreach (var point in response.Result) + { + addresses.Add(new AddressEmbedding + { + Id = Guid.Parse(point.Id.Uuid), + FullAddress = point.Payload["address"].StringValue, + Vector = Array.Empty(), + Score = 0f + }); + } + return addresses; + } } \ No newline at end of file