From 61aa91b3aa9c19966e25ae32fd5e6412bebd3dc7 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Fri, 18 Apr 2025 19:31:02 +0800 Subject: [PATCH] perf: hnsw query (#4596) * perf: hnsw query * check response embedding recall result --- docSite/content/zh-cn/docs/development/upgrading/497.md | 3 ++- packages/service/common/vectorStore/pg/class.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/497.md b/docSite/content/zh-cn/docs/development/upgrading/497.md index fe3f65c97..1e073a182 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/497.md +++ b/docSite/content/zh-cn/docs/development/upgrading/497.md @@ -12,7 +12,8 @@ weight: 793 ## ⚙️ 优化 -1. Doc2x 文档解析,增加报错信息捕获,增加超时时长 +1. Doc2x 文档解析,增加报错信息捕获,增加超时时长。 +2. 调整 PG vector 查询语句,强制使用向量索引。 ## 🐛 修复 diff --git a/packages/service/common/vectorStore/pg/class.ts b/packages/service/common/vectorStore/pg/class.ts index 39287630a..cb18440e9 100644 --- a/packages/service/common/vectorStore/pg/class.ts +++ b/packages/service/common/vectorStore/pg/class.ts @@ -192,8 +192,7 @@ export class PgVectorCtrl { WITH relaxed_results AS MATERIALIZED ( select id, collection_id, vector <#> '[${vector}]' AS score from ${DatasetVectorTableName} - where team_id='${teamId}' - AND dataset_id IN (${datasetIds.map((id) => `'${String(id)}'`).join(',')}) + where dataset_id IN (${datasetIds.map((id) => `'${String(id)}'`).join(',')}) ${filterCollectionIdSql} ${forbidCollectionSql} order by score limit ${limit} @@ -202,6 +201,12 @@ export class PgVectorCtrl { ); const rows = results?.[3]?.rows as PgSearchRawType[]; + if (!Array.isArray(rows)) { + return { + results: [] + }; + } + return { results: rows.map((item) => ({ id: String(item.id),