ChatRAG/Settings/ghcutjxi.wn3~
2025-06-21 14:20:07 -03:00

120 lines
4.1 KiB
Plaintext

using Microsoft.Extensions.AI;
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; }
/// <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;
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 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";
}
}