split collection name

This commit is contained in:
Jicheng Lu 2024-08-07 11:50:23 -05:00
parent ac4e856f7b
commit 1ba98db5c9
9 changed files with 18 additions and 21 deletions

View file

@ -14,6 +14,6 @@ public interface IKnowledgeService
#region List
Task<KnowledgeCollectionInfo> GetKnowledgeCollectionInfo(string collectionName);
Task<StringIdPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(KnowledgeFilter filter);
Task<StringIdPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(string collectionName, KnowledgeFilter filter);
#endregion
}

View file

@ -2,9 +2,6 @@ namespace BotSharp.Abstraction.Knowledges.Models;
public class KnowledgeFilter : StringIdPagination
{
[JsonPropertyName("collection_name")]
public string CollectionName { get; set; }
[JsonPropertyName("with_vector")]
public bool WithVector { get; set; }
}

View file

@ -6,7 +6,7 @@ public interface IVectorDb
{
Task<List<string>> GetCollections();
Task<KnowledgeCollectionInfo> GetCollectionInfo(string collectionName);
Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter);
Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(string collectionName, KnowledgeFilter filter);
Task CreateCollection(string collectionName, int dim);
Task<bool> Upsert(string collectionName, string id, float[] vector, string text, Dictionary<string, string>? payload = null);
Task<List<string>> Search(string collectionName, float[] vector, string returnFieldName, int limit = 5, float confidence = 0.5f);

View file

@ -92,17 +92,17 @@ public class KnowledgeBaseController : ControllerBase
return Ok(new { count = files.Count, size });
}
[HttpGet("/knowledge/collection/info")]
public async Task<KnowledgeCollectionInfoViewModel> GetKnowledgeCollectionInfo([FromQuery] string collectionName)
[HttpGet("/knowledge/{collection}/info")]
public async Task<KnowledgeCollectionInfoViewModel> GetKnowledgeCollectionInfo([FromRoute] string collection)
{
var info = await _knowledgeService.GetKnowledgeCollectionInfo(collectionName);
var info = await _knowledgeService.GetKnowledgeCollectionInfo(collection);
return KnowledgeCollectionInfoViewModel.ToViewModel(info);
}
[HttpPost("/knowledge/collection/data")]
public async Task<StringIdPagedItems<KnowledgeCollectionDataViewModel>> GetKnowledgeCollectionData([FromBody] KnowledgeFilter filter)
{
var data = await _knowledgeService.GetKnowledgeCollectionData(filter);
[HttpPost("/knowledge/{collection}/data")]
public async Task<StringIdPagedItems<KnowledgeCollectionDataViewModel>> GetKnowledgeCollectionData([FromRoute] string collection, [FromBody] KnowledgeFilter filter)
{;
var data = await _knowledgeService.GetKnowledgeCollectionData(collection, filter);
var items = data.Items?.Select(x => KnowledgeCollectionDataViewModel.ToViewModel(x))?
.ToList() ?? new List<KnowledgeCollectionDataViewModel>();

View file

@ -32,7 +32,7 @@ public class MemVectorDatabase : IVectorDb
};
}
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(string collectionName, KnowledgeFilter filter)
{
throw new NotImplementedException();
}

View file

@ -16,12 +16,12 @@ public partial class KnowledgeService
}
}
public async Task<StringIdPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(KnowledgeFilter filter)
public async Task<StringIdPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(string collectionName, KnowledgeFilter filter)
{
try
{
var db = GetVectorDb();
return await db.GetCollectionData(filter);
return await db.GetCollectionData(collectionName, filter);
}
catch (Exception ex)
{

View file

@ -19,7 +19,7 @@ public class FaissDb : IVectorDb
throw new NotImplementedException();
}
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(string collectionName, KnowledgeFilter filter)
{
throw new NotImplementedException();
}

View file

@ -54,17 +54,17 @@ public class QdrantDb : IVectorDb
};
}
public async Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
public async Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(string collectionName, KnowledgeFilter filter)
{
var client = GetClient();
var exists = await client.CollectionExistsAsync(filter.CollectionName);
var exists = await client.CollectionExistsAsync(collectionName);
if (!exists)
{
return new StringIdPagedItems<KnowledgeCollectionData>();
}
var totalPointCount = await client.CountAsync(filter.CollectionName);
var response = await client.ScrollAsync(filter.CollectionName, limit: (uint)filter.Size,
var totalPointCount = await client.CountAsync(collectionName);
var response = await client.ScrollAsync(collectionName, limit: (uint)filter.Size,
offset: !string.IsNullOrWhiteSpace(filter.StartId) ? new PointId { Uuid = filter.StartId } : 0,
vectorsSelector: filter.WithVector);
var points = response?.Result?.Select(x => new KnowledgeCollectionData

View file

@ -24,7 +24,7 @@ namespace BotSharp.Plugin.SemanticKernel
await _memoryStore.CreateCollectionAsync(collectionName);
}
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(string collectionName, KnowledgeFilter filter)
{
throw new System.NotImplementedException();
}