Compare commits
2
Commits
26df2c7ebc
...
c8ad34944a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8ad34944a | ||
|
|
ae4b567bb3 |
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using xAiModels.Constants;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
|
||||||
|
namespace xAiModels.Configurations.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorEntityConfiguration : XBaseEntityTypeConfiguration<XAiVector, Guid>
|
||||||
|
{
|
||||||
|
public override void Configure(EntityTypeBuilder<XAiVector> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(XAiModelsConstants.XAiVectorTable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,15 @@ namespace xAiModels.Configurations
|
|||||||
// XAiMessage ...
|
// XAiMessage ...
|
||||||
CreateMap<XAiMessage, XAiMessageDto>();
|
CreateMap<XAiMessage, XAiMessageDto>();
|
||||||
|
|
||||||
|
//
|
||||||
|
// XAiVector ...
|
||||||
|
CreateMap<XAiVector, XAiVectorDto>()
|
||||||
|
.ForMember(x => x.Embedding, opt => opt.Ignore())
|
||||||
|
.ForMember(x => x.Metadata, opt => opt.Ignore());
|
||||||
|
CreateMap<XAiVectorDto, XAiVector>()
|
||||||
|
.ForMember(x => x.Embedding, opt => opt.Ignore())
|
||||||
|
.ForMember(x => x.Metadata, opt => opt.Ignore());
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiProject ...
|
// XAiProject ...
|
||||||
CreateMap<XAiProject, XAiProjectDto>();
|
CreateMap<XAiProject, XAiProjectDto>();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace xAiModels.Constants
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Table Mapping Identifiers ...
|
// Table Mapping Identifiers ...
|
||||||
|
public const string XAiVectorTable = "AiVectors";
|
||||||
public const string XAiMessageTable = "AiMessages";
|
public const string XAiMessageTable = "AiMessages";
|
||||||
public const string XAiProjectTable = "AiProjects";
|
public const string XAiProjectTable = "AiProjects";
|
||||||
public const string XAiConversationTable = "AiConversations";
|
public const string XAiConversationTable = "AiConversations";
|
||||||
@@ -21,6 +22,9 @@ namespace xAiModels.Constants
|
|||||||
public const string XAiMessageCollectionName = "aiMessages";
|
public const string XAiMessageCollectionName = "aiMessages";
|
||||||
public const string XAiProjectCollectionName = "AiProjectsa";
|
public const string XAiProjectCollectionName = "AiProjectsa";
|
||||||
public const string XAiConversationCollectionName = "aiConversations";
|
public const string XAiConversationCollectionName = "aiConversations";
|
||||||
|
|
||||||
|
public const string XAiVectorSingleName = "aiVector";
|
||||||
|
public const string XAiVectorCollectionName = "aiVectors";
|
||||||
|
|
||||||
//
|
//
|
||||||
// Hubs ...
|
// Hubs ...
|
||||||
@@ -33,6 +37,9 @@ namespace xAiModels.Constants
|
|||||||
public const string XAiConversationDtoHub = "aiConversationDto";
|
public const string XAiConversationDtoHub = "aiConversationDto";
|
||||||
public const string XAiConversationEntityHub = "aiConversationEntity";
|
public const string XAiConversationEntityHub = "aiConversationEntity";
|
||||||
|
|
||||||
|
public const string XAiVectorDtoHub = "aiVectorDto";
|
||||||
|
public const string XAiVectorEntityHub = "aiVectorEntity";
|
||||||
|
|
||||||
//
|
//
|
||||||
// Resource Provider Identifiers ...
|
// Resource Provider Identifiers ...
|
||||||
public const string XAiProjectTitleIdentifier = "AiPrjT";
|
public const string XAiProjectTitleIdentifier = "AiPrjT";
|
||||||
@@ -44,6 +51,7 @@ namespace xAiModels.Constants
|
|||||||
public const string GetXAiMessageEFRepositoryDescriptor = "GetXAiMessageEFRepositoryDescriptor";
|
public const string GetXAiMessageEFRepositoryDescriptor = "GetXAiMessageEFRepositoryDescriptor";
|
||||||
public const string GetXAiProjectEFRepositoryDescriptor = "GetXAiProjectEFRepositoryDescriptor";
|
public const string GetXAiProjectEFRepositoryDescriptor = "GetXAiProjectEFRepositoryDescriptor";
|
||||||
public const string GetXAiConversationEFRepositoryDescriptor = "GetXAiConversationEFRepositoryDescriptor";
|
public const string GetXAiConversationEFRepositoryDescriptor = "GetXAiConversationEFRepositoryDescriptor";
|
||||||
|
public const string GetXAiVectorEFRepositoryDescriptor = "GetXAiVectorEFRepositoryDescriptor";
|
||||||
|
|
||||||
//
|
//
|
||||||
public const string DefaultXAiProjectTitleResourceID = "XAiPrjT";
|
public const string DefaultXAiProjectTitleResourceID = "XAiPrjT";
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ namespace xAiModels.DI
|
|||||||
//
|
//
|
||||||
var pushHelper = new XPushServiceHelper();
|
var pushHelper = new XPushServiceHelper();
|
||||||
|
|
||||||
|
//
|
||||||
|
// XAiVector ...
|
||||||
|
pushHelper.AddHub<XAiVectorDtoHub>(XAiModelsConstants.XAiVectorDtoHub);
|
||||||
|
pushHelper.AddHub<XAiVectorEntityHub>(XAiModelsConstants.XAiVectorEntityHub);
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiMessage ...
|
// XAiMessage ...
|
||||||
pushHelper.AddHub<XAiMessageDtoHub>(XAiModelsConstants.XAiMessageDtoHub);
|
pushHelper.AddHub<XAiMessageDtoHub>(XAiModelsConstants.XAiMessageDtoHub);
|
||||||
@@ -245,6 +250,7 @@ namespace xAiModels.DI
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Private ...
|
#region Private ...
|
||||||
|
private static XRepositoryDescriptor aiVectorDescriptor = null;
|
||||||
private static XRepositoryDescriptor aiMessageDescriptor = null;
|
private static XRepositoryDescriptor aiMessageDescriptor = null;
|
||||||
private static XRepositoryDescriptor aiProjectDescriptor = null;
|
private static XRepositoryDescriptor aiProjectDescriptor = null;
|
||||||
private static XRepositoryDescriptor aiConversationDescriptor = null;
|
private static XRepositoryDescriptor aiConversationDescriptor = null;
|
||||||
@@ -322,6 +328,15 @@ namespace xAiModels.DI
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
case XRepositoryType.EF:
|
case XRepositoryType.EF:
|
||||||
|
//
|
||||||
|
// XAiVector ...
|
||||||
|
aiVectorDescriptor = typeof(XAiModelsHelper)
|
||||||
|
.InvokeGenericMethod<XRepositoryDescriptor>(
|
||||||
|
args: null,
|
||||||
|
runtimeType: contextType,
|
||||||
|
methodName: XAiModelsConstants.GetXAiVectorEFRepositoryDescriptor
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiMessage ...
|
// XAiMessage ...
|
||||||
aiMessageDescriptor = typeof(XAiModelsHelper)
|
aiMessageDescriptor = typeof(XAiModelsHelper)
|
||||||
@@ -352,6 +367,10 @@ namespace xAiModels.DI
|
|||||||
|
|
||||||
//
|
//
|
||||||
case XRepositoryType.Mongo:
|
case XRepositoryType.Mongo:
|
||||||
|
//
|
||||||
|
// XAiVector ...
|
||||||
|
aiVectorDescriptor = XAiModelsHelper.GetXAiVectorMongoRepositoryDescriptor();
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiMessage ...
|
// XAiMessage ...
|
||||||
aiMessageDescriptor = XAiModelsHelper.GetXAiMessageMongoRepositoryDescriptor();
|
aiMessageDescriptor = XAiModelsHelper.GetXAiMessageMongoRepositoryDescriptor();
|
||||||
@@ -367,6 +386,10 @@ namespace xAiModels.DI
|
|||||||
|
|
||||||
//
|
//
|
||||||
case XRepositoryType.InMemory:
|
case XRepositoryType.InMemory:
|
||||||
|
//
|
||||||
|
// XAiVector ...
|
||||||
|
aiVectorDescriptor = XAiModelsHelper.GetXAiVectorInMemoryRepositoryDescriptor();
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiMessage ...
|
// XAiMessage ...
|
||||||
aiMessageDescriptor = XAiModelsHelper.GetXAiMessageInMemoryRepositoryDescriptor();
|
aiMessageDescriptor = XAiModelsHelper.GetXAiMessageInMemoryRepositoryDescriptor();
|
||||||
@@ -383,6 +406,17 @@ namespace xAiModels.DI
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Register Repository Descriptor ...
|
#region Register Repository Descriptor ...
|
||||||
|
//
|
||||||
|
// XAiVector ...
|
||||||
|
if (!aiVectorDescriptor.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
services.AddXRepository(
|
||||||
|
lifeTime: lifeTime,
|
||||||
|
descriptor: aiVectorDescriptor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiMessage ...
|
// XAiMessage ...
|
||||||
if (!aiMessageDescriptor.IsNull())
|
if (!aiMessageDescriptor.IsNull())
|
||||||
@@ -419,6 +453,26 @@ namespace xAiModels.DI
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Register Services ...
|
#region Register Services ...
|
||||||
|
//
|
||||||
|
#region AiVector ...
|
||||||
|
//
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXAiVectorServiceProvider), typeof(XAiVectorServiceProvider), lifeTime)
|
||||||
|
);
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXAiVectorRepositoryService), typeof(XAiVectorRepositoryService), lifeTime)
|
||||||
|
);
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXAiVectorRepositoryProvider), typeof(XAiVectorRepositoryProvider), lifeTime)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enrichers ...
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXAiVectorEnricher), typeof(XAiVectorEnricher), lifeTime)
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region AiMessage ...
|
#region AiMessage ...
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using xCommons.Extensions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xAiModels.Extensions
|
||||||
|
{
|
||||||
|
public static class XEmbeddingExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts String to Embeddings JSON ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static float[] AsEmbedding(this string source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (source.IsNullOrEmpty()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// JSON is expected to be like: [0.12, 0.34, ...] ...
|
||||||
|
var result = source.FromJSON<float[]>();
|
||||||
|
if (!result.HasChild())
|
||||||
|
{
|
||||||
|
result = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts to Meta Data Representation ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Dictionary<string, string> AsMetadat(this string source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (source.IsNullOrEmpty()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// JSON is expected to be like: [0.12, 0.34, ...] ...
|
||||||
|
var result = source.FromJSON<Dictionary<string, string>>();
|
||||||
|
if (!result.HasChild())
|
||||||
|
{
|
||||||
|
result = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -811,6 +811,273 @@ namespace xAiModels.Helpers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region XAiVector ...
|
||||||
|
//
|
||||||
|
#region EF Repository Descriptor Provider(s) ...
|
||||||
|
public static XEFRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorEFRepository<TContext>,
|
||||||
|
TContext
|
||||||
|
> GetXAiVectorEFRepositoryDescriptor<TContext>()
|
||||||
|
where TContext : XDbContext
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = new XEFRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorEFRepository<TContext>,
|
||||||
|
TContext
|
||||||
|
>();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XEFRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorEFRepository<TContext>,
|
||||||
|
TContext,
|
||||||
|
IXAiVectorSeeder,
|
||||||
|
TSeederImplementation
|
||||||
|
> GetXAiVectorEFRepositoryDescriptor<TContext, TSeederImplementation>()
|
||||||
|
where TContext : XDbContext
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<XAiVector, Guid>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = new XEFRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorEFRepository<TContext>,
|
||||||
|
TContext,
|
||||||
|
IXAiVectorSeeder,
|
||||||
|
TSeederImplementation
|
||||||
|
>();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Mongo Repository Descriptor Provider(s) ...
|
||||||
|
public static XMongoRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorMongoRepository
|
||||||
|
> GetXAiVectorMongoRepositoryDescriptor()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = new XMongoRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorMongoRepository
|
||||||
|
>();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XMongoRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorMongoRepository,
|
||||||
|
IXAiVectorSeeder,
|
||||||
|
TSeederImplementation
|
||||||
|
> GetXAiVectorMongoRepositoryDescriptor<TSeederImplementation>()
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<XAiVector, Guid>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = new XMongoRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorMongoRepository,
|
||||||
|
IXAiVectorSeeder,
|
||||||
|
TSeederImplementation
|
||||||
|
>();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region InMemory Repository Descriptor Provider(s) ...
|
||||||
|
public static XInMemoryRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorInMemoryRepository
|
||||||
|
> GetXAiVectorInMemoryRepositoryDescriptor()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = new XInMemoryRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorInMemoryRepository
|
||||||
|
>();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XInMemoryRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorInMemoryRepository,
|
||||||
|
IXAiVectorSeeder,
|
||||||
|
TSeederImplementation
|
||||||
|
> GetXAiVectorInMemoryRepositoryDescriptor<TSeederImplementation>()
|
||||||
|
where TSeederImplementation : XBaseDbSeeder<XAiVector, Guid>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = new XInMemoryRepositoryDescriptor<
|
||||||
|
XAiVector,
|
||||||
|
Guid,
|
||||||
|
IXAiVectorKeyGenerator,
|
||||||
|
XAiVectorKeyGenerator,
|
||||||
|
IXAiVectorRepositoryEvents,
|
||||||
|
XAiVectorRepositoryEvents,
|
||||||
|
XAiVectorGraphType,
|
||||||
|
GuidGraphType,
|
||||||
|
XAiVectorGraphQuery,
|
||||||
|
IXAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphQLTypeHelper,
|
||||||
|
XAiVectorGraphSchema,
|
||||||
|
IXAiVectorRepository,
|
||||||
|
XAiVectorInMemoryRepository,
|
||||||
|
IXAiVectorSeeder,
|
||||||
|
TSeederImplementation
|
||||||
|
>();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xPushService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Dtos
|
||||||
|
{
|
||||||
|
public interface IXAiVectorDtoHub : IXBaseDtoHub<XAiVector, XAiVectorDto, Guid>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Dtos
|
||||||
|
{
|
||||||
|
public interface IXAiVectorRepositoryService : IXBaseRepositoryService<XAiVector, XAiVectorDto, Guid>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xPushService.Interfaces;
|
||||||
|
using xAiModels.Providers.Dtos;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Dtos
|
||||||
|
{
|
||||||
|
public interface IXAiVectorServiceProvider : IXBaseDtoProvider<XAiVector, XAiVectorDto, Guid, XAiVectorDtoHub>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Enrichers
|
||||||
|
{
|
||||||
|
public interface IXAiVectorEnricher
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Enrichers ...
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiVectorDto> Enrich(
|
||||||
|
XAiVector source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiVectorDto> Enrich(
|
||||||
|
XAiVectorDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
||||||
|
IEnumerable<XAiVector> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
||||||
|
IEnumerable<XAiVectorDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using xPushService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Entities
|
||||||
|
{
|
||||||
|
public interface IXAiVectorEntityHub : IXBaseEntityHub<XAiVector, Guid>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Entities
|
||||||
|
{
|
||||||
|
public interface IXAiVectorGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XAiVector, Guid>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Entities
|
||||||
|
{
|
||||||
|
public interface IXAiVectorKeyGenerator : IXKeyGenerator<XAiVector, Guid>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Entities
|
||||||
|
{
|
||||||
|
public interface IXAiVectorRepository : IXBaseRepository<XAiVector, Guid>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Entities
|
||||||
|
{
|
||||||
|
public interface IXAiVectorRepositoryEvents : IXBaseRepositoryEvents<XAiVector>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using xPushService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xAiModels.Providers.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Entities
|
||||||
|
{
|
||||||
|
public interface IXAiVectorRepositoryProvider : IXBaseEntityProvider<XAiVector, Guid, XAiVectorEntityHub>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Entities
|
||||||
|
{
|
||||||
|
public interface IXAiVectorSeeder : IXBaseDbSeeder<XAiVector, Guid>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using xModels.Base;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xAiModels.Models.Dtos
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Vector DTO for AI Vector data ...
|
||||||
|
/// </summary>
|
||||||
|
public class XAiVectorDto : XBaseGuidIDEntityDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Text content of the vector ...
|
||||||
|
/// </summary>
|
||||||
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Doc and Chunk Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
public string Identifier { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Embedding vector representation ...
|
||||||
|
/// </summary>
|
||||||
|
public virtual ReadOnlyMemory<float> Embedding { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Metadata associated with the vector ...
|
||||||
|
/// </summary>
|
||||||
|
public virtual Dictionary<string, string> Metadata { get; set; } = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xAiModels.Models.Dtos
|
||||||
|
{
|
||||||
|
public class XAiVectorSearchResult
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Text { get; set; }
|
||||||
|
public float Score { get; set; }
|
||||||
|
public string Identifier { get; set; }
|
||||||
|
public Dictionary<string, string> Metadata { get; set; } = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using xModels.Base;
|
|
||||||
|
|
||||||
namespace xAiModels.Models.Entities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an embedd document in the AI system.
|
|
||||||
/// </summary>
|
|
||||||
public class XAiDocument : XBaseGuidIDEntity
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// User Identifier ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
[Required]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string OwnerId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Title of Document ...
|
|
||||||
/// </summary>
|
|
||||||
[StringLength(255)]
|
|
||||||
public string Title { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Content of Document ...
|
|
||||||
/// </summary>
|
|
||||||
public string Content { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Hash of the Document Content ...
|
|
||||||
/// </summary>
|
|
||||||
public string ContentHash { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Embedding Model Identifier ...
|
|
||||||
/// </summary>
|
|
||||||
public string EmbeddingModel { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Dimensions of the Embedding ...
|
|
||||||
/// </summary>
|
|
||||||
public int Dimensions { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Vector representation of the Document ...
|
|
||||||
/// </summary>
|
|
||||||
public byte[] Vector { get; set; } = [];
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Created Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime CreatedOn { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updated Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using xModels.Base;
|
||||||
|
|
||||||
|
namespace xAiModels.Models.Entities
|
||||||
|
{
|
||||||
|
public class XAiVector : XBaseGuidIDEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Thge Content Which Embedded ...
|
||||||
|
/// </summary>
|
||||||
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Doc and Chunk Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
public string Identifier { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a Json String which Represents IReadOnlyList of float ...
|
||||||
|
/// </summary>
|
||||||
|
public string Embedding { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a Json String Which Represents MetaData ...
|
||||||
|
/// </summary>
|
||||||
|
public string Metadata { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using xPushService.Base;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xAiModels.Interfaces.Dtos;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Dtos
|
||||||
|
{
|
||||||
|
public class XAiVectorDtoHub : XBaseDtoHub<XAiVector, XAiVectorDto, Guid>, IXAiVectorDtoHub
|
||||||
|
{
|
||||||
|
public XAiVectorDtoHub(
|
||||||
|
ILogger<XAiVectorDtoHub> logger
|
||||||
|
) : base(logger)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xAiModels.Configurations;
|
||||||
|
using xAiModels.Interfaces.Dtos;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Dtos
|
||||||
|
{
|
||||||
|
public class XAiVectorRepositoryService : XBaseRepositoryService<XAiVector, XAiVectorDto, Guid>, IXAiVectorRepositoryService
|
||||||
|
{
|
||||||
|
public XAiVectorRepositoryService(
|
||||||
|
IXAiVectorRepository repository
|
||||||
|
) : base(
|
||||||
|
repository,
|
||||||
|
mapperProfiles:
|
||||||
|
[
|
||||||
|
new XAiModelMappersProfile()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using xPushService.Base;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xAiModels.Interfaces.Dtos;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Dtos
|
||||||
|
{
|
||||||
|
public class XAiVectorServiceProvider : XBaseDtoProvider<XAiVector, XAiVectorDto, Guid, XAiVectorDtoHub>, IXAiVectorServiceProvider
|
||||||
|
{
|
||||||
|
public XAiVectorServiceProvider(
|
||||||
|
IHubContext<XAiVectorDtoHub> hub,
|
||||||
|
XDataServiceConfiguration dataConfiguration,
|
||||||
|
IXAiVectorRepositoryService service,
|
||||||
|
IXIdentityProvider identityProvider = null
|
||||||
|
) : base(
|
||||||
|
hub,
|
||||||
|
dataConfiguration,
|
||||||
|
service,
|
||||||
|
identityProvider
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Db;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorEFRepository<TContext> : XBaseEFRepository<XAiVector, Guid, TContext>, IXAiVectorRepository
|
||||||
|
where TContext : XDbContext
|
||||||
|
{
|
||||||
|
public XAiVectorEFRepository(
|
||||||
|
IXUnitOfWorks<TContext> unitOfWorks,
|
||||||
|
XDataServiceConfiguration configuration,
|
||||||
|
IXAiVectorKeyGenerator keyGenerator = null,
|
||||||
|
IXAiVectorRepositoryEvents baseRepositoryEvents = null
|
||||||
|
) : base(
|
||||||
|
unitOfWorks,
|
||||||
|
configuration,
|
||||||
|
keyGenerator,
|
||||||
|
baseRepositoryEvents
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using xPushService.Base;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorEntityHub : XBaseEntityHub<XAiVector, Guid>, IXAiVectorEntityHub
|
||||||
|
{
|
||||||
|
public XAiVectorEntityHub(
|
||||||
|
ILogger<XAiVectorEntityHub> logger
|
||||||
|
) : base(logger)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorInMemoryRepository : XBaseInMemoryRepository<XAiVector, Guid>, IXAiVectorRepository
|
||||||
|
{
|
||||||
|
public XAiVectorInMemoryRepository(
|
||||||
|
XDataServiceConfiguration configuration,
|
||||||
|
IXAiVectorKeyGenerator keyGenerator = null,
|
||||||
|
IXAiVectorRepositoryEvents baseRepositoryEvents = null
|
||||||
|
) : base(
|
||||||
|
configuration,
|
||||||
|
keyGenerator,
|
||||||
|
baseRepositoryEvents
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using xDataService.Providers;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorKeyGenerator : XGuidKeyGenerator<XAiVector>, IXAiVectorKeyGenerator
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorMongoRepository : XBaseMongoRepository<XAiVector, Guid>, IXAiVectorRepository
|
||||||
|
{
|
||||||
|
public XAiVectorMongoRepository(
|
||||||
|
XDataBaseConfiguration dbConfiguration,
|
||||||
|
XDataServiceConfiguration configuration,
|
||||||
|
string collectionName = null,
|
||||||
|
IXAiVectorKeyGenerator keyGenerator = null,
|
||||||
|
IXAiVectorRepositoryEvents baseRepositoryEvents = null
|
||||||
|
) : base(
|
||||||
|
dbConfiguration,
|
||||||
|
configuration,
|
||||||
|
collectionName,
|
||||||
|
keyGenerator,
|
||||||
|
baseRepositoryEvents
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using xDataService.Providers;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorRepositoryEvents : XBaseRepositoryEvents<XAiVector>, IXAiVectorRepositoryEvents
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using xPushService.Base;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public class XAiVectorRepositoryProvider : XBaseEntityProvider<XAiVector, Guid, XAiVectorEntityHub>, IXAiVectorRepositoryProvider
|
||||||
|
{
|
||||||
|
public XAiVectorRepositoryProvider(
|
||||||
|
IHubContext<XAiVectorEntityHub> hub,
|
||||||
|
IXAiVectorRepository repository,
|
||||||
|
XDataServiceConfiguration dataConfiguration,
|
||||||
|
IXIdentityProvider identityProvider = null
|
||||||
|
) : base(
|
||||||
|
hub,
|
||||||
|
repository,
|
||||||
|
dataConfiguration,
|
||||||
|
identityProvider
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.Entities
|
||||||
|
{
|
||||||
|
public abstract class XAiVectorSeederBase : XBaseDbSeeder<XAiVector, Guid>, IXAiVectorSeeder
|
||||||
|
{
|
||||||
|
protected XAiVectorSeederBase(
|
||||||
|
string entity,
|
||||||
|
string database,
|
||||||
|
IXAiVectorRepository repository,
|
||||||
|
XDataServiceConfiguration dataServiceConfiguration
|
||||||
|
) : base(
|
||||||
|
entity,
|
||||||
|
database,
|
||||||
|
repository,
|
||||||
|
dataServiceConfiguration
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using xAiModels.Constants;
|
||||||
|
using xDataService.GraphQL;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.GraphQL
|
||||||
|
{
|
||||||
|
public class XAiVectorGraphQLTypeHelper : XBaseGraphQLTypeHelper<XAiVector, Guid>, IXAiVectorGraphQLTypeHelper
|
||||||
|
{
|
||||||
|
public override string GetInQueryCollectionName()
|
||||||
|
{
|
||||||
|
return XAiModelsConstants.XAiVectorCollectionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetInQuerySingleName()
|
||||||
|
{
|
||||||
|
return XAiModelsConstants.XAiVectorSingleName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using GraphQL.Types;
|
||||||
|
using xDataService.GraphQL;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.GraphQL
|
||||||
|
{
|
||||||
|
public class XAiVectorGraphQuery : XBaseGraphQLQuery<XAiVector, Guid, XAiVectorGraphType, GuidGraphType>
|
||||||
|
{
|
||||||
|
public XAiVectorGraphQuery(
|
||||||
|
XDataServiceConfiguration configuration,
|
||||||
|
IXAiVectorRepository repository,
|
||||||
|
IXAiVectorGraphQLTypeHelper helper
|
||||||
|
) : base(
|
||||||
|
configuration,
|
||||||
|
repository,
|
||||||
|
helper
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using GraphQL.Types;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.GraphQL
|
||||||
|
{
|
||||||
|
public class XAiVectorGraphSchema : Schema
|
||||||
|
{
|
||||||
|
public XAiVectorGraphSchema(IServiceProvider services) : base(services)
|
||||||
|
{
|
||||||
|
Query = (XAiVectorGraphQuery)services.GetService(typeof(XAiVectorGraphQuery));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.GraphQL;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers.GraphQL
|
||||||
|
{
|
||||||
|
public class XAiVectorGraphType : XBaseGraphObjectType<XAiVector, Guid>
|
||||||
|
{
|
||||||
|
public XAiVectorGraphType() : base()
|
||||||
|
{
|
||||||
|
Field(x => x.Text);
|
||||||
|
Field(x => x.Metadata);
|
||||||
|
Field(x => x.Embedding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,12 +12,14 @@ using System.Threading.Tasks;
|
|||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using xDataService.Extensions;
|
using xDataService.Extensions;
|
||||||
|
using System.Numerics.Tensors;
|
||||||
using xAiModels.Providers.Hubs;
|
using xAiModels.Providers.Hubs;
|
||||||
using xAiModels.Interfaces.Dtos;
|
using xAiModels.Interfaces.Dtos;
|
||||||
using xStringService.Interfaces;
|
using xStringService.Interfaces;
|
||||||
using xAiModels.Models.Entities;
|
using xAiModels.Models.Entities;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using xAiModels.Interfaces.Entities;
|
||||||
using xAiModels.Interfaces.Enrichers;
|
using xAiModels.Interfaces.Enrichers;
|
||||||
|
|
||||||
namespace xAiModels.Providers
|
namespace xAiModels.Providers
|
||||||
@@ -30,11 +32,14 @@ namespace xAiModels.Providers
|
|||||||
//
|
//
|
||||||
#region Properties ...
|
#region Properties ...
|
||||||
private readonly IXStringProvider stringProvider;
|
private readonly IXStringProvider stringProvider;
|
||||||
|
private readonly IXAiVectorEnricher vectorEnricher;
|
||||||
private readonly XAppConfiguration appConfiguration;
|
private readonly XAppConfiguration appConfiguration;
|
||||||
private readonly IHubContext<XAiDataProviderHub> hub;
|
private readonly IHubContext<XAiDataProviderHub> hub;
|
||||||
private readonly IXAiMessageEnricher messageEnricher;
|
private readonly IXAiMessageEnricher messageEnricher;
|
||||||
private readonly IXAiProjectEnricher projectEnricher;
|
private readonly IXAiProjectEnricher projectEnricher;
|
||||||
|
private readonly IXAiVectorRepository vectorRepository;
|
||||||
private readonly IXAiConversationEnricher conversationEnricher;
|
private readonly IXAiConversationEnricher conversationEnricher;
|
||||||
|
private readonly IXAiVectorRepositoryService vectorRepositoryService;
|
||||||
private readonly IXAiMessageRepositoryService messageRepositoryService;
|
private readonly IXAiMessageRepositoryService messageRepositoryService;
|
||||||
private readonly IXAiProjectRepositoryService projectRepositoryService;
|
private readonly IXAiProjectRepositoryService projectRepositoryService;
|
||||||
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
||||||
@@ -45,11 +50,14 @@ namespace xAiModels.Providers
|
|||||||
|
|
||||||
public XAiDataProvider(
|
public XAiDataProvider(
|
||||||
IXStringProvider stringProvider,
|
IXStringProvider stringProvider,
|
||||||
|
IXAiVectorEnricher vectorEnricher,
|
||||||
XAppConfiguration appConfiguration,
|
XAppConfiguration appConfiguration,
|
||||||
IHubContext<XAiDataProviderHub> hub,
|
IHubContext<XAiDataProviderHub> hub,
|
||||||
IXAiProjectEnricher projectEnricher,
|
IXAiProjectEnricher projectEnricher,
|
||||||
IXAiMessageEnricher messageEnricher,
|
IXAiMessageEnricher messageEnricher,
|
||||||
|
IXAiVectorRepository vectorRepository,
|
||||||
IXAiConversationEnricher conversationEnricher,
|
IXAiConversationEnricher conversationEnricher,
|
||||||
|
IXAiVectorRepositoryService vectorRepositoryService,
|
||||||
IXAiMessageRepositoryService messageRepositoryService,
|
IXAiMessageRepositoryService messageRepositoryService,
|
||||||
IXAiProjectRepositoryService projectRepositoryService,
|
IXAiProjectRepositoryService projectRepositoryService,
|
||||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
||||||
@@ -60,10 +68,13 @@ namespace xAiModels.Providers
|
|||||||
{
|
{
|
||||||
this.hub = hub;
|
this.hub = hub;
|
||||||
this.stringProvider = stringProvider;
|
this.stringProvider = stringProvider;
|
||||||
|
this.vectorEnricher = vectorEnricher;
|
||||||
this.projectEnricher = projectEnricher;
|
this.projectEnricher = projectEnricher;
|
||||||
this.messageEnricher = messageEnricher;
|
this.messageEnricher = messageEnricher;
|
||||||
this.appConfiguration = appConfiguration;
|
this.appConfiguration = appConfiguration;
|
||||||
|
this.vectorRepository = vectorRepository;
|
||||||
this.conversationEnricher = conversationEnricher;
|
this.conversationEnricher = conversationEnricher;
|
||||||
|
this.vectorRepositoryService = vectorRepositoryService;
|
||||||
this.messageRepositoryService = messageRepositoryService;
|
this.messageRepositoryService = messageRepositoryService;
|
||||||
this.projectRepositoryService = projectRepositoryService;
|
this.projectRepositoryService = projectRepositoryService;
|
||||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
||||||
@@ -1216,7 +1227,7 @@ namespace xAiModels.Providers
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Query Messages ...
|
/// Query Messages ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1283,12 +1294,245 @@ namespace xAiModels.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Vectors ...
|
||||||
|
/// <summary>
|
||||||
|
/// Insert or Update ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
/// <param name="embedding"></param>
|
||||||
|
/// <param name="metadata"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task UpsertAsync(
|
||||||
|
string identifier,
|
||||||
|
string text,
|
||||||
|
ReadOnlyMemory<float> embedding,
|
||||||
|
Dictionary<string, string> metadata = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
embedding.IsEmpty ||
|
||||||
|
text.IsNullOrEmpty() ||
|
||||||
|
identifier.IsNullOrEmpty()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var exists = await vectorRepository.FindOneAsync(
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
predicate: x => x.Identifier == identifier
|
||||||
|
);
|
||||||
|
var isExists = !exists.IsNullOrDefault();
|
||||||
|
if (isExists)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
exists.Text = text;
|
||||||
|
exists.Embedding = embedding.ToJSON();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
exists = new XAiVector
|
||||||
|
{
|
||||||
|
Text = text,
|
||||||
|
Identifier = identifier,
|
||||||
|
Metadata = metadata.ToJSON(),
|
||||||
|
Embedding = embedding.ToJSON(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
await vectorRepository.AddOrUpdateAsync(
|
||||||
|
item: exists,
|
||||||
|
saveChanges: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Search Cosine Similarity based on Top K ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="queryEmbedding"></param>
|
||||||
|
/// <param name="topK"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IReadOnlyList<XAiVectorSearchResult>> SearchAsync(
|
||||||
|
ReadOnlyMemory<float> queryEmbedding,
|
||||||
|
int topK = 5,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (
|
||||||
|
topK <= 0 ||
|
||||||
|
queryEmbedding.IsEmpty
|
||||||
|
)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converts Question Vector to Vector Array ...
|
||||||
|
var queryVector = queryEmbedding.ToArray();
|
||||||
|
var scoredResult = new List<(XAiVectorSearchResult Result, float Score)>();
|
||||||
|
|
||||||
|
//
|
||||||
|
var vectorsEnumerator = vectorRepository.GetAllAsAsyncEnumerable();
|
||||||
|
await foreach (var vector in vectorsEnumerator)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Vector ...
|
||||||
|
if (vector.Embedding.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Cancellation Token ...
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ignore Unsame Vectors ...
|
||||||
|
var embd = vector.Embedding.AsEmbedding();
|
||||||
|
if (
|
||||||
|
embd.IsNull() ||
|
||||||
|
embd.Length != queryEmbedding.Length
|
||||||
|
)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Cosine Similarity Score ...
|
||||||
|
var score = ComputeCosineSimilarity(queryVector, embd);
|
||||||
|
|
||||||
|
//
|
||||||
|
scoredResult.Add((new XAiVectorSearchResult
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Score = score,
|
||||||
|
Id = vector.Id,
|
||||||
|
Text = vector.Text,
|
||||||
|
Identifier = vector.Identifier,
|
||||||
|
Metadata = vector.Metadata.AsMetadat(),
|
||||||
|
}, score));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = scoredResult
|
||||||
|
.OrderByDescending(x => x.Score)
|
||||||
|
.Take(topK)
|
||||||
|
.Select(x => x.Result)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Enrichers ...
|
#region Enrichers ...
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XAiVectorDto> Enrich(
|
||||||
|
XAiVector source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await vectorEnricher.Enrich(
|
||||||
|
source: source,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
||||||
|
IEnumerable<XAiVector> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await vectorEnricher.EnrichRange(
|
||||||
|
sources: sources,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Item ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XAiVectorDto> Enrich(
|
||||||
|
XAiVectorDto source,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await vectorEnricher.Enrich(
|
||||||
|
source: source,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enrich Specified Items ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sources"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XAiVectorDto>> EnrichRange(
|
||||||
|
IEnumerable<XAiVectorDto> sources,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await vectorEnricher.EnrichRange(
|
||||||
|
sources: sources,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enrich Specified Item ...
|
/// Enrich Specified Item ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1848,6 +2092,33 @@ namespace xAiModels.Providers
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Search Similarity ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a"></param>
|
||||||
|
/// <param name="b"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private float ComputeCosineSimilarity(float[] a, float[] b)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (a.Length != b.Length)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Similarity ...
|
||||||
|
var result = TensorPrimitives
|
||||||
|
.CosineSimilarity(
|
||||||
|
a.AsSpan(),
|
||||||
|
b.AsSpan()
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using xAiModels.Configurations.Entities;
|
||||||
|
|
||||||
|
namespace xAiModels.Providers
|
||||||
|
{
|
||||||
|
public class XAiVectorEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
|
||||||
|
{
|
||||||
|
public XAiVectorEntityRegisterar()
|
||||||
|
: base(nameof(XAiVectorEntityRegisterar))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Add Entity ...
|
||||||
|
AddEntity<XAiVector, Guid>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configure Entities ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="modelBuilder"></param>
|
||||||
|
public override void ConfigureEntities(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Configure Entity Using Provided ...
|
||||||
|
modelBuilder
|
||||||
|
.ApplyConfigurationsFromAssembly(typeof(XAiVectorEntityConfiguration).Assembly);
|
||||||
|
|
||||||
|
//
|
||||||
|
base.ConfigureEntities(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user