feat: add test inclusion for vectorDB tests in vitest configuration#6358
Conversation
TestGru AssignmentSummary
Tip You can |
|
|
1 similar comment
|
|
Preview mcp_server Image: |
|
Preview sandbox Image: |
Preview fastgpt Image: |
- Enhanced README to clarify the use of factory pattern for vectorDB integration tests. - Updated instructions for setting up environment variables from a local file. - Removed obsolete PG integration test file and adjusted test execution instructions. - Improved structure explanation for shared test data and factory functions.
|
@c121914yu fixed. |
代码审查反馈感谢提交这个向量数据库集成测试的 PR!这是一个非常有价值的改进,为向量数据库层添加了真实环境下的集成测试保证。以下是详细的审查反馈: ✅ 优点
🔍 建议改进1. 测试数据生成逻辑文件: // 当前实现
function makeVector(seed: number): number[] {
const vec: number[] = [];
for (let i = 0; i < VECTOR_DIM; i++) {
vec.push((Math.sin(seed * 1000 + i * 0.1) * 0.5 + 0.5) * 0.01);
}
return vec;
}建议:
改进示例: function makeVector(seed: number): number[] {
const vec: number[] = [];
for (let i = 0; i < VECTOR_DIM; i++) {
// 使用更真实的 embedding 值范围
vec.push(Math.sin(seed * 1000 + i * 0.1));
}
// 归一化
const norm = Math.sqrt(vec.reduce((sum, v) => sum + v * v, 0));
return vec.map(v => v / norm);
}2. 测试超时配置优化文件: 当前超时设置可能不够灵活:
建议:
const TIMEOUT = {
INIT: 30000,
QUERY: 20000, // embRecall 可能更慢
DEFAULT: 15000
};3. 环境变量加载安全性文件: 当前环境变量解析逻辑较为简单,建议增强: // 建议添加
// 1. 处理注释行(行中有 # 的情况)
// 2. 处理空值情况
// 3. 处引号内的等号
// 4. 使用 dotenv 库替代手动解析改进建议: import { config } from 'dotenv';
const envTestLocalPath = path.resolve(process.cwd(), 'test', '.env.test.local');
if (existsSync(envTestLocalPath)) {
config({ path: envTestLocalPath, override: false });
}4. 测试清理策略文件: 当前 afterEach(async () => {
if (!ctrl) return;
try {
await ctrl.delete({
teamId: TEST_TEAM_ID,
datasetIds: [TEST_DATASET_ID],
collectionIds: [TEST_COLLECTION_ID]
});
} catch {
// ignore cleanup errors
}
});建议:
5. 测试覆盖增强文件: `factory.ts) 当前测试用例较为基础,建议增加:
示例: it('embRecall() returns results sorted by score', async () => {
await ctrl.insert({...});
const res = await ctrl.embRecall({...});
for (let i = 1; i < res.results.length; i++) {
expect(res.results[i-1].score).toBeGreaterThanOrEqual(res.results[i].score);
}
});6. 并发测试缺失文件: 建议添加并发场景测试: it.concurrent('handles concurrent insert operations', async () => {
const promises = Array.from({ length: 10 }, (_, i) =>
ctrl.insert({
teamId: TEST_TEAM_ID,
datasetId: TEST_DATASET_ID,
collectionId: TEST_COLLECTION_ID,
vectors: [makeVector(i)]
})
);
await expect(Promise.all(promises)).resolves.not.toThrow();
});
|
* feat(vectordb): add OceanBase HNSW quantization (HNSW_SQ/HNSW_BQ) (#6348) Support OceanBase vector index quantization via VECTOR_VQ_LEVEL: - 32 (default): hnsw + inner_product - 8: hnsw_sq + inner_product (2-3x memory savings) - 1: hnsw_bq + cosine (~15x memory savings) HNSW_BQ requires cosine distance per OceanBase docs. Tested on OceanBase 4.3.5.5 (BP5). Closes #6202 * feat: add test inclusion for vectorDB tests in vitest configuration (#6358) * feat: add test inclusion for vectorDB tests in vitest configuration * refactor: update vectorDB README and setup for environment configuration - Enhanced README to clarify the use of factory pattern for vectorDB integration tests. - Updated instructions for setting up environment variables from a local file. - Removed obsolete PG integration test file and adjusted test execution instructions. - Improved structure explanation for shared test data and factory functions. * perf: integrationTest * feat: vector integration --------- Co-authored-by: ZHANG Yixin <hi.yixinz@gmail.com> Co-authored-by: Jingchao <alswlx@gmail.com>
本 PR 为 FastGPT 增加向量数据库集成测试,用于在真实环境下验证 PGVector 控制器的行为,保证向量相关操作的兼容性和稳定性。
主要改动:
新增
test/vectorDB/目录fixtures.ts:统一测试数据(TEST_TEAM_ID、TEST_DATASET_ID、TEST_COLLECTION_ID及 1536 维向量),供 PG 及后续 Oceanbase、Milvus 复用。pg.integration.test.ts:对PgVectorCtrl的集成测试,覆盖init、insert、getVectorCount、embRecall、getVectorDataByTime、delete,使用真实 PostgreSQL + pgvector,无 mock。README.md:说明环境变量(如PG_URL)及如何运行集成测试。Vitest 配置
vitest.config.mts的test.include中增加test/vectorDB/**/*.test.ts。运行方式:
PG_URL时,该组集成测试会整体跳过,不影响现有单元测试。PG_URL后,可运行:pnpm test test/vectorDB。关联: 关闭 #6194
Title: feat(test): Add vector database integration tests (Issue #6194)
Description:
This PR adds integration tests for FastGPT’s vector database layer, validating the PGVector controller against a real PostgreSQL + pgvector instance to ensure compatibility and stability of vector operations.
Changes:
New
test/vectorDB/directoryfixtures.ts: Shared test data (TEST_TEAM_ID, TEST_DATASET_ID, TEST_COLLECTION_ID, and 1536-dim vectors) for PG and future Oceanbase/Milvus tests.pg.integration.test.ts: Integration tests forPgVectorCtrlcoveringinit,insert,getVectorCount,embRecall,getVectorDataByTime, anddelete; no mocks, uses real DB.README.md: Documents required env vars (e.g.PG_URL) and how to run the tests.Vitest
test/vectorDB/**/*.test.tstotest.includeinvitest.config.mts.How to run:
PG_URL, the vectorDB integration suite is skipped; existing unit tests are unchanged.PG_URLset:pnpm test test/vectorDB.Ref: Closes #6194