Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IKnowledgeService
Task<IEnumerable<VectorSearchResult>> SearchVectorKnowledge(string query, string collectionName, VectorSearchOptions options);
Task<StringIdPagedItems<VectorSearchResult>> GetPagedVectorCollectionData(string collectionName, VectorFilter filter);
Task<bool> DeleteVectorCollectionData(string collectionName, string id);
Task<bool> DeleteVectorCollectionAllData(string collectionName);
Task<bool> CreateVectorCollectionData(string collectionName, VectorCreateModel create);
Task<bool> UpdateVectorCollectionData(string collectionName, VectorUpdateModel update);
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public interface IVectorDb
Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, string>? payload = null);
Task<IEnumerable<VectorCollectionData>> Search(string collectionName, float[] vector, IEnumerable<string>? fields, int limit = 5, float confidence = 0.5f, bool withVector = false);
Task<bool> DeleteCollectionData(string collectionName, List<Guid> ids);
Task<bool> DeleteCollectionAllData(string collectionName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public async Task<bool> DeleteVectorCollectionData([FromRoute] string collection
{
return await _knowledgeService.DeleteVectorCollectionData(collection, id);
}

[HttpDelete("/knowledge/vector/{collection}/data")]
public async Task<bool> DeleteVectorCollectionAllData([FromRoute] string collection)
{
return await _knowledgeService.DeleteVectorCollectionAllData(collection);
}
#endregion


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public async Task<bool> DeleteCollectionData(string collectionName, List<Guid> i
{
return await Task.FromResult(false);
}

public async Task<bool> DeleteCollectionAllData(string collectionName)
{
return await Task.FromResult(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BotSharp.Abstraction.Files;
using BotSharp.Abstraction.VectorStorage.Enums;
using System;

namespace BotSharp.Plugin.KnowledgeBase.Services;

Expand Down Expand Up @@ -182,6 +183,21 @@ public async Task<bool> DeleteVectorCollectionData(string collectionName, string
}
}


public async Task<bool> 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<StringIdPagedItems<VectorSearchResult>> GetPagedVectorCollectionData(string collectionName, VectorFilter filter)
{
try
Expand Down
4 changes: 0 additions & 4 deletions src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs
Original file line number Diff line number Diff line change
@@ -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;

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

services.AddSingleton<ITextEmbedding, fastTextEmbeddingProvider>();
services.AddSingleton<IVectorDb, FaissDb>();
}
}
55 changes: 0 additions & 55 deletions src/Plugins/BotSharp.Plugin.MetaAI/Providers/FaissDb.cs

This file was deleted.

20 changes: 19 additions & 1 deletion src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -246,10 +245,29 @@ public async Task<bool> DeleteCollectionData(string collectionName, List<Guid> 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<bool> 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<bool> DoesCollectionExist(QdrantClient client, string collectionName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,10 @@ public async Task<bool> DeleteCollectionData(string collectionName, List<Guid> i
await _memoryStore.RemoveBatchAsync(collectionName, ids.Select(x => x.ToString()));
return true;
}

public async Task<bool> DeleteCollectionAllData(string collectionName)
{
return await Task.FromResult(false);
}
}
}