Merge pull request #649 from iceljc/features/add-knowledge-docs · SciSharp/BotSharp@0f37ef8 · GitHub
Skip to content

Commit 0f37ef8

Browse files
authored
Merge pull request #649 from iceljc/features/add-knowledge-docs
delete all points in a collection
2 parents f73d734 + 3926c39 commit 0f37ef8

9 files changed

Lines changed: 53 additions & 60 deletions

File tree

‎src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs‎

Lines changed: 1 addition & 0 deletions

‎src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public interface IVectorDb
1414
Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, string>? payload = null);
1515
Task<IEnumerable<VectorCollectionData>> Search(string collectionName, float[] vector, IEnumerable<string>? fields, int limit = 5, float confidence = 0.5f, bool withVector = false);
1616
Task<bool> DeleteCollectionData(string collectionName, List<Guid> ids);
17+
Task<bool> DeleteCollectionAllData(string collectionName);
1718
}

‎src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBaseController.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public async Task<bool> DeleteVectorCollectionData([FromRoute] string collection
102102
{
103103
return await _knowledgeService.DeleteVectorCollectionData(collection, id);
104104
}
105+
106+
[HttpDelete("/knowledge/vector/{collection}/data")]
107+
public async Task<bool> DeleteVectorCollectionAllData([FromRoute] string collection)
108+
{
109+
return await _knowledgeService.DeleteVectorCollectionAllData(collection);
110+
}
105111
#endregion
106112

107113

‎src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemoryVectorDb.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ public async Task<bool> DeleteCollectionData(string collectionName, List<Guid> i
7878
{
7979
return await Task.FromResult(false);
8080
}
81+
82+
public async Task<bool> DeleteCollectionAllData(string collectionName)
83+
{
84+
return await Task.FromResult(false);
85+
}
8186
}

‎src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BotSharp.Abstraction.Files;
22
using BotSharp.Abstraction.VectorStorage.Enums;
3+
using System;
34

45
namespace BotSharp.Plugin.KnowledgeBase.Services;
56

@@ -182,6 +183,21 @@ public async Task<bool> DeleteVectorCollectionData(string collectionName, string
182183
}
183184
}
184185

186+
187+
public async Task<bool> DeleteVectorCollectionAllData(string collectionName)
188+
{
189+
try
190+
{
191+
var db = GetVectorDb();
192+
return await db.DeleteCollectionAllData(collectionName);
193+
}
194+
catch (Exception ex)
195+
{
196+
_logger.LogWarning($"Error when deleting vector collection data ({collectionName}). {ex.Message}\r\n{ex.InnerException}");
197+
return false;
198+
}
199+
}
200+
185201
public async Task<StringIdPagedItems<VectorSearchResult>> GetPagedVectorCollectionData(string collectionName, VectorFilter filter)
186202
{
187203
try

‎src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using BotSharp.Abstraction.Knowledges.Settings;
21
using BotSharp.Abstraction.MLTasks;
32
using BotSharp.Abstraction.Plugins;
43
using BotSharp.Abstraction.Settings;
5-
using BotSharp.Abstraction.VectorStorage;
64
using BotSharp.Plugin.MetaAI.Providers;
75
using BotSharp.Plugin.MetaAI.Settings;
86
using Microsoft.Extensions.Configuration;
97
using Microsoft.Extensions.DependencyInjection;
10-
using System;
118

129
namespace BotSharp.Plugin.MetaAI;
1310

@@ -32,6 +29,5 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
3229
});
3330

3431
services.AddSingleton<ITextEmbedding, fastTextEmbeddingProvider>();
35-
services.AddSingleton<IVectorDb, FaissDb>();
3632
}
3733
}

‎src/Plugins/BotSharp.Plugin.MetaAI/Providers/FaissDb.cs‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using BotSharp.Abstraction.Utilities;
22
using BotSharp.Abstraction.VectorStorage.Models;
3-
using Google.Protobuf.WellKnownTypes;
43
using Microsoft.Extensions.Logging;
54
using Qdrant.Client;
65
using Qdrant.Client.Grpc;
@@ -246,10 +245,29 @@ public async Task<bool> DeleteCollectionData(string collectionName, List<Guid> i
246245
if (ids.IsNullOrEmpty()) return false;
247246

248247
var client = GetClient();
248+
var exist = await DoesCollectionExist(client, collectionName);
249+
if (!exist)
250+
{
251+
return false;
252+
}
253+
249254
var result = await client.DeleteAsync(collectionName, ids);
250255
return result.Status == UpdateStatus.Completed;
251256
}
252257

258+
public async Task<bool> DeleteCollectionAllData(string collectionName)
259+
{
260+
var client = GetClient();
261+
var exist = await DoesCollectionExist(client, collectionName);
262+
if (!exist)
263+
{
264+
return false;
265+
}
266+
267+
var result = await client.DeleteAsync(collectionName, new Filter());
268+
return result.Status == UpdateStatus.Completed;
269+
}
270+
253271

254272
private async Task<bool> DoesCollectionExist(QdrantClient client, string collectionName)
255273
{

‎src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelMemoryStoreProvider.cs‎

Lines changed: 5 additions & 0 deletions

0 commit comments

Comments
 (0)