Skip to content

Commit f6eb4bd

Browse files
authored
Merge pull request #594 from iceljc/master
add default collection
2 parents e6b54c6 + 548cd55 commit f6eb4bd

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

src/Infrastructure/BotSharp.Abstraction/Knowledges/Settings/KnowledgeBaseSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using BotSharp.Abstraction.Knowledges.Enums;
2+
13
namespace BotSharp.Abstraction.Knowledges.Settings;
24

35
public class KnowledgeBaseSettings
46
{
57
public string VectorDb { get; set; }
8+
public string DefaultCollection { get; set; } = KnowledgeCollectionName.BotSharp;
69
public KnowledgeModelSetting TextEmbedding { get; set; }
710
}
811

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private void UpdateAgentAllFields(Agent inputAgent)
298298
var json = JsonSerializer.Serialize(agent, _options);
299299
File.WriteAllText(agentFile, json);
300300

301-
UpdateAgentInstructions(inputAgent.Id, inputAgent.Instruction, agent.ChannelInstructions);
301+
UpdateAgentInstructions(inputAgent.Id, inputAgent.Instruction, inputAgent.ChannelInstructions);
302302
UpdateAgentResponses(inputAgent.Id, inputAgent.Responses);
303303
UpdateAgentTemplates(inputAgent.Id, inputAgent.Templates);
304304
UpdateAgentFunctions(inputAgent.Id, inputAgent.Functions);

src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/KnowledgeRetrievalFn.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public async Task<bool> Execute(RoleDialogModel message)
2222

2323
var vector = await embedding.GetVectorAsync(args.Question);
2424
var vectorDb = _services.GetServices<IVectorDb>().FirstOrDefault(x => x.Name == _settings.VectorDb);
25-
var knowledges = await vectorDb.Search(KnowledgeCollectionName.BotSharp, vector, new List<string> { KnowledgePayloadName.Answer });
25+
var collectionName = !string.IsNullOrWhiteSpace(_settings.DefaultCollection) ? _settings.DefaultCollection : KnowledgeCollectionName.BotSharp;
26+
var knowledges = await vectorDb.Search(collectionName, vector, new List<string> { KnowledgePayloadName.Answer });
2627

2728
if (!knowledges.IsNullOrEmpty())
2829
{

src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/MemorizeKnowledgeFn.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public async Task<bool> Execute(RoleDialogModel message)
2626
});
2727

2828
var vectorDb = _services.GetServices<IVectorDb>().FirstOrDefault(x => x.Name == _settings.VectorDb);
29-
await vectorDb.CreateCollection(KnowledgeCollectionName.BotSharp, vector[0].Length);
29+
var collectionName = !string.IsNullOrWhiteSpace(_settings.DefaultCollection) ? _settings.DefaultCollection : KnowledgeCollectionName.BotSharp;
30+
await vectorDb.CreateCollection(collectionName, vector[0].Length);
3031

3132
var id = Guid.NewGuid().ToString();
32-
var result = await vectorDb.Upsert(KnowledgeCollectionName.BotSharp, id, vector[0],
33+
var result = await vectorDb.Upsert(collectionName, id, vector[0],
3334
args.Question,
3435
new Dictionary<string, string>
3536
{

src/WebStarter/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259

260260
"KnowledgeBase": {
261261
"VectorDb": "Qdrant",
262+
"DefaultCollection": "BotSharp",
262263
"TextEmbedding": {
263264
"Provider": "openai",
264265
"Model": "text-embedding-3-small"

0 commit comments

Comments
 (0)