115 lines
3.3 KiB
C#
115 lines
3.3 KiB
C#
using System.Linq;
|
|
using System.Threading;
|
|
using xCommons.Extensions;
|
|
using xAiModels.Extensions;
|
|
using xAiModels.Models.Dtos;
|
|
using System.Threading.Tasks;
|
|
using xAiModels.Models.Entities;
|
|
using System.Collections.Generic;
|
|
using xAiModels.Interfaces.Enrichers;
|
|
|
|
namespace xAiModels.Providers.Enrichers
|
|
{
|
|
public class XAiVectorEnricher : IXAiVectorEnricher
|
|
{
|
|
public XAiVectorEnricher()
|
|
{ }
|
|
|
|
//
|
|
#region Enrichers ...
|
|
/// <summary>
|
|
/// Enrich Specified Item ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XAiVectorDto> Enrich(
|
|
XAiVector source,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Mapping Default ...
|
|
var result = source.MapConvert<XAiVectorDto, XAiVector>();
|
|
|
|
//
|
|
// Here we Converts Embeddings ...
|
|
result.Metadata = source.Metadata.AsMetadat();
|
|
result.Embedding = source.Embedding.AsEmbedding();
|
|
|
|
//
|
|
result = await Enrich(
|
|
source: result,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enrich Specified Item ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XAiVectorDto> Enrich(
|
|
XAiVectorDto source,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Currently no additional enrichment needed for XAiVector
|
|
// This can be extended in the future if needed
|
|
return await Task.FromResult(source);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enrich Specified Items ...
|
|
/// </summary>
|
|
/// <param name="sources"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
|
IEnumerable<XAiVector> sources,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var tasks = sources
|
|
.Select(x => Enrich(
|
|
source: x,
|
|
cancellationToken: cancellationToken
|
|
));
|
|
|
|
//
|
|
var result = await Task.WhenAll(tasks);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enrich Specified Items ...
|
|
/// </summary>
|
|
/// <param name="sources"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
|
IEnumerable<XAiVectorDto> sources,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var tasks = sources
|
|
.Select(x => Enrich(
|
|
source: x,
|
|
cancellationToken: cancellationToken
|
|
));
|
|
|
|
//
|
|
var result = await Task.WhenAll(tasks);
|
|
return result;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|