Added ability to remove all records from the database.
This commit is contained in:
@@ -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;
|
||||
@@ -232,3 +236,31 @@ 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}");
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public interface IQdrantService
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user