fix(kbdb): search keyword 補 source filter(#66)+semantic 曝 top_k/min_score、entry 附 score(#67) #70
Reference in New Issue
Block a user
Delete Branch "fix/search-source-filter-and-semantic-threshold"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
修 kbdb
/entries/search兩個已核實檢索缺口(雲端總管交辦,B 類平台維護)。關聯 #66 #67。#66 keyword 路徑 source 參數解析後丟棄
根因:
routes/entries.ts有解析source,但 keyword 分支呼叫的searchEntries(actions/entry-crud.ts)函式簽名根本沒有 source 參數——解析完即丟。#5.1 只接了listEntries那半;semantic 分支走 Vectorize metadata filter 本來就正常,唯獨 keyword 漏。修法:
searchEntries尾端加source?: string(positional 參數不動順序,全 repo grep 過 caller——kbdb route 兩處+測試兩處,既有呼叫點一個都不用改)。listEntries#5.1 同款謂詞:json_extract(metadata_json, '$.source') = ?。#67 semantic 固定 topK=20、零分數閾值
根因:
embed.tstopK: Math.min(opts.topK ?? 20, 100)寫死預設、matches 全量 hydrate 回傳,低分尾硬湊 20 筆全是無關內容;route 也未曝任何參數。修法:
top_k(預設 20、封頂 100)與min_score(預設 0=不過濾)。壞值(非數字/非正)視同沒帶回預設、不 400——與其他 filter「壞值靜默忽略」慣例一致。semanticSearch增min_scoreopt,依score >= min_score截低分尾(過濾放查詢端,Vectorize API 無此參數)。score欄(加欄不改形:entries/count/mode 結構不變,console/portal/rag_chat 既有 caller 不解析多的欄位不受影響)。向後相容
source/top_k/min_score時,SQL 與輸出行為與現況一字不變(semantic 僅多 score 資訊)。metadata_jsonTEXT 欄的 json_extract,零 migration、零 schema 變更。測試(誠實回報)
kbdb/tests/search-source-and-score.test.ts13 條:source 謂詞形狀/route 下傳/semantic 降級仍套 source/min_score 截斷/topK 透傳與封頂 100/壞值防呆/不帶參數行為不變/keyword 不受新參數影響。npx vitest run33/33 全綠(4 檔含既有 20 條無回歸);npx tsc --noEmit0 錯。部署提醒
merge 後需 gated redeploy kbdb worker(leo 閘)——本 PR 不含任何部署動作。
關閉說明(總管):本 PR 的 commit
65d85eb因目錄共用事故已隨 docs push 先行上了 main(總管與 subagent 共用同一 clone、總管push HEAD:main時帶上了分支 commit——流程破口,教訓已記頂層 wiki)。總管已事後逐項審:兩呼叫點 source 傳遞正確、謂詞與 listEntries #5.1 同款、min_score/top_k 向後相容、33/33 測試綠 tsc 零錯——審核通過,main 上的版本留用。#66/#67 保持 open 直到 gated redeploy kbdb worker(leo 閘)+live 驗證後才關。
Pull request closed