Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge PR 4 round-2 lane 4c2 into capy/wave-b-pr4

garrytan072aaeef5145
diff --cc src/core/page-body/segmented-embedding.ts
index e2eaf6707d,bf23588ad0..be0bd7a4ab
--- a/src/core/page-body/segmented-embedding.ts
+++ b/src/core/page-body/segmented-embedding.ts
@@@ -138,12 -138,22 +139,23 @@@ export async function embedSegmentedRow
const tier = plainEmbeddingTier(page.contextual_retrieval_mode);
const provenance = embeddingInputContext(target, page.title, null, []);
return { pending: rows.length, installed: await installSegmentedVectors(engine, page, target, chunks.map((chunk, i) => ({ chunk_index: chunk.chunk_index,
- chunk_text: chunk.chunk_text, vector: vectors[i]!, hash: embeddingInputHash(provenance, tier, chunk) })),
- chunk_text: chunk.chunk_text, vector: vectors[i]!, hash: embeddingInputHash(provenance, tier, chunk), expected: asRead.get(chunk.chunk_index) ?? null })), opts.beforeInstall) };
++ chunk_text: chunk.chunk_text, vector: vectors[i]!, hash: embeddingInputHash(provenance, tier, chunk), expected: asRead.get(chunk.chunk_index) ?? null })),
+ async tx => { await lease.assertHeld(tx); await opts.beforeInstall?.(tx); }) };
}
- /** One vector to install on a segmented page: the row's chunk_index and exact text, and the recorded embedding input. */
- export interface SegmentedVectorUpdate { chunk_index: number; chunk_text: string; vector: Float32Array; hash: string }
+ /** The recorded embedding input of a segmented page's live rows at `chunkIndexes`, as read now (null: none recorded). */
+ async function readChunkInputHashes(engine: Pick<BrainEngine, 'executeRaw'>, pageId: number, chunkIndexes: readonly number[]): Promise<Map<number, string | null>> {
+ const rows = await engine.executeRaw<{ chunk_index: number; embedding_input_hash: string | null }>(
+ `SELECT cc.chunk_index, cc.embedding_input_hash FROM content_chunks cc JOIN pages p ON p.id = cc.page_id
+ WHERE cc.page_id = $1 AND cc.chunk_index = ANY($2::int[]) AND ${chunkGenerationFilter('p', 'cc')}`, [pageId, [...chunkIndexes]]);
+ return new Map(rows.map(row => [Number(row.chunk_index), row.embedding_input_hash]));
+ }
+
+ /**
+ * One vector to install on a segmented page: the row's chunk_index and exact text, the recorded embedding input, and
+ * `expected`, the row's recorded input as the writer read it before building the vector (null: none).
+ */
+ export interface SegmentedVectorUpdate { chunk_index: number; chunk_text: string; vector: Float32Array; hash: string; expected: string | null }
/**
* Install vectors with their recorded inputs on the live rows of a segmented page with the same chunk_index and text,