add default collection

This commit is contained in:
Jicheng Lu 2024-08-14 16:56:32 -05:00
parent e6b54c6ed3
commit 548cd558c0
5 changed files with 10 additions and 4 deletions

View file

@ -1,8 +1,11 @@
using BotSharp.Abstraction.Knowledges.Enums;
namespace BotSharp.Abstraction.Knowledges.Settings;
public class KnowledgeBaseSettings
{
public string VectorDb { get; set; }
public string DefaultCollection { get; set; } = KnowledgeCollectionName.BotSharp;
public KnowledgeModelSetting TextEmbedding { get; set; }
}

View file

@ -298,7 +298,7 @@ namespace BotSharp.Core.Repository
var json = JsonSerializer.Serialize(agent, _options);
File.WriteAllText(agentFile, json);
UpdateAgentInstructions(inputAgent.Id, inputAgent.Instruction, agent.ChannelInstructions);
UpdateAgentInstructions(inputAgent.Id, inputAgent.Instruction, inputAgent.ChannelInstructions);
UpdateAgentResponses(inputAgent.Id, inputAgent.Responses);
UpdateAgentTemplates(inputAgent.Id, inputAgent.Templates);
UpdateAgentFunctions(inputAgent.Id, inputAgent.Functions);

View file

@ -22,7 +22,8 @@ public class KnowledgeRetrievalFn : IFunctionCallback
var vector = await embedding.GetVectorAsync(args.Question);
var vectorDb = _services.GetServices<IVectorDb>().FirstOrDefault(x => x.Name == _settings.VectorDb);
var knowledges = await vectorDb.Search(KnowledgeCollectionName.BotSharp, vector, new List<string> { KnowledgePayloadName.Answer });
var collectionName = !string.IsNullOrWhiteSpace(_settings.DefaultCollection) ? _settings.DefaultCollection : KnowledgeCollectionName.BotSharp;
var knowledges = await vectorDb.Search(collectionName, vector, new List<string> { KnowledgePayloadName.Answer });
if (!knowledges.IsNullOrEmpty())
{

View file

@ -26,10 +26,11 @@ public class MemorizeKnowledgeFn : IFunctionCallback
});
var vectorDb = _services.GetServices<IVectorDb>().FirstOrDefault(x => x.Name == _settings.VectorDb);
await vectorDb.CreateCollection(KnowledgeCollectionName.BotSharp, vector[0].Length);
var collectionName = !string.IsNullOrWhiteSpace(_settings.DefaultCollection) ? _settings.DefaultCollection : KnowledgeCollectionName.BotSharp;
await vectorDb.CreateCollection(collectionName, vector[0].Length);
var id = Guid.NewGuid().ToString();
var result = await vectorDb.Upsert(KnowledgeCollectionName.BotSharp, id, vector[0],
var result = await vectorDb.Upsert(collectionName, id, vector[0],
args.Question,
new Dictionary<string, string>
{

View file

@ -259,6 +259,7 @@
"KnowledgeBase": {
"VectorDb": "Qdrant",
"DefaultCollection": "BotSharp",
"TextEmbedding": {
"Provider": "openai",
"Model": "text-embedding-3-small"