Skip to content

Commit af48457

Browse files
committed
Support more data type in Qdrant payload.
1 parent 08d1a40 commit af48457

File tree

13 files changed

+76
-22
lines changed

13 files changed

+76
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IVectorDb
1212
Task<IEnumerable<VectorCollectionData>> GetCollectionData(string collectionName, IEnumerable<Guid> ids, bool withPayload = false, bool withVector = false);
1313
Task<bool> CreateCollection(string collectionName, int dimension);
1414
Task<bool> DeleteCollection(string collectionName);
15-
Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, string>? payload = null);
15+
Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, object>? payload = null);
1616
Task<IEnumerable<VectorCollectionData>> Search(string collectionName, float[] vector, IEnumerable<string>? fields, int limit = 5, float confidence = 0.5f, bool withVector = false);
1717
Task<bool> DeleteCollectionData(string collectionName, List<Guid> ids);
1818
Task<bool> DeleteCollectionAllData(string collectionName);

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCollectionData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace BotSharp.Abstraction.VectorStorage.Models;
33
public class VectorCollectionData
44
{
55
public string Id { get; set; }
6-
public Dictionary<string, string> Data { get; set; } = new();
6+
public Dictionary<string, object> Data { get; set; } = new();
77
public double? Score { get; set; }
88

99
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCreateModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public class VectorCreateModel
66
{
77
public string Text { get; set; }
88
public string DataSource { get; set; } = VectorDataSource.Api;
9-
public Dictionary<string, string>? Payload { get; set; }
9+
public Dictionary<string, object>? Payload { get; set; }
1010
}

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/VectorKnowledgeCreateRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public class VectorKnowledgeCreateRequest
1111
public string DataSource { get; set; } = VectorDataSource.Api;
1212

1313
[JsonPropertyName("payload")]
14-
public Dictionary<string, string>? Payload { get; set; }
14+
public Dictionary<string, object>? Payload { get; set; }
1515
}

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/VectorKnowledgeViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class VectorKnowledgeViewModel
99
public string Id { get; set; }
1010

1111
[JsonPropertyName("data")]
12-
public IDictionary<string, string> Data { get; set; }
12+
public IDictionary<string, object> Data { get; set; }
1313

1414
[JsonPropertyName("score")]
1515
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task<bool> Execute(RoleDialogModel message)
2424
var result = await knowledgeService.CreateVectorCollectionData(collectionName, new VectorCreateModel
2525
{
2626
Text = args.Question,
27-
Payload = new Dictionary<string, string>
27+
Payload = new Dictionary<string, object>
2828
{
2929
{ KnowledgePayloadName.Answer, args.Answer }
3030
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public async Task<IEnumerable<VectorCollectionData>> Search(string collectionNam
5959
.Take(limit)
6060
.Select(i => new VectorCollectionData
6161
{
62-
Data = new Dictionary<string, string> { { "text", _vectors[collectionName][i].Text } },
62+
Data = new Dictionary<string, object> { { "text", _vectors[collectionName][i].Text } },
6363
Score = similarities[i],
6464
Vector = withVector ? _vectors[collectionName][i].Vector : null,
6565
})
@@ -68,7 +68,7 @@ public async Task<IEnumerable<VectorCollectionData>> Search(string collectionNam
6868
return await Task.FromResult(results);
6969
}
7070

71-
public async Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, string>? payload = null)
71+
public async Task<bool> Upsert(string collectionName, Guid id, float[] vector, string text, Dictionary<string, object>? payload = null)
7272
{
7373
_vectors[collectionName].Add(new VecRecord
7474
{

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Document.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private async Task<IEnumerable<string>> SaveToVectorDb(
398398
var vectorDb = GetVectorDb();
399399
var textEmbedding = GetTextEmbedding(collectionName);
400400

401-
var payload = new Dictionary<string, string>
401+
var payload = new Dictionary<string, object>
402402
{
403403
{ KnowledgePayloadName.DataSource, vectorDataSource },
404404
{ KnowledgePayloadName.FileId, fileId.ToString() },

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public async Task<bool> UpsertVectorCollectionData(string collectionName, Vector
196196
withPayload: true);
197197
if (!found.IsNullOrEmpty())
198198
{
199-
if (found.First().Data["text"] == update.Text)
199+
if (found.First().Data["text"].ToString() == update.Text)
200200
{
201201
// Only update payload
202202
return await db.Upsert(collectionName, guid, found.First().Vector, update.Text, update.Payload);

src/Plugins/BotSharp.Plugin.Planner/Functions/PrimaryStagePlanFn.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,31 @@ public async Task<bool> Execute(RoleDialogModel message)
1919
{
2020
var agentService = _services.GetRequiredService<IAgentService>();
2121
var state = _services.GetRequiredService<IConversationStateService>();
22-
var knowledgeService = _services.GetRequiredService<IKnowledgeService>();
23-
var knowledgeSettings = _services.GetRequiredService<KnowledgeBaseSettings>();
22+
// var knowledgeService = _services.GetRequiredService<IKnowledgeService>();
23+
// var knowledgeSettings = _services.GetRequiredService<KnowledgeBaseSettings>();
2424

2525
state.SetState("max_tokens", "4096");
2626
var task = JsonSerializer.Deserialize<PrimaryRequirementRequest>(message.FunctionArgs);
27-
var collectionName = knowledgeSettings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp;
27+
// var collectionName = knowledgeSettings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp;
2828

2929
// Get knowledge from vectordb
3030
var hooks = _services.GetServices<IKnowledgeHook>();
3131
var knowledges = new List<string>();
3232
foreach (var question in task.Questions)
3333
{
34-
var list = await knowledgeService.SearchVectorKnowledge(question, collectionName, new VectorSearchOptions
34+
/*var list = await knowledgeService.SearchVectorKnowledge(question, collectionName, new VectorSearchOptions
3535
{
3636
Confidence = 0.4f
3737
});
38-
knowledges.Add(string.Join("\r\n\r\n=====\r\n", list.Select(x => x.ToQuestionAnswer())));
38+
knowledges.Add(string.Join("\r\n\r\n=====\r\n", list.Select(x => x.ToQuestionAnswer())));*/
3939

4040
foreach (var hook in hooks)
4141
{
4242
var k = await hook.GetRelevantKnowledges(question);
4343
knowledges.AddRange(k);
4444
}
4545
}
46+
knowledges = knowledges.Distinct().ToList();
4647

4748
// Get first stage planning prompt
4849
var currentAgent = await agentService.LoadAgent(message.CurrentAgentId);

0 commit comments

Comments
 (0)