diff --git a/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs b/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs index d9d5eed4..d7d9d528 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs @@ -14,10 +14,10 @@ public interface IKnowledgeService Task GetVectorCollectionDetails(string collectionName); Task> SearchVectorKnowledge(string query, string collectionName, VectorSearchOptions options); Task> GetPagedVectorCollectionData(string collectionName, VectorFilter filter); + Task> GetVectorCollectionData(string collectionName, IEnumerable ids, VectorQueryOptions? options = null); Task DeleteVectorCollectionData(string collectionName, string id); Task DeleteVectorCollectionAllData(string collectionName); Task CreateVectorCollectionData(string collectionName, VectorCreateModel create); - Task> GetVectorCollectionData(string collectionName, IEnumerable ids, VectorQueryOptions? options = null); Task UpdateVectorCollectionData(string collectionName, VectorUpdateModel update); Task UpsertVectorCollectionData(string collectionName, VectorUpdateModel update); #endregion diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs index 7c8e695e..8704f7d1 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs @@ -85,7 +85,7 @@ public partial class KnowledgeService catch (Exception ex) { _logger.LogError(ex, $"Error when getting vector db collections."); - return Enumerable.Empty(); + return []; } } @@ -176,35 +176,6 @@ public partial class KnowledgeService } } - public async Task> GetVectorCollectionData(string collectionName, IEnumerable ids, VectorQueryOptions? options = null) - { - try - { - if (string.IsNullOrWhiteSpace(collectionName) || ids.IsNullOrEmpty()) - { - return []; - } - - var pointIds = new List(); - foreach (var id in ids) - { - if (Guid.TryParse(id, out var guid)) - { - pointIds.Add(guid); - } - } - - var db = GetVectorDb(); - var points = await db.GetCollectionData(collectionName, pointIds, options); - return points; - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error when querying vector collection {collectionName} points."); - return []; - } - } - public async Task UpdateVectorCollectionData(string collectionName, VectorUpdateModel update) { @@ -328,6 +299,31 @@ public partial class KnowledgeService } } + public async Task> GetVectorCollectionData(string collectionName, IEnumerable ids, VectorQueryOptions? options = null) + { + try + { + if (string.IsNullOrWhiteSpace(collectionName) || ids.IsNullOrEmpty()) + { + return []; + } + + var pointIds = ids.Select(x => new { Id = x, IsValid = Guid.TryParse(x, out var guid), ParseResult = guid }) + .Where(x => x.IsValid) + .Select(x => x.ParseResult) + .ToList(); + + var db = GetVectorDb(); + var points = await db.GetCollectionData(collectionName, pointIds, options); + return points; + } + catch (Exception ex) + { + _logger.LogError(ex, $"Error when querying vector collection {collectionName} points."); + return []; + } + } + public async Task> SearchVectorKnowledge(string query, string collectionName, VectorSearchOptions options) { try @@ -345,7 +341,7 @@ public partial class KnowledgeService catch (Exception ex) { _logger.LogError(ex, $"Error when searching vector knowledge ({collectionName})."); - return Enumerable.Empty(); + return []; } } #endregion