BotSharp/src/Infrastructure/BotSharp.Core/Knowledges/Services/KnowledgeService.Update.cs

34 lines
1.1 KiB
C#
Raw Normal View History

2024-08-31 05:57:49 +00:00
using BotSharp.Abstraction.VectorStorage.Models;
namespace BotSharp.Core.Knowledges.Services;
2024-08-23 03:13:40 +00:00
public partial class KnowledgeService
{
public async Task<bool> UpdateVectorCollectionData(string collectionName, VectorUpdateModel update)
{
try
{
if (string.IsNullOrWhiteSpace(collectionName) || string.IsNullOrWhiteSpace(update.Text) || !Guid.TryParse(update.Id, out var guid))
{
return false;
}
2024-08-23 16:25:44 +00:00
var db = GetVectorDb();
var found = await db.GetCollectionData(collectionName, new List<Guid> { guid });
if (found.IsNullOrEmpty())
{
return false;
}
2024-08-23 03:13:40 +00:00
var textEmbedding = GetTextEmbedding(collectionName);
var vector = await textEmbedding.GetVectorAsync(update.Text);
return await db.Upsert(collectionName, guid, vector, update.Text, update.Payload);
}
catch (Exception ex)
{
_logger.LogWarning($"Error when updating vector collection data. {ex.Message}\r\n{ex.InnerException}");
return false;
}
}
}