fix: unificar settings
This commit is contained in:
parent
9a1d75aaf8
commit
caf50d9d7f
@ -1,5 +1,6 @@
|
||||
using ChatApi;
|
||||
using ChatRAG.Models;
|
||||
using ChatRAG.Settings.ChatRAG.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
|
||||
@ -10,16 +11,16 @@ namespace ChatRAG.Data
|
||||
private readonly IMongoCollection<Project> _textsCollection;
|
||||
|
||||
public ProjectDataRepository(
|
||||
IOptions<DomvsDatabaseSettings> databaseSettings)
|
||||
IOptions<VectorDatabaseSettings> databaseSettings)
|
||||
{
|
||||
var mongoClient = new MongoClient(
|
||||
databaseSettings.Value.ConnectionString);
|
||||
databaseSettings.Value.MongoDB.ConnectionString);
|
||||
|
||||
var mongoDatabase = mongoClient.GetDatabase(
|
||||
databaseSettings.Value.DatabaseName);
|
||||
databaseSettings.Value.MongoDB.DatabaseName);
|
||||
|
||||
_textsCollection = mongoDatabase.GetCollection<Project>(
|
||||
databaseSettings.Value.ProjectCollectionName);
|
||||
databaseSettings.Value.MongoDB.ProjectCollectionName);
|
||||
}
|
||||
|
||||
public async Task<List<Project>> GetAsync() =>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using ChatApi;
|
||||
using ChatRAG.Models;
|
||||
using ChatRAG.Settings.ChatRAG.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
@ -11,16 +12,16 @@ namespace ChatRAG.Data
|
||||
private readonly IMongoCollection<TextoComEmbedding> _textsCollection;
|
||||
|
||||
public TextDataRepository(
|
||||
IOptions<DomvsDatabaseSettings> bookStoreDatabaseSettings)
|
||||
IOptions<VectorDatabaseSettings> vectorStoreDatabaseSettings)
|
||||
{
|
||||
var mongoClient = new MongoClient(
|
||||
bookStoreDatabaseSettings.Value.ConnectionString);
|
||||
vectorStoreDatabaseSettings.Value.MongoDB.ConnectionString);
|
||||
|
||||
var mongoDatabase = mongoClient.GetDatabase(
|
||||
bookStoreDatabaseSettings.Value.DatabaseName);
|
||||
vectorStoreDatabaseSettings.Value.MongoDB.DatabaseName);
|
||||
|
||||
_textsCollection = mongoDatabase.GetCollection<TextoComEmbedding>(
|
||||
bookStoreDatabaseSettings.Value.TextCollectionName);
|
||||
vectorStoreDatabaseSettings.Value.MongoDB.TextCollectionName);
|
||||
}
|
||||
|
||||
public IMongoCollection<TextoComEmbedding> GetCollection()
|
||||
@ -32,7 +33,7 @@ namespace ChatRAG.Data
|
||||
await _textsCollection.Find(_ => true).ToListAsync();
|
||||
|
||||
public async Task<List<TextoComEmbedding>> GetByProjectIdAsync(string projectId) =>
|
||||
await _textsCollection.Find(s => s.ProjetoId == ObjectId.Parse(projectId).ToString()).ToListAsync();
|
||||
await _textsCollection.Find(s => s.ProjetoId == projectId).ToListAsync();
|
||||
|
||||
public async Task<TextoComEmbedding?> GetAsync(string id) =>
|
||||
await _textsCollection.Find(x => x.Id == id).FirstOrDefaultAsync();
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using ChatApi.Models;
|
||||
using ChatRAG.Settings.ChatRAG.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
|
||||
@ -9,16 +10,16 @@ namespace ChatApi
|
||||
private readonly IMongoCollection<UserData> _userCollection;
|
||||
|
||||
public UserDataRepository(
|
||||
IOptions<DomvsDatabaseSettings> bookStoreDatabaseSettings)
|
||||
IOptions<VectorDatabaseSettings> vectorStoreDatabaseSettings)
|
||||
{
|
||||
var mongoClient = new MongoClient(
|
||||
bookStoreDatabaseSettings.Value.ConnectionString);
|
||||
vectorStoreDatabaseSettings.Value.MongoDB.ConnectionString);
|
||||
|
||||
var mongoDatabase = mongoClient.GetDatabase(
|
||||
bookStoreDatabaseSettings.Value.DatabaseName);
|
||||
vectorStoreDatabaseSettings.Value.MongoDB.DatabaseName);
|
||||
|
||||
_userCollection = mongoDatabase.GetCollection<UserData>(
|
||||
bookStoreDatabaseSettings.Value.UserDataName);
|
||||
vectorStoreDatabaseSettings.Value.MongoDB.UserDataName);
|
||||
}
|
||||
|
||||
public async Task<List<UserData>> GetAsync() =>
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
namespace ChatApi
|
||||
{
|
||||
public class DomvsDatabaseSettings
|
||||
{
|
||||
public string ConnectionString { get; set; } = null!;
|
||||
|
||||
public string DatabaseName { get; set; } = null!;
|
||||
|
||||
public string TextCollectionName { get; set; } = null!;
|
||||
|
||||
public string UserDataName { get; set; } = null!;
|
||||
|
||||
public string ProjectCollectionName { get; set; } = null!;
|
||||
|
||||
}
|
||||
}
|
||||
18
Program.cs
18
Program.cs
@ -10,6 +10,7 @@ using ChatRAG.Services;
|
||||
using ChatRAG.Services.Contracts;
|
||||
using ChatRAG.Services.ResponseService;
|
||||
using ChatRAG.Services.SearchVectors;
|
||||
using ChatRAG.Settings.ChatRAG.Configuration;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
@ -73,9 +74,6 @@ builder.Services.AddSwaggerGen(c =>
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.Configure<DomvsDatabaseSettings>(
|
||||
builder.Configuration.GetSection("DomvsDatabase"));
|
||||
|
||||
builder.Services.Configure<ChatRHSettings>(
|
||||
builder.Configuration.GetSection("ChatRHSettings"));
|
||||
|
||||
@ -105,7 +103,11 @@ builder.Services.AddSingleton<CryptUtil>();
|
||||
//var apiClient = new OllamaApiClient(new Uri("http://localhost:11435"), "tinydolphin");
|
||||
|
||||
//Olllama
|
||||
builder.Services.AddOllamaChatCompletion("llama3.2", new Uri("http://localhost:11434"));
|
||||
//Desktop
|
||||
//builder.Services.AddOllamaChatCompletion("llama3.2", new Uri("http://localhost:11434"));
|
||||
//Notebook
|
||||
builder.Services.AddOllamaChatCompletion("llama3.2:3b", new Uri("http://localhost:11435"));
|
||||
|
||||
|
||||
//builder.Services.AddOllamaChatCompletion("tinydolphin", new Uri("http://localhost:11435"));
|
||||
//builder.Services.AddOllamaChatCompletion("tinyllama", new Uri("http://localhost:11435"));
|
||||
@ -118,7 +120,13 @@ builder.Services.AddOllamaChatCompletion("llama3.2", new Uri("http://localhost:1
|
||||
//builder.Services.AddOllamaChatCompletion("llama3.1:latest", new Uri("http://192.168.0.150:11434"));
|
||||
|
||||
//builder.Services.AddOllamaTextEmbeddingGeneration("all-minilm", new Uri("http://192.168.0.150:11434"));
|
||||
builder.Services.AddOllamaTextEmbeddingGeneration("all-minilm", new Uri("http://localhost:11434"));
|
||||
|
||||
//Desktop
|
||||
//builder.Services.AddOllamaTextEmbeddingGeneration("all-minilm", new Uri("http://localhost:11434"));
|
||||
//Notebook
|
||||
builder.Services.AddOllamaTextEmbeddingGeneration("all-minilm", new Uri("http://localhost:11435"));
|
||||
|
||||
|
||||
//builder.Services.AddOllamaChatCompletion("phi3.5", new Uri("http://localhost:11435"));
|
||||
//builder.Services.AddOpenAIChatCompletion("gpt-4o-mini", "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");
|
||||
//builder.Services.AddGoogleAIGeminiChatCompletion("gemini-1.5-flash-latest", "AIzaSyDKBMX5yW77vxJFVJVE-5VLxlQRxCepck8");
|
||||
|
||||
@ -30,9 +30,17 @@ namespace ChatRAG.Services.SearchVectors
|
||||
int limit = 5,
|
||||
Dictionary<string, object>? filters = null)
|
||||
{
|
||||
var textos = string.IsNullOrEmpty(projectId)
|
||||
List<TextoComEmbedding> textos = null;
|
||||
try
|
||||
{
|
||||
textos = string.IsNullOrEmpty(projectId)
|
||||
? await _textDataRepository.GetAsync()
|
||||
: await _textDataRepository.GetByProjectIdAsync(projectId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Erro ao buscar documentos: {ex.Message}");
|
||||
}
|
||||
|
||||
var resultados = textos
|
||||
.Select(texto => new VectorSearchResult
|
||||
|
||||
@ -14,19 +14,19 @@
|
||||
}
|
||||
},
|
||||
"VectorDatabase": {
|
||||
"Provider": "MongoDB", // 👈 Mude para "Qdrant" quando quiser testar
|
||||
"Provider": "Qdrant", // 👈 Mude para "Qdrant" quando quiser testar
|
||||
"MongoDB": {
|
||||
"ConnectionString": "sua_connection_string_atual",
|
||||
"DatabaseName": "seu_database_atual",
|
||||
"TextCollectionName": "seu_collection_atual",
|
||||
"ProjectCollectionName": "seu_project_collection",
|
||||
"UserDataName": "seu_user_collection"
|
||||
"ConnectionString": "mongodb://admin:c4rn31r0@k3sw2:27017,k3ss1:27017/?authSource=admin",
|
||||
"DatabaseName": "RAGProjects-dev-en",
|
||||
"TextCollectionName": "Texts",
|
||||
"ProjectCollectionName": "Groups",
|
||||
"UserDataName": "UserData"
|
||||
},
|
||||
"Qdrant": {
|
||||
"Host": "localhost",
|
||||
"Port": 6334,
|
||||
"CollectionName": "documents",
|
||||
"VectorSize": 1536,
|
||||
"CollectionName": "texts",
|
||||
"VectorSize": 384,
|
||||
"Distance": "Cosine",
|
||||
"HnswM": 16,
|
||||
"HnswEfConstruct": 200,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user