diff --git a/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs b/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs index 2f87ac9bc..307cb57d5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs @@ -12,6 +12,7 @@ public interface IKnowledgeService Task> SearchVectorKnowledge(string query, string collectionName, VectorSearchOptions options); Task> GetPagedVectorCollectionData(string collectionName, VectorFilter filter); Task DeleteVectorCollectionData(string collectionName, string id); + Task DeleteVectorCollectionAllData(string collectionName); Task CreateVectorCollectionData(string collectionName, VectorCreateModel create); Task UpdateVectorCollectionData(string collectionName, VectorUpdateModel update); #endregion diff --git a/src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs b/src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs index 2fbc628b7..42471d42d 100644 --- a/src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs +++ b/src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs @@ -14,4 +14,5 @@ public interface IVectorDb Task Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary? payload = null); Task> Search(string collectionName, float[] vector, IEnumerable? fields, int limit = 5, float confidence = 0.5f, bool withVector = false); Task DeleteCollectionData(string collectionName, List ids); + Task DeleteCollectionAllData(string collectionName); } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBaseController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBaseController.cs index fa0df804b..0acfff2e2 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBaseController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBaseController.cs @@ -102,6 +102,12 @@ public async Task DeleteVectorCollectionData([FromRoute] string collection { return await _knowledgeService.DeleteVectorCollectionData(collection, id); } + + [HttpDelete("/knowledge/vector/{collection}/data")] + public async Task DeleteVectorCollectionAllData([FromRoute] string collection) + { + return await _knowledgeService.DeleteVectorCollectionAllData(collection); + } #endregion diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemoryVectorDb.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemoryVectorDb.cs index 61a56477f..0ba4f3e98 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemoryVectorDb.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemoryVectorDb.cs @@ -78,4 +78,9 @@ public async Task DeleteCollectionData(string collectionName, List i { return await Task.FromResult(false); } + + public async Task DeleteCollectionAllData(string collectionName) + { + return await Task.FromResult(false); + } } diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs index ffd76c35f..df9fb4abd 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Files; using BotSharp.Abstraction.VectorStorage.Enums; +using System; namespace BotSharp.Plugin.KnowledgeBase.Services; @@ -182,6 +183,21 @@ public async Task DeleteVectorCollectionData(string collectionName, string } } + + public async Task DeleteVectorCollectionAllData(string collectionName) + { + try + { + var db = GetVectorDb(); + return await db.DeleteCollectionAllData(collectionName); + } + catch (Exception ex) + { + _logger.LogWarning($"Error when deleting vector collection data ({collectionName}). {ex.Message}\r\n{ex.InnerException}"); + return false; + } + } + public async Task> GetPagedVectorCollectionData(string collectionName, VectorFilter filter) { try diff --git a/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs b/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs index bf4081d5e..f3c44ffce 100644 --- a/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs @@ -1,13 +1,10 @@ -using BotSharp.Abstraction.Knowledges.Settings; using BotSharp.Abstraction.MLTasks; using BotSharp.Abstraction.Plugins; using BotSharp.Abstraction.Settings; -using BotSharp.Abstraction.VectorStorage; using BotSharp.Plugin.MetaAI.Providers; using BotSharp.Plugin.MetaAI.Settings; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using System; namespace BotSharp.Plugin.MetaAI; @@ -32,6 +29,5 @@ public void RegisterDI(IServiceCollection services, IConfiguration config) }); services.AddSingleton(); - services.AddSingleton(); } } diff --git a/src/Plugins/BotSharp.Plugin.MetaAI/Providers/FaissDb.cs b/src/Plugins/BotSharp.Plugin.MetaAI/Providers/FaissDb.cs deleted file mode 100644 index 817deb363..000000000 --- a/src/Plugins/BotSharp.Plugin.MetaAI/Providers/FaissDb.cs +++ /dev/null @@ -1,55 +0,0 @@ -using BotSharp.Abstraction.Utilities; -using BotSharp.Abstraction.VectorStorage; -using BotSharp.Abstraction.VectorStorage.Models; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace BotSharp.Plugin.MetaAI.Providers; - -public class FaissDb : IVectorDb -{ - public string Provider => "Faiss"; - - public Task CreateCollection(string collectionName, int dimension) - { - throw new NotImplementedException(); - } - - public Task DeleteCollection(string collectionName) - { - throw new NotImplementedException(); - } - - public Task> GetPagedCollectionData(string collectionName, VectorFilter filter) - { - throw new NotImplementedException(); - } - - public Task> GetCollectionData(string collectionName, IEnumerable ids, - bool withPayload = false, bool withVector = false) - { - throw new NotImplementedException(); - } - - public Task> GetCollections() - { - throw new NotImplementedException(); - } - - public Task> Search(string collectionName, float[] vector, - IEnumerable? fields, int limit = 10, float confidence = 0.5f, bool withVector = false) - { - throw new NotImplementedException(); - } - - public Task Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary? payload = null) - { - throw new NotImplementedException(); - } - - public Task DeleteCollectionData(string collectionName, List ids) - { - throw new NotImplementedException(); - } -} diff --git a/src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs b/src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs index f2d6ff06c..5664fa402 100644 --- a/src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs +++ b/src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs @@ -1,6 +1,5 @@ using BotSharp.Abstraction.Utilities; using BotSharp.Abstraction.VectorStorage.Models; -using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.Logging; using Qdrant.Client; using Qdrant.Client.Grpc; @@ -246,10 +245,29 @@ public async Task DeleteCollectionData(string collectionName, List i if (ids.IsNullOrEmpty()) return false; var client = GetClient(); + var exist = await DoesCollectionExist(client, collectionName); + if (!exist) + { + return false; + } + var result = await client.DeleteAsync(collectionName, ids); return result.Status == UpdateStatus.Completed; } + public async Task DeleteCollectionAllData(string collectionName) + { + var client = GetClient(); + var exist = await DoesCollectionExist(client, collectionName); + if (!exist) + { + return false; + } + + var result = await client.DeleteAsync(collectionName, new Filter()); + return result.Status == UpdateStatus.Completed; + } + private async Task DoesCollectionExist(QdrantClient client, string collectionName) { diff --git a/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelMemoryStoreProvider.cs b/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelMemoryStoreProvider.cs index 3d8a8455c..bf086db9d 100644 --- a/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelMemoryStoreProvider.cs +++ b/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelMemoryStoreProvider.cs @@ -95,5 +95,10 @@ public async Task DeleteCollectionData(string collectionName, List i await _memoryStore.RemoveBatchAsync(collectionName, ids.Select(x => x.ToString())); return true; } + + public async Task DeleteCollectionAllData(string collectionName) + { + return await Task.FromResult(false); + } } }