100 lines
3.6 KiB
C#
100 lines
3.6 KiB
C#
using ChatApi.Data;
|
|
using ChatRAG.Contracts.VectorSearch;
|
|
using ChatRAG.Data;
|
|
using ChatRAG.Services;
|
|
using ChatRAG.Services.Contracts;
|
|
using ChatRAG.Services.ResponseService;
|
|
using ChatRAG.Services.SearchVectors;
|
|
using ChatRAG.Services.TextServices;
|
|
using ChatRAG.Settings;
|
|
using ChatRAG.Settings.ChatRAG.Configuration;
|
|
using Microsoft.Extensions.Options;
|
|
using Qdrant.Client;
|
|
|
|
namespace ChatRAG.Extensions
|
|
{
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Registra o sistema completo de Vector Database
|
|
/// </summary>
|
|
public static IServiceCollection AddVectorDatabase(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
// Registra e valida configurações
|
|
services.Configure<VectorDatabaseSettings>(
|
|
configuration.GetSection("VectorDatabase"));
|
|
|
|
services.AddSingleton<IValidateOptions<VectorDatabaseSettings>,
|
|
ChatRAG.Settings.VectorDatabaseSettingsValidator>();
|
|
|
|
// Registra factory principal
|
|
services.AddScoped<IVectorDatabaseFactory, VectorDatabaseFactory>();
|
|
|
|
// Registra implementações de todos os providers
|
|
services.AddMongoDbProvider();
|
|
services.AddQdrantProvider(); // 👈 Agora ativo!
|
|
|
|
// Registra interfaces principais usando factory
|
|
services.AddScoped<IVectorSearchService>(provider =>
|
|
{
|
|
var factory = provider.GetRequiredService<IVectorDatabaseFactory>();
|
|
return factory.CreateVectorSearchService();
|
|
});
|
|
|
|
services.AddScoped<ITextDataService>(provider =>
|
|
{
|
|
var factory = provider.GetRequiredService<IVectorDatabaseFactory>();
|
|
return factory.CreateTextDataService();
|
|
});
|
|
|
|
services.AddScoped<IResponseService>(provider =>
|
|
{
|
|
var factory = provider.GetRequiredService<IVectorDatabaseFactory>();
|
|
return factory.CreateResponseService();
|
|
});
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registra implementações MongoDB (suas classes atuais)
|
|
/// </summary>
|
|
private static IServiceCollection AddMongoDbProvider(this IServiceCollection services)
|
|
{
|
|
services.AddScoped<TextData>(); // Implementa ITextDataService
|
|
services.AddScoped<TextDataRepository>();
|
|
services.AddScoped<ResponseRAGService>(); // Implementa IResponseService
|
|
services.AddScoped<MongoVectorSearchService>(); // Wrapper para IVectorSearchService
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registra implementações Qdrant
|
|
/// </summary>
|
|
private static IServiceCollection AddQdrantProvider(this IServiceCollection services)
|
|
{
|
|
// ✅ Cliente Qdrant configurado
|
|
services.AddScoped<QdrantClient>(provider =>
|
|
{
|
|
var settings = provider.GetRequiredService<IOptions<VectorDatabaseSettings>>();
|
|
var qdrantSettings = settings.Value.Qdrant;
|
|
|
|
return new QdrantClient(
|
|
host: qdrantSettings.Host,
|
|
port: qdrantSettings.Port,
|
|
https: qdrantSettings.UseTls
|
|
);
|
|
});
|
|
|
|
// ✅ Serviços Qdrant
|
|
services.AddScoped<QdrantVectorSearchService>();
|
|
services.AddScoped<QdrantTextDataService>();
|
|
services.AddScoped<QdrantResponseService>();
|
|
|
|
return services;
|
|
}
|
|
}
|
|
} |