179 lines
5.7 KiB
C#
179 lines
5.7 KiB
C#
using Microsoft.Extensions.AI;
|
|
using Qdrant.Client.Grpc;
|
|
|
|
namespace ChatRAG.Settings.ChatRAG.Configuration
|
|
{
|
|
public class VectorDatabaseSettings
|
|
{
|
|
public string Provider { get; set; } = "Qdrant";
|
|
public MongoDBSettings? MongoDB { get; set; }
|
|
public QdrantSettings? Qdrant { get; set; }
|
|
public ChromaSettings? Chroma { get; set; }
|
|
public EmbeddingSettings Embedding { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Retorna erros de validação
|
|
/// </summary>
|
|
public List<string> GetValidationErrors()
|
|
{
|
|
var errors = new List<string>();
|
|
|
|
if (string.IsNullOrWhiteSpace(Provider))
|
|
errors.Add("Provider é obrigatório");
|
|
|
|
switch (Provider.ToLower())
|
|
{
|
|
case "mongodb":
|
|
errors.AddRange(MongoDB.GetValidationErrors());
|
|
break;
|
|
case "qdrant":
|
|
errors.AddRange(Qdrant.GetValidationErrors());
|
|
break;
|
|
case "chroma":
|
|
errors.AddRange(Chroma.GetValidationErrors());
|
|
break;
|
|
default:
|
|
errors.Add($"Provider '{Provider}' não é suportado");
|
|
break;
|
|
}
|
|
|
|
errors.AddRange(Embedding.GetValidationErrors());
|
|
|
|
return errors;
|
|
}
|
|
}
|
|
|
|
public class MongoDBSettings
|
|
{
|
|
public string ConnectionString { get; set; } = "";
|
|
public string DatabaseName { get; set; } = "";
|
|
public string TextCollectionName { get; set; } = "Texts";
|
|
public string ProjectCollectionName { get; set; } = "Groups";
|
|
public string UserDataName { get; set; } = "UserData";
|
|
public int ConnectionTimeoutSeconds { get; set; } = 30;
|
|
|
|
public List<string> GetValidationErrors()
|
|
{
|
|
var errors = new List<string>();
|
|
|
|
if (string.IsNullOrWhiteSpace(ConnectionString))
|
|
errors.Add("MongoDB ConnectionString é obrigatória");
|
|
|
|
if (string.IsNullOrWhiteSpace(DatabaseName))
|
|
errors.Add("MongoDB DatabaseName é obrigatório");
|
|
|
|
if (string.IsNullOrWhiteSpace(TextCollectionName))
|
|
errors.Add("MongoDB TextCollectionName é obrigatório");
|
|
|
|
if (ConnectionTimeoutSeconds <= 0)
|
|
errors.Add("MongoDB ConnectionTimeoutSeconds deve ser maior que 0");
|
|
|
|
return errors;
|
|
}
|
|
}
|
|
|
|
public class QdrantSettings
|
|
{
|
|
public string Host { get; set; } = "localhost";
|
|
public int Port { get; set; } = 6334;
|
|
public string CollectionName { get; set; } = "texts";
|
|
public string GroupsCollectionName { get; set; } = "projects";
|
|
public int VectorSize { get; set; } = 384;
|
|
public string Distance { get; set; } = "Cosine";
|
|
public int HnswM { get; set; } = 16;
|
|
public int HnswEfConstruct { get; set; } = 200;
|
|
public bool OnDisk { get; set; } = false;
|
|
public bool UseTls { get; set; } = false;
|
|
|
|
public List<string> GetValidationErrors()
|
|
{
|
|
var errors = new List<string>();
|
|
|
|
if (string.IsNullOrWhiteSpace(Host))
|
|
errors.Add("Qdrant Host é obrigatório");
|
|
|
|
if (Port <= 0)
|
|
errors.Add("Qdrant Port deve ser maior que 0");
|
|
|
|
if (string.IsNullOrWhiteSpace(CollectionName))
|
|
errors.Add("Qdrant CollectionName é obrigatório");
|
|
|
|
if (VectorSize <= 0)
|
|
errors.Add("Qdrant VectorSize deve ser maior que 0");
|
|
|
|
if (HnswM <= 0)
|
|
errors.Add("Qdrant HnswM deve ser maior que 0");
|
|
|
|
if (HnswEfConstruct <= 0)
|
|
errors.Add("Qdrant HnswEfConstruct deve ser maior que 0");
|
|
|
|
var validDistances = new[] { "Cosine", "Euclid", "Dot", "Manhattan" };
|
|
if (!validDistances.Contains(Distance))
|
|
errors.Add($"Qdrant Distance deve ser um de: {string.Join(", ", validDistances)}");
|
|
|
|
return errors;
|
|
}
|
|
}
|
|
|
|
public class ChromaSettings
|
|
{
|
|
public string Host { get; set; } = "localhost";
|
|
public int Port { get; set; } = 8000;
|
|
public string CollectionName { get; set; } = "rag_documents";
|
|
public string ApiVersion { get; set; } = "v1";
|
|
|
|
public List<string> GetValidationErrors()
|
|
{
|
|
var errors = new List<string>();
|
|
|
|
return errors;
|
|
}
|
|
}
|
|
|
|
public class EmbeddingSettings
|
|
{
|
|
/// <summary>
|
|
/// Provider de embedding (OpenAI, Ollama, Azure, etc.)
|
|
/// </summary>
|
|
public string Provider { get; set; } = "OpenAI";
|
|
|
|
/// <summary>
|
|
/// Modelo de embedding
|
|
/// </summary>
|
|
public string Model { get; set; } = "text-embedding-ada-002";
|
|
|
|
/// <summary>
|
|
/// Tamanho esperado do embedding
|
|
/// </summary>
|
|
public int ExpectedSize { get; set; } = 1536;
|
|
|
|
/// <summary>
|
|
/// Batch size para processamento em lote
|
|
/// </summary>
|
|
public int BatchSize { get; set; } = 100;
|
|
|
|
/// <summary>
|
|
/// Cache de embeddings em memória
|
|
/// </summary>
|
|
public bool EnableCache { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// TTL do cache em minutos
|
|
/// </summary>
|
|
public int CacheTtlMinutes { get; set; } = 60;
|
|
|
|
public List<string> GetValidationErrors()
|
|
{
|
|
var errors = new List<string>();
|
|
|
|
if (ExpectedSize <= 0)
|
|
errors.Add("Embedding ExpectedSize deve ser maior que 0");
|
|
|
|
if (BatchSize <= 0)
|
|
errors.Add("Embedding BatchSize deve ser maior que 0");
|
|
|
|
return errors;
|
|
}
|
|
}
|
|
}
|