rename
This commit is contained in:
parent
6ab7c02545
commit
ba9180120d
|
|
@ -14,6 +14,6 @@ public interface IKnowledgeService
|
|||
|
||||
#region List
|
||||
Task<KnowledgeCollectionInfo> GetKnowledgeCollectionInfo(string collectionName);
|
||||
Task<UuidPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(KnowledgeFilter filter);
|
||||
Task<StringIdPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(KnowledgeFilter filter);
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ namespace BotSharp.Abstraction.Knowledges.Models;
|
|||
public class KnowledgeCollectionData
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Text { get; set; }
|
||||
public string Question { get; set; }
|
||||
public string Answer { get; set; }
|
||||
public float[]? Vector { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
namespace BotSharp.Abstraction.Knowledges.Models;
|
||||
|
||||
public class KnowledgeFilter : UuidPagination
|
||||
public class KnowledgeFilter : StringIdPagination
|
||||
{
|
||||
[JsonPropertyName("collection_name")]
|
||||
public string CollectionName { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
namespace BotSharp.Abstraction.Utilities;
|
||||
|
||||
public class UuidPagination : Pagination
|
||||
public class StringIdPagination : Pagination
|
||||
{
|
||||
[JsonPropertyName("start_id")]
|
||||
public string? StartId { get; set; }
|
||||
}
|
||||
|
||||
public class UuidPagedItems<T> : PagedItems<T>
|
||||
public class StringIdPagedItems<T> : PagedItems<T>
|
||||
{
|
||||
public new ulong Count { get; set; }
|
||||
|
||||
|
|
@ -6,7 +6,7 @@ public interface IVectorDb
|
|||
{
|
||||
Task<List<string>> GetCollections();
|
||||
Task<KnowledgeCollectionInfo> GetCollectionInfo(string collectionName);
|
||||
Task<UuidPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter);
|
||||
Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(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);
|
||||
|
|
|
|||
|
|
@ -100,13 +100,13 @@ public class KnowledgeBaseController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/knowledge/collection/data")]
|
||||
public async Task<UuidPagedItems<KnowledgeCollectionDataViewModel>> GetKnowledgeCollectionData([FromBody] KnowledgeFilter filter)
|
||||
public async Task<StringIdPagedItems<KnowledgeCollectionDataViewModel>> GetKnowledgeCollectionData([FromBody] KnowledgeFilter filter)
|
||||
{
|
||||
var data = await _knowledgeService.GetKnowledgeCollectionData(filter);
|
||||
var items = data.Items?.Select(x => KnowledgeCollectionDataViewModel.ToViewModel(x))?
|
||||
.ToList() ?? new List<KnowledgeCollectionDataViewModel>();
|
||||
|
||||
return new UuidPagedItems<KnowledgeCollectionDataViewModel>
|
||||
return new StringIdPagedItems<KnowledgeCollectionDataViewModel>
|
||||
{
|
||||
Count = data.Count,
|
||||
NextId = data.NextId,
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ public class KnowledgeCollectionDataViewModel
|
|||
[JsonPropertyName("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonPropertyName("text")]
|
||||
public string Text { get; set; }
|
||||
[JsonPropertyName("question")]
|
||||
public string Question { get; set; }
|
||||
|
||||
[JsonPropertyName("answer")]
|
||||
public string Answer { get; set; }
|
||||
|
|
@ -23,7 +23,7 @@ public class KnowledgeCollectionDataViewModel
|
|||
return new KnowledgeCollectionDataViewModel
|
||||
{
|
||||
Id = data.Id,
|
||||
Text = data.Text,
|
||||
Question = data.Question,
|
||||
Answer = data.Answer,
|
||||
Vector = data.Vector
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class MemVectorDatabase : IVectorDb
|
|||
};
|
||||
}
|
||||
|
||||
public Task<UuidPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
|
||||
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public partial class KnowledgeService
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<UuidPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(KnowledgeFilter filter)
|
||||
public async Task<StringIdPagedItems<KnowledgeCollectionData>> GetKnowledgeCollectionData(KnowledgeFilter filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ public partial class KnowledgeService
|
|||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Error when getting knowledge collectio data. {ex.Message}\r\n{ex.InnerException}");
|
||||
return new UuidPagedItems<KnowledgeCollectionData>();
|
||||
return new StringIdPagedItems<KnowledgeCollectionData>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class FaissDb : IVectorDb
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<UuidPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
|
||||
public Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,13 +54,13 @@ public class QdrantDb : IVectorDb
|
|||
};
|
||||
}
|
||||
|
||||
public async Task<UuidPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
|
||||
public async Task<StringIdPagedItems<KnowledgeCollectionData>> GetCollectionData(KnowledgeFilter filter)
|
||||
{
|
||||
var client = GetClient();
|
||||
var exists = await client.CollectionExistsAsync(filter.CollectionName);
|
||||
if (!exists)
|
||||
{
|
||||
return new UuidPagedItems<KnowledgeCollectionData>();
|
||||
return new StringIdPagedItems<KnowledgeCollectionData>();
|
||||
}
|
||||
|
||||
var totalPointCount = await client.CountAsync(filter.CollectionName);
|
||||
|
|
@ -70,12 +70,12 @@ public class QdrantDb : IVectorDb
|
|||
var points = response?.Result?.Select(x => new KnowledgeCollectionData
|
||||
{
|
||||
Id = x.Id?.Uuid ?? string.Empty,
|
||||
Text = x.Payload.ContainsKey(KnowledgePayloadName.Text) ? x.Payload[KnowledgePayloadName.Text].StringValue : string.Empty,
|
||||
Question = x.Payload.ContainsKey(KnowledgePayloadName.Text) ? x.Payload[KnowledgePayloadName.Text].StringValue : string.Empty,
|
||||
Answer = x.Payload.ContainsKey(KnowledgePayloadName.Answer) ? x.Payload[KnowledgePayloadName.Answer].StringValue : string.Empty,
|
||||
Vector = filter.WithVector ? x.Vectors?.Vector?.Data?.ToArray() : null
|
||||
})?.ToList() ?? new List<KnowledgeCollectionData>();
|
||||
|
||||
return new UuidPagedItems<KnowledgeCollectionData>
|
||||
return new StringIdPagedItems<KnowledgeCollectionData>
|
||||
{
|
||||
Count = totalPointCount,
|
||||
NextId = response?.NextPageOffset?.Uuid,
|
||||
|
|
|
|||
Loading…
Reference in a new issue