Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(ann-build): size only HNSW builds; graduation also defers non-HNSW indexes through the PGLite path
time-attack22c936fc5a1d
diff --git a/src/core/embedding-ann-build.ts b/src/core/embedding-ann-build.tsindex 7798dc967a..bfc30357fc 100644--- a/src/core/embedding-ann-build.ts+++ b/src/core/embedding-ann-build.ts@@ -24,6 +24,7 @@ export interface DeferredAnnIndex { name: string; def: string }export const ANN_BUILD_MESSAGE = 'building vector index after re-embed (search runs unindexed until done)';+const HNSW_TARGET = / ON (?:ONLY )?(?:public\.)?([a-z_][a-z0-9_]*) USING hnsw \(([a-z_][a-z0-9_]*) /;const ANN_DEF = /^CREATE INDEX (?:IF NOT EXISTS )?([a-z_][a-z0-9_]{0,62}) ON (?:public\.)?([a-z_][a-z0-9_]*) USING hnsw \(embedding (?:vector|halfvec)_(?:cosine|l2|ip)_ops\)(?: WITH \([a-z_]+ ?= ?'?[0-9]+'?(?:, ?[a-z_]+ ?= ?'?[0-9]+'?)*\))?(?: WHERE [A-Za-z0-9_ ().,:<>=!'-]+)?$/;/**@@ -115,8 +116,10 @@ export async function buildDeferredAnnIndexes(});} else {if (validity === false) await engine.executeRaw(`DROP INDEX IF EXISTS ${next.name}`);- await withHnswBuildMemory(engine, ANN_DEF.exec(next.def)![2]!, 'embedding', () =>- engine.executeRaw(next.def.replace(/^CREATE INDEX (?:IF NOT EXISTS )?/, 'CREATE INDEX IF NOT EXISTS ')));+ const create = () => engine.executeRaw(next.def.replace(/^CREATE INDEX (?:IF NOT EXISTS )?/, 'CREATE INDEX IF NOT EXISTS '));+ // Graduation also defers non-HNSW indexes through here; only an HNSW build is sized.+ const hnsw = HNSW_TARGET.exec(next.def);+ await (hnsw ? withHnswBuildMemory(engine, hnsw[1]!, hnsw[2]!, create) : create());}if (await annIndexValidity(engine, next.name) !== true) {throw new Error(`vector index ${next.name} is not valid after its build; rerun the migration to rebuild it`);