refine code
This commit is contained in:
parent
6e5689b640
commit
0c064cd8b4
|
|
@ -14,10 +14,10 @@ public interface IKnowledgeService
|
|||
Task<VectorCollectionDetails?> GetVectorCollectionDetails(string collectionName);
|
||||
Task<IEnumerable<VectorSearchResult>> SearchVectorKnowledge(string query, string collectionName, VectorSearchOptions options);
|
||||
Task<StringIdPagedItems<VectorSearchResult>> GetPagedVectorCollectionData(string collectionName, VectorFilter filter);
|
||||
Task<IEnumerable<VectorCollectionData>> GetVectorCollectionData(string collectionName, IEnumerable<string> ids, VectorQueryOptions? options = null);
|
||||
Task<bool> DeleteVectorCollectionData(string collectionName, string id);
|
||||
Task<bool> DeleteVectorCollectionAllData(string collectionName);
|
||||
Task<bool> CreateVectorCollectionData(string collectionName, VectorCreateModel create);
|
||||
Task<IEnumerable<VectorCollectionData>> GetVectorCollectionData(string collectionName, IEnumerable<string> ids, VectorQueryOptions? options = null);
|
||||
Task<bool> UpdateVectorCollectionData(string collectionName, VectorUpdateModel update);
|
||||
Task<bool> UpsertVectorCollectionData(string collectionName, VectorUpdateModel update);
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public partial class KnowledgeService
|
|||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error when getting vector db collections.");
|
||||
return Enumerable.Empty<VectorCollectionConfig>();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -176,35 +176,6 @@ public partial class KnowledgeService
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<VectorCollectionData>> GetVectorCollectionData(string collectionName, IEnumerable<string> ids, VectorQueryOptions? options = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(collectionName) || ids.IsNullOrEmpty())
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var pointIds = new List<Guid>();
|
||||
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<bool> UpdateVectorCollectionData(string collectionName, VectorUpdateModel update)
|
||||
{
|
||||
|
|
@ -328,6 +299,31 @@ public partial class KnowledgeService
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<VectorCollectionData>> GetVectorCollectionData(string collectionName, IEnumerable<string> 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<IEnumerable<VectorSearchResult>> 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<VectorSearchResult>();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
|
|
|||
Loading…
Reference in a new issue