diff --git a/VectorSearchApp/Program.cs b/VectorSearchApp/Program.cs index fa362ac..1c72b34 100644 --- a/VectorSearchApp/Program.cs +++ b/VectorSearchApp/Program.cs @@ -62,6 +62,7 @@ while (true) Console.WriteLine(" 2. Search for similar addresses"); Console.WriteLine(" 3. Get all addresses"); Console.WriteLine(" 4. Exit"); + Console.WriteLine(" 5. Delete all records"); Console.Write("Select an option: "); var option = Console.ReadLine()?.Trim(); @@ -83,6 +84,9 @@ while (true) case "3": await GetAllAddressesAsync(qdrantService); break; + case "5": + await DeleteAllAddressesAsync(qdrantService); + break; default: Console.WriteLine("Invalid option. Please try again."); break; @@ -231,4 +235,32 @@ async Task GetAllAddressesAsync(IQdrantService? qdrantService) { Console.WriteLine($"Error retrieving addresses: {ex.Message}"); } +} + +async Task DeleteAllAddressesAsync(IQdrantService? qdrantService) +{ + if (qdrantService == null) + { + Console.WriteLine("Deleting all records is not available because Qdrant is not connected."); + return; + } + + Console.Write("Are you sure you want to delete ALL records? This cannot be undone. (yes/no): "); + var confirmation = Console.ReadLine()?.Trim().ToLower(); + + if (confirmation != "yes") + { + Console.WriteLine("Deletion cancelled."); + return; + } + + try + { + await qdrantService.DeleteAllAddressesAsync(); + Console.WriteLine("All records have been deleted successfully."); + } + catch (Exception ex) + { + Console.WriteLine($"Error deleting records: {ex.Message}"); + } } \ No newline at end of file diff --git a/VectorSearchApp/Services/QdrantService.cs b/VectorSearchApp/Services/QdrantService.cs index 154aac1..e1ab684 100644 --- a/VectorSearchApp/Services/QdrantService.cs +++ b/VectorSearchApp/Services/QdrantService.cs @@ -11,6 +11,7 @@ public interface IQdrantService 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); + Task DeleteAllAddressesAsync(CancellationToken cancellationToken = default); } public class QdrantService : IQdrantService @@ -86,4 +87,9 @@ public class QdrantService : IQdrantService } return addresses; } + + public async Task DeleteAllAddressesAsync(CancellationToken cancellationToken = default) + { + await _client.DeleteAsync(_collectionName, filter: new Filter(), cancellationToken: cancellationToken); + } } \ No newline at end of file