Переехали на графовую модель, засунули все в докер, поменяли парсинг

This commit is contained in:
2026-07-23 08:34:26 +04:00
parent c503fc4990
commit b2a13528ee
14 changed files with 420 additions and 204 deletions

View File

@@ -1,20 +1,28 @@
using CodeBase.Services;
using CodeBase.Warehouse;
using Qdrant.Client;
using Qdrant.Client.Grpc;
using Microsoft.Build.Locator;
using Neo4j.Driver;
if (!MSBuildLocator.IsRegistered)
{
MSBuildLocator.RegisterDefaults();
}
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddSingleton(new QdrantClient("localhost", 6334));
builder.Services.AddSingleton<IDriver>(sp =>
GraphDatabase.Driver(
"bolt://localhost:7687",
AuthTokens.Basic("neo4j", "password123")
)
);
builder.Services.AddSingleton<ChunkWarehouse>();
builder.Services.AddTransient<VectorizationService>();
builder.Services.AddTransient<LlmService>();
builder.Services.AddScoped<LlmPromptBuilder>();
builder.Services.AddTransient<ChunkService>();
builder.Services.AddTransient<CodeService>();
builder.Services.AddTransient<QdrantRepository>();
builder.Services.AddTransient<GraphRepository>();
builder.Services.AddControllers();
builder.Services.AddSwaggerGen();
@@ -34,27 +42,12 @@ app.UseAuthorization();
app.MapControllers();
using (var scope = app.Services.CreateScope())
{
var qdrantClient = scope.ServiceProvider.GetRequiredService<QdrantClient>();
// Получаем список существующих коллекций
var collections = await qdrantClient.ListCollectionsAsync();
if (!collections.Contains("CodeBaseCollection"))
{
Console.WriteLine("Создаем новую коллекцию в Qdrant...");
await qdrantClient.CreateCollectionAsync(
collectionName: "CodeBaseCollection",
vectorsConfig: new VectorParams
{
Size = 768, // Размер вектора GraphCodeBERT
Distance = Distance.Cosine // Сразу задаем алгоритм поиска (косинусное сходство)
}
);
}
var graphRepo = scope.ServiceProvider.GetRequiredService<GraphRepository>();
Console.WriteLine("Проверяем и создаем векторный индекс в Neo4j...");
await graphRepo.InitializeDbAsync();
Console.WriteLine("Индекс готов!");
}
app.Run();