- 添加HNSW向量索引提升检索性能 - 实现Hybrid检索模式支持向量和关键词双路召回 - 采用RRF算法融合多路召回结果 - 支持ParentChild分块模式的上下文回填 - 优化向量写入采用批量SQL操作提升性能 - 添加RAG PostgreSQL连接字符串配置 - 更新部署脚本增加PGVector集成测试 - 修正表名引用从document_chunks到b_document_chunks - 重构RagRetrievalService实现完整的检索流程 - 增加重排策略支持关键词和LLM重排 - 修改服务器部署地址配置
42 lines
1.6 KiB
C#
42 lines
1.6 KiB
C#
using BuildFlow.Application.Document.Handlers;
|
||
using BuildFlow.Application.Document.Queries;
|
||
using BuildFlow.Infrastructure.Persistence;
|
||
using BuildFlow.Shared.Domain.Errors;
|
||
using BuildFlow.Shared.Domain.Exceptions;
|
||
using FluentAssertions;
|
||
using Microsoft.EntityFrameworkCore;
|
||
using Xunit;
|
||
|
||
namespace BuildFlow.Rag.Tests;
|
||
|
||
/// <summary>
|
||
/// Get 文档分块查询处理器测试。
|
||
/// 注意:该 Handler 在取回分块后执行 raw SQL(针对 b_document_chunks),依赖真实关系型(Postgres)库;
|
||
/// 当前存在已知 P0 表名漂移(document_chunks vs b_document_chunks),此处仅覆盖「依赖调用之前」的
|
||
/// 文档不存在→NotFound 前置分支,不假设该 bug 已修复,raw SQL 分支交由集成测试覆盖。
|
||
/// </summary>
|
||
public class GetDocumentChunksQueryHandlerTests
|
||
{
|
||
[Fact]
|
||
public async Task Handle_DocumentNotFound_ThrowsNotFound()
|
||
{
|
||
await using var db = CreateDb();
|
||
var handler = new GetDocumentChunksQueryHandler(db);
|
||
|
||
var act = async () => await handler.Handle(
|
||
new GetDocumentChunksQuery(Guid.NewGuid()), CancellationToken.None);
|
||
var ex = await act.Should().ThrowAsync<NotFoundException>();
|
||
ex.Which.Code.Should().Be(ErrorCode.NotFound);
|
||
}
|
||
|
||
private static RagDbContext CreateDb()
|
||
{
|
||
var options = new DbContextOptionsBuilder<RagDbContext>()
|
||
.UseInMemoryDatabase($"rag-get-chunks-{Guid.NewGuid():N}")
|
||
.Options;
|
||
var db = new RagDbContext(options);
|
||
db.SavingChanges += (_, _) => RagTestDb.FillAudit(db);
|
||
return db;
|
||
}
|
||
}
|