Revert "WIP(kbdb): 語意搜尋零命中的排查——⚠️ 被總管中途叫停,未完成驗證"

This reverts commit af3edff856.
This commit is contained in:
uncle6me-web
2026-08-11 23:18:38 +08:00
parent af3edff856
commit 7e3ca4c1a1
6 changed files with 25 additions and 332 deletions
@@ -107,80 +107,3 @@ describe('GET /entries/search?mode=semantic — 零命中時分辨「為什麼
expect(body.capability_hint).toBeUndefined();
});
});
// ── 第四態 filter_blindArcrun#85 D702026-08-11 leo21c 實撞)─────────────────
//
// 現場:現役 Vectorize index `arcrun-kbdb-embed-m3` 上**一個 metadata index 都沒有**
// (真兇=arcrun-rag 安裝器把端點寫成 `metadata-index/create`,連字號版 CF 回 404
// 底線 `metadata_index/create` 才是對的;而該安裝器把失敗降級成一行 ⚠ 就宣告成功)。
// ⇒ Vectorize 對 owner_id 下 filter 一律回 0 筆,而**每一條真實使用者路徑都帶 owner_id**
// 做租戶隔離 ⇒ 語意搜尋 100% 全盲。
// 實測(leo21c,同一句查詢):不帶 filter → 1 命中 score 0.8957;帶 owner_id → 0 命中。
//
// 舊行為把這個歸成 no_match,回「換個說法或更具體的關鍵字再試試看」
// =**把系統故障說成使用者的問題**,正是 leo 2026-08-09 直令禁止的那件事,
// 而且沒有人會因為「搜不到」去翻 Cloudflare 的 Vectorize 設定。
function makeFilterAwareEnv(
dbOpts: Parameters<typeof makeFakeDB>[0],
opts: { unfiltered: { id: string; score: number }[]; filtered: { id: string; score: number }[] },
): Bindings {
return {
DB: makeFakeDB(dbOpts),
ENVIRONMENT: 'test',
AI: { async run() { return { data: [[0.1, 0.2, 0.3]] }; } },
VECTORIZE: {
async query(_v: number[], o?: { filter?: Record<string, unknown> }) {
const filtered = !!(o?.filter && Object.keys(o.filter).length > 0);
return { matches: filtered ? opts.filtered : opts.unfiltered };
},
},
} as unknown as Bindings;
}
describe('empty_reason=filter_blind — Vectorize metadata 過濾整個是死的', () => {
it('帶 owner_id 零命中、拿掉 filter 有命中 → filter_blind,且照實說是我們的故障', async () => {
const app = makeApp();
const env = makeFilterAwareEnv(
{ embeddedCount: 805, hydrateEntry: mkEntry('e1') },
{ unfiltered: [{ id: 'e1', score: 0.8957 }], filtered: [] },
);
const res = await app.request('/entries/search?q=黑面琵鷺&mode=semantic&owner_id=bfezv28v', {}, env);
const body = (await res.json()) as Record<string, unknown>;
expect(body.count).toBe(0);
expect(body.empty_reason).toBe('filter_blind');
const hint = body.capability_hint as string;
// 🔴 誠實鐵律:是故障、不是使用者的錯,且**明說換個說法沒有用**
expect(hint).toContain('故障');
expect(hint).toContain('不是你');
expect(/換個說法也不會有用/.test(hint)).toBe(true);
// 🔴 人話紅線:不准把 Vectorize/owner_id 這類內部詞漏給使用者
expect(/vectorize|owner_id|metadata|index/i.test(hint)).toBe(false);
// 技術細節與**處方順序**留給維運者
const admin = body.admin_hint as string;
expect(admin).toContain('metadata index');
expect(admin).toContain('reindex');
});
it('沒帶任何 filter 的查詢不做探針,維持 no_match(不多花一次查詢)', async () => {
const app = makeApp();
let queries = 0;
const env = {
DB: makeFakeDB({ embeddedCount: 42 }),
ENVIRONMENT: 'test',
AI: { async run() { return { data: [[0.1, 0.2, 0.3]] }; } },
VECTORIZE: { async query() { queries++; return { matches: [] }; } },
} as unknown as Bindings;
const res = await app.request('/entries/search?q=x&mode=semantic', {}, env);
const body = (await res.json()) as Record<string, unknown>;
expect(body.empty_reason).toBe('no_match');
expect(queries).toBe(1);
});
it('帶 filter 但拿掉 filter 也零命中 → 仍是 no_match(別把正常的找不到誣賴成故障)', async () => {
const app = makeApp();
const env = makeFilterAwareEnv({ embeddedCount: 42 }, { unfiltered: [], filtered: [] });
const res = await app.request('/entries/search?q=x&mode=semantic&owner_id=t1', {}, env);
const body = (await res.json()) as Record<string, unknown>;
expect(body.empty_reason).toBe('no_match');
});
});