feat(app): add get all addresses feature
This commit is contained in:
@@ -60,12 +60,13 @@ while (true)
|
|||||||
Console.WriteLine("Options:");
|
Console.WriteLine("Options:");
|
||||||
Console.WriteLine(" 1. Add a new address");
|
Console.WriteLine(" 1. Add a new address");
|
||||||
Console.WriteLine(" 2. Search for similar addresses");
|
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: ");
|
Console.Write("Select an option: ");
|
||||||
|
|
||||||
var option = Console.ReadLine()?.Trim();
|
var option = Console.ReadLine()?.Trim();
|
||||||
|
|
||||||
if (option?.ToLower() == "exit" || option == "3")
|
if (option?.ToLower() == "exit" || option == "4")
|
||||||
{
|
{
|
||||||
Console.WriteLine("Goodbye!");
|
Console.WriteLine("Goodbye!");
|
||||||
return;
|
return;
|
||||||
@@ -79,6 +80,9 @@ while (true)
|
|||||||
case "2":
|
case "2":
|
||||||
await SearchAddressesAsync(embeddingService, qdrantService, appConfig);
|
await SearchAddressesAsync(embeddingService, qdrantService, appConfig);
|
||||||
break;
|
break;
|
||||||
|
case "3":
|
||||||
|
await GetAllAddressesAsync(qdrantService);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("Invalid option. Please try again.");
|
Console.WriteLine("Invalid option. Please try again.");
|
||||||
break;
|
break;
|
||||||
@@ -196,4 +200,35 @@ async Task SearchAddressesAsync(IEmbeddingService embeddingService, IQdrantServi
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"Error during search: {ex.Message}");
|
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}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ public interface IQdrantService
|
|||||||
Task InitializeCollectionAsync(CancellationToken cancellationToken = default);
|
Task InitializeCollectionAsync(CancellationToken cancellationToken = default);
|
||||||
Task StoreAddressAsync(Address address, float[] embedding, 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>> SearchSimilarAddressesAsync(float[] queryEmbedding, int limit = 5, float scoreThreshold = 0.0f, CancellationToken cancellationToken = default);
|
||||||
|
Task<List<AddressEmbedding>> GetAllAddressesAsync(CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QdrantService : IQdrantService
|
public class QdrantService : IQdrantService
|
||||||
@@ -67,4 +68,22 @@ public class QdrantService : IQdrantService
|
|||||||
Score = r.Score
|
Score = r.Score
|
||||||
}).ToList();
|
}).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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user