- 添加HNSW向量索引提升检索性能 - 实现Hybrid检索模式支持向量和关键词双路召回 - 采用RRF算法融合多路召回结果 - 支持ParentChild分块模式的上下文回填 - 优化向量写入采用批量SQL操作提升性能 - 添加RAG PostgreSQL连接字符串配置 - 更新部署脚本增加PGVector集成测试 - 修正表名引用从document_chunks到b_document_chunks - 重构RagRetrievalService实现完整的检索流程 - 增加重排策略支持关键词和LLM重排 - 修改服务器部署地址配置
38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using BuildFlow.Infrastructure.Persistence;
|
||
using BuildFlow.Shared.Domain.Common;
|
||
using Microsoft.EntityFrameworkCore;
|
||
|
||
namespace BuildFlow.Rag.Tests;
|
||
|
||
/// <summary>Rag 模块测试数据库工厂,使用独立 InMemory 数据库并自动补齐审计字段(IAuditable / IHasOperatorIP)。</summary>
|
||
internal static class RagTestDb
|
||
{
|
||
public static RagDbContext Create([System.Runtime.CompilerServices.CallerMemberName] string testName = "")
|
||
{
|
||
var options = new DbContextOptionsBuilder<RagDbContext>()
|
||
.UseInMemoryDatabase($"rag-{testName}-{Guid.NewGuid()}")
|
||
.Options;
|
||
var db = new RagDbContext(options);
|
||
db.SavingChanges += (_, _) => FillAudit(db);
|
||
return db;
|
||
}
|
||
|
||
/// <summary>兜底补齐审计字段,供各测试文件的 CreateDb() 直接挂载 SavingChanges 事件。</summary>
|
||
public static void FillAudit(RagDbContext db)
|
||
{
|
||
foreach (var entry in db.ChangeTracker.Entries())
|
||
{
|
||
if (entry.Entity is IAuditable auditable)
|
||
{
|
||
auditable.CreatedBy ??= "test";
|
||
auditable.UpdatedBy ??= "test";
|
||
if (auditable.CreatedAt == default) auditable.CreatedAt = DateTime.UtcNow;
|
||
if (auditable.UpdatedAt == default) auditable.UpdatedAt = DateTime.UtcNow;
|
||
}
|
||
|
||
if (entry.Entity is IHasOperatorIP operatorEntity)
|
||
operatorEntity.OperatorIP ??= "127.0.0.1";
|
||
}
|
||
}
|
||
}
|