Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

belief: one-statement state read; index-driven link, transition and fact reads (idx_facts_belief_stream, built online by v249); reuse pre-read fingerprints

garrytan7bea1fa4dc0f
diff --git a/src/core/belief/ledger.ts b/src/core/belief/ledger.ts
index 6e2d22e9c1..6760652d85 100644
--- a/src/core/belief/ledger.ts
+++ b/src/core/belief/ledger.ts
@@ -356,7 +356,7 @@ function pageDrafts(d: DiffContext, stream: Stream, lifetime: string, after: Sub
/** Appends the batch's events, last in its transaction. */
export async function finalizeBeliefEvents(tx: BrainEngine, batch: Batch): Promise<number> {
const { opts, pre } = batch;
- const post = await readBeliefState(tx, opts.sourceId, opts.slugs, pre.pages.map(p => p.id));
+ const post = await readBeliefState(tx, opts.sourceId, opts.slugs, pre.pages.map(p => p.id), pre);
const streams = matchStreams(opts.slugs, pre, post);
const added = streams.filter(s => s.post && !opts.slugs.includes(s.post.slug)).map(s => ({ sourceId: opts.sourceId, slug: s.post!.slug }));
if (added.length) assertHeldPageKeys(tx, added);
diff --git a/src/core/belief/schema.ts b/src/core/belief/schema.ts
index ce4e5b13da..2b4d5879e9 100644
--- a/src/core/belief/schema.ts
+++ b/src/core/belief/schema.ts
@@ -96,3 +96,14 @@ ${RLS('belief_redactions')}
/** Migration-only: purge serializes on this counter; the ledger refuses a payload prepared under an older epoch. */
export const BELIEF_SOURCE_COLUMNS_SQL = `ALTER TABLE sources ADD COLUMN IF NOT EXISTS purge_epoch BIGINT NOT NULL DEFAULT 0;`;
+
+/**
+ * The batch state read selects a stream's active facts by `source_markdown_slug` (the fence facts and file-less
+ * facts filed on a page); without this index that is a scan of the source's facts on every write. Built online by
+ * v249's handler (Postgres CONCURRENTLY).
+ */
+export const BELIEF_FACTS_STREAM_INDEX = {
+ name: 'idx_facts_belief_stream',
+ table: 'facts',
+ sql: 'CREATE INDEX IF NOT EXISTS idx_facts_belief_stream ON facts (source_id, source_markdown_slug) WHERE expired_at IS NULL',
+};
diff --git a/src/core/belief/state.ts b/src/core/belief/state.ts
index a2a8aa2229..1e6a02dbdf 100644
--- a/src/core/belief/state.ts
+++ b/src/core/belief/state.ts
@@ -10,7 +10,6 @@
* rewritten with identical values, renumbered, re-inserted) yields no event.
*/
import type { BrainEngine } from '../engine.ts';
-import { pipelined } from '../page-state/transactions.ts';
import { privatePagesFilterFragment } from '../search/private-visibility.ts';
import { PAGE_INLINE_MAX_BYTES } from '../page-size-policy.ts';
@@ -45,62 +44,75 @@ export interface RawState { pages: RawPage[]; facts: RawFact[]; takes: RawTake[]
const iso = (value: unknown): string | null => value == null ? null : new Date(value as string).toISOString();
const num = (value: unknown): number | null => value == null ? null : Number(value);
-const ENDPOINT = (alias: string, as: string) =>
- `${alias}.id AS ${as}_id, ${alias}.slug AS ${as}_slug, ${alias}.source_id AS ${as}_source, ${as}s.incarnation::text AS ${as}_inc`;
-const endpoint = (row: Record<string, unknown>, as: string): RawEndpoint | null => row[`${as}_id`] == null ? null
- : { id: Number(row[`${as}_id`]), slug: String(row[`${as}_slug`]), source_id: String(row[`${as}_source`]), incarnation: String(row[`${as}_inc`]) };
+const ENDS = 'from_page_id, to_page_id, origin_page_id';
+/**
+ * The rows a page set owns (its origin, or its from-page when it has no origin), as two index scans. Kept as a
+ * subquery with OFFSET 0 so the planner drives the endpoint joins from these few rows instead of joining pages first.
+ */
+const OWNED_ROWS = (table: 'links' | 'link_transitions', ids: string, columns = '*') => `SELECT ${columns} FROM ${table} WHERE origin_page_id = ANY(${ids})
+ UNION ALL SELECT ${columns} FROM ${table} WHERE origin_page_id IS NULL AND from_page_id = ANY(${ids}) OFFSET 0`;
/**
* One pipeline of five reads. `slugs` select the stream pages and the facts
* keyed to them; `pageIds` add pages by id (a renamed page is found at its new
* slug); `factIds`/`takeIds` add rows a guard named that live in another stream.
*/
-export async function readBeliefState(tx: BrainEngine, sourceId: string, slugs: readonly string[], pageIds: readonly number[] = []): Promise<RawState> {
- const pageRows = await tx.executeRaw<Record<string, unknown>>(`SELECT p.id, p.slug, p.deleted_at IS NOT NULL AS deleted, p.knowledge_revision::text AS revision,
+export async function readBeliefState(tx: BrainEngine, sourceId: string, slugs: readonly string[], pageIds: readonly number[] = [], known?: RawState): Promise<RawState> {
+ // One statement: each part selects the batch's pages itself ($1 source, $2 slugs, $3 page ids) and returns its rows as JSON.
+ // Fingerprints of claim texts `known` (the batch's pre-read) already has are not recomputed: the SQL fingerprint
+ // is most of a large page's read.
+ const knownFp = new Map<string, string>([...(known?.facts ?? []).map(f => [f.fact, f.fp] as const), ...(known?.takes ?? []).map(k => [k.claim, k.claim_fp] as const)]);
+ const params = [sourceId, [...slugs], [...pageIds], [...knownFp.keys()]];
+ const STREAM_SLUGS = `$2::text[] || ARRAY(SELECT p.slug FROM pages p WHERE p.source_id = $1 AND p.id = ANY($3::int[]))`;
+ const PAGE_IDS = `ARRAY(SELECT p.id FROM pages p WHERE p.source_id = $1 AND (p.slug = ANY($2::text[]) OR p.id = ANY($3::int[])))`;
+ const [row] = await tx.executeRaw<Record<string, Record<string, unknown>[]>>(`SELECT
+ (SELECT COALESCE(json_agg(q), '[]'::json) FROM (
+SELECT p.id, p.slug, p.deleted_at IS NOT NULL AS deleted, p.knowledge_revision::text AS revision,
p.content_hash, p.trust_tier, (${privatePagesFilterFragment('p')}) AS visible, s.incarnation::text AS incarnation,
(p.body_storage = 'segmented' OR octet_length(COALESCE(p.compiled_truth,'')) + octet_length(COALESCE(p.timeline,'')) > ${PAGE_INLINE_MAX_BYTES}) AS large,
current_setting('gbrain.write_trust_tier', true) AS writer_tier
FROM pages p JOIN sources s ON s.id = p.source_id
- WHERE p.source_id = $1 AND (p.slug = ANY($2::text[]) OR p.id = ANY($3::int[]))`, [sourceId, [...slugs], [...pageIds]]);
- const pages: RawPage[] = pageRows.map(r => ({ id: Number(r.id), slug: String(r.slug), deleted: r.deleted === true, revision: String(r.revision),
- content_hash: (r.content_hash as string | null) ?? null, tier: String(r.trust_tier), visible: r.visible === true, large: r.large === true,
- incarnation: String(r.incarnation) }));
- const ids = pages.map(p => p.id);
- const allSlugs = [...new Set([...slugs, ...pages.map(p => p.slug)])];
- const [facts, takes, links, transitions] = await pipelined(tx, [
- () => tx.executeRaw<Record<string, unknown>>(`SELECT f.id, f.entity_slug, f.source_markdown_slug AS sms, pe.id AS entity_page_id, f.fact,
- gbrain_fact_fingerprint(f.fact) AS fp, f.kind, f.visibility, f.notability, f.context, f.confidence::text AS confidence,
+ WHERE p.source_id = $1 AND (p.slug = ANY($2::text[]) OR p.id = ANY($3::int[]))) q) AS pages,
+ (SELECT COALESCE(json_agg(q), '[]'::json) FROM (
+SELECT f.id, f.entity_slug, f.source_markdown_slug AS sms, pe.id AS entity_page_id, f.fact,
+ CASE WHEN f.fact = ANY($4::text[]) THEN NULL ELSE gbrain_fact_fingerprint(f.fact) END AS fp, f.kind, f.visibility, f.notability, f.context, f.confidence::text AS confidence,
f.valid_from, f.valid_until, f.claim_metric, f.claim_value::text AS claim_value, f.claim_unit, f.claim_period, f.event_type,
f.dimension, f.value, f.value_hash, f.row_num, f.trust_tier
- FROM facts f LEFT JOIN pages pe ON pe.source_id = f.source_id AND pe.slug = f.entity_slug
- WHERE f.source_id = $1 AND f.expired_at IS NULL
- AND (f.source_markdown_slug = ANY($2::text[]) OR (f.source_markdown_slug IS NULL AND f.entity_slug = ANY($2::text[])))`, [sourceId, allSlugs]),
- () => ids.length ? tx.executeRaw<Record<string, unknown>>(`SELECT k.id, k.page_id, k.row_num, k.claim, gbrain_fact_fingerprint(k.claim) AS claim_fp,
+ FROM (SELECT * FROM facts WHERE source_id = $1 AND expired_at IS NULL AND source_markdown_slug = ANY(${STREAM_SLUGS})
+ UNION ALL SELECT * FROM facts WHERE source_id = $1 AND expired_at IS NULL AND source_markdown_slug IS NULL AND entity_slug = ANY(${STREAM_SLUGS})) f
+ LEFT JOIN pages pe ON pe.source_id = f.source_id AND pe.slug = f.entity_slug) q) AS facts,
+ (SELECT COALESCE(json_agg(q), '[]'::json) FROM (
+SELECT k.id, k.page_id, k.row_num, k.claim, CASE WHEN k.claim = ANY($4::text[]) THEN NULL ELSE gbrain_fact_fingerprint(k.claim) END AS claim_fp,
k.kind, k.holder, k.weight::text AS weight, k.since_date, k.until_date, k.source, k.active, k.resolved_at, k.resolved_outcome,
k.resolved_value::text AS resolved_value, k.resolved_unit, k.resolved_source, k.resolved_by, k.resolved_quality, k.trust_tier
- FROM takes k WHERE k.page_id = ANY($1::int[])`, [ids]) : Promise.resolve([]),
- () => ids.length ? tx.executeRaw<Record<string, unknown>>(`SELECT l.id, ${ENDPOINT('f', 'f')}, ${ENDPOINT('t', 't')}, ${ENDPOINT('o', 'o')},
+ FROM takes k WHERE k.page_id = ANY(${PAGE_IDS})) q) AS takes,
+ (SELECT COALESCE(json_agg(q), '[]'::json) FROM (
+SELECT l.id, l.from_page_id AS f, l.to_page_id AS t, l.origin_page_id AS o,
l.link_type, l.link_source, l.context, l.origin_field, l.link_kind, l.resolution_type, l.assertion_tense
- FROM links l JOIN pages f ON f.id = l.from_page_id JOIN sources fs ON fs.id = f.source_id
- JOIN pages t ON t.id = l.to_page_id JOIN sources ts ON ts.id = t.source_id
- LEFT JOIN pages o ON o.id = l.origin_page_id LEFT JOIN sources os ON os.id = o.source_id
- WHERE l.origin_page_id = ANY($1::int[]) OR (l.origin_page_id IS NULL AND l.from_page_id = ANY($1::int[]))`, [ids]) : Promise.resolve([]),
- () => ids.length ? tx.executeRaw<Record<string, unknown>>(`SELECT x.id, ${ENDPOINT('f', 'f')}, ${ENDPOINT('t', 't')}, ${ENDPOINT('o', 'o')},
+ FROM (${OWNED_ROWS('links', PAGE_IDS)}) l) q) AS links,
+ (SELECT COALESCE(json_agg(q), '[]'::json) FROM (
+SELECT x.id, x.from_page_id AS f, x.to_page_id AS t, x.origin_page_id AS o,
x.link_type, x.kind, x.occurred_on::text AS occurred_on, x.date_precision, x.producer, x.line_hash
- FROM link_transitions x JOIN pages f ON f.id = x.from_page_id JOIN sources fs ON fs.id = f.source_id
- JOIN pages t ON t.id = x.to_page_id JOIN sources ts ON ts.id = t.source_id
- LEFT JOIN pages o ON o.id = x.origin_page_id LEFT JOIN sources os ON os.id = o.source_id
- WHERE x.origin_page_id = ANY($1::int[]) OR (x.origin_page_id IS NULL AND x.from_page_id = ANY($1::int[]))`, [ids]) : Promise.resolve([]),
- ]) as Array<Record<string, unknown>[]>;
+ FROM (${OWNED_ROWS('link_transitions', PAGE_IDS)}) x) q) AS transitions,
+ (SELECT COALESCE(json_agg(q), '[]'::json) FROM (
+SELECT p.id, p.slug, p.source_id, s.incarnation::text AS incarnation FROM pages p JOIN sources s ON s.id = p.source_id
+ WHERE p.id = ANY(ARRAY(SELECT unnest(ARRAY[e.from_page_id, e.to_page_id, e.origin_page_id])
+ FROM ((${OWNED_ROWS('links', PAGE_IDS, ENDS)}) UNION ALL (${OWNED_ROWS('link_transitions', PAGE_IDS, ENDS)})) e))) q) AS endpoints`, params);
+ const { pages: pageRows, facts, takes, links, transitions, endpoints } = row!;
+ const byId = new Map(endpoints.map(r => [Number(r.id), { id: Number(r.id), slug: String(r.slug), source_id: String(r.source_id), incarnation: String(r.incarnation) }]));
+ const endpoint = (id: unknown): RawEndpoint | null => id == null ? null : byId.get(Number(id)) ?? null;
+ const pages: RawPage[] = pageRows.map(r => ({ id: Number(r.id), slug: String(r.slug), deleted: r.deleted === true, revision: String(r.revision),
+ content_hash: (r.content_hash as string | null) ?? null, tier: String(r.trust_tier), visible: r.visible === true, large: r.large === true,
+ incarnation: String(r.incarnation) }));
return {
pages,
- facts: facts.map(toFact),
- takes: takes.map(toTake),
- links: links.map(r => ({ id: Number(r.id), from: endpoint(r, 'f')!, to: endpoint(r, 't')!, origin: endpoint(r, 'o'), link_type: String(r.link_type),
+ facts: facts.map(r => toFact(r.fp == null ? { ...r, fp: knownFp.get(String(r.fact)) } : r)),
+ takes: takes.map(r => toTake(r.claim_fp == null ? { ...r, claim_fp: knownFp.get(String(r.claim)) } : r)),
+ links: links.map(r => ({ id: Number(r.id), from: endpoint(r.f)!, to: endpoint(r.t)!, origin: endpoint(r.o), link_type: String(r.link_type),
link_source: (r.link_source as string | null) ?? null, context: String(r.context ?? ''), origin_field: (r.origin_field as string | null) ?? null,
link_kind: (r.link_kind as string | null) ?? null, resolution_type: (r.resolution_type as string | null) ?? null,
assertion_tense: (r.assertion_tense as string | null) ?? null })),
- transitions: transitions.map(r => ({ id: Number(r.id), from: endpoint(r, 'f')!, to: endpoint(r, 't')!, origin: endpoint(r, 'o'),
+ transitions: transitions.map(r => ({ id: Number(r.id), from: endpoint(r.f)!, to: endpoint(r.t)!, origin: endpoint(r.o),
link_type: String(r.link_type), kind: String(r.kind), occurred_on: String(r.occurred_on), date_precision: String(r.date_precision),
producer: String(r.producer), line_hash: String(r.line_hash) })),
writerTier: ((pageRows[0] ?? (await tx.executeRaw<Record<string, unknown>>(`SELECT current_setting('gbrain.write_trust_tier', true) AS writer_tier`))[0])
diff --git a/src/core/schema-migrations/v249-belief-ledger.ts b/src/core/schema-migrations/v249-belief-ledger.ts
index 94aeee0d28..2bf268de08 100644
--- a/src/core/schema-migrations/v249-belief-ledger.ts
+++ b/src/core/schema-migrations/v249-belief-ledger.ts
@@ -1,5 +1,6 @@
import type { Migration } from './types.ts';
-import { BELIEF_LEDGER_SCHEMA_SQL, BELIEF_SOURCE_COLUMNS_SQL } from '../belief/schema.ts';
+import { BELIEF_FACTS_STREAM_INDEX, BELIEF_LEDGER_SCHEMA_SQL, BELIEF_SOURCE_COLUMNS_SQL } from '../belief/schema.ts';
+import { buildIndexOnline, migrationNotice } from './helpers.ts';
// Applied by src/core/migrate.ts on the next initSchema(); see docs/ENGINES.md
// ("Canonical schema sources") for when schema.sql or a TS fragment also changes.
@@ -9,6 +10,7 @@ import { BELIEF_LEDGER_SCHEMA_SQL, BELIEF_SOURCE_COLUMNS_SQL } from '../belief/s
// manifest and purge redaction register (src/core/belief/schema.ts, also in
// both blobs), plus the migration-only `sources.purge_epoch` counter. Additive
// and empty: nothing appends until `gbrain beliefs enable` baselines a source.
+// The handler builds the facts index the batch state read uses (online on Postgres).
export const v249: Migration = {
version: 249,
name: 'belief_ledger',
@@ -16,4 +18,5 @@ export const v249: Migration = {
sql: `${BELIEF_LEDGER_SCHEMA_SQL}
${BELIEF_SOURCE_COLUMNS_SQL}
`,
+ handler: async engine => { await buildIndexOnline(engine, 249, BELIEF_FACTS_STREAM_INDEX, { notice: migrationNotice }); },
};
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
index 59755cd43d..ccf3ad53d7 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
@@ -1085,6 +1085,7 @@
"idx_eval_candidates_created_at": "CREATE INDEX idx_eval_candidates_created_at ON public.eval_candidates USING btree (created_at DESC)",
"idx_eval_capture_failures_ts": "CREATE INDEX idx_eval_capture_failures_ts ON public.eval_capture_failures USING btree (ts DESC)",
"idx_extract_rollup_7d_day": "CREATE INDEX idx_extract_rollup_7d_day ON public.extract_rollup_7d USING btree (day)",
+ "idx_facts_belief_stream": "CREATE INDEX idx_facts_belief_stream ON public.facts USING btree (source_id, source_markdown_slug) WHERE (expired_at IS NULL)",
"idx_facts_dimension": "CREATE INDEX idx_facts_dimension ON public.facts USING btree (source_id, entity_slug, dimension, valid_from DESC) WHERE ((expired_at IS NULL) AND (dimension IS NOT NULL))",
"idx_facts_embedding_hnsw": "CREATE INDEX idx_facts_embedding_hnsw ON public.facts USING hnsw (embedding halfvec_cosine_ops) WHERE ((embedding IS NOT NULL) AND (expired_at IS NULL))",
"idx_facts_embedding_model": "CREATE INDEX idx_facts_embedding_model ON public.facts USING btree (source_id, embedding_model) WHERE (expired_at IS NULL)",
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
index 7f496943fb..0404bf426b 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
@@ -1085,6 +1085,7 @@
"idx_eval_candidates_created_at": "CREATE INDEX idx_eval_candidates_created_at ON public.eval_candidates USING btree (created_at DESC)",
"idx_eval_capture_failures_ts": "CREATE INDEX idx_eval_capture_failures_ts ON public.eval_capture_failures USING btree (ts DESC)",
"idx_extract_rollup_7d_day": "CREATE INDEX idx_extract_rollup_7d_day ON public.extract_rollup_7d USING btree (day)",
+ "idx_facts_belief_stream": "CREATE INDEX idx_facts_belief_stream ON public.facts USING btree (source_id, source_markdown_slug) WHERE (expired_at IS NULL)",
"idx_facts_dimension": "CREATE INDEX idx_facts_dimension ON public.facts USING btree (source_id, entity_slug, dimension, valid_from DESC) WHERE ((expired_at IS NULL) AND (dimension IS NOT NULL))",
"idx_facts_embedding_hnsw": "CREATE INDEX idx_facts_embedding_hnsw ON public.facts USING hnsw (embedding halfvec_cosine_ops) WHERE ((embedding IS NOT NULL) AND (expired_at IS NULL))",
"idx_facts_embedding_model": "CREATE INDEX idx_facts_embedding_model ON public.facts USING btree (source_id, embedding_model) WHERE (expired_at IS NULL)",
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
index eccc7d1d1e..5aa5690e18 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
@@ -1084,6 +1084,7 @@
"idx_eval_candidates_created_at": "CREATE INDEX idx_eval_candidates_created_at ON public.eval_candidates USING btree (created_at DESC)",
"idx_eval_capture_failures_ts": "CREATE INDEX idx_eval_capture_failures_ts ON public.eval_capture_failures USING btree (ts DESC)",
"idx_extract_rollup_7d_day": "CREATE INDEX idx_extract_rollup_7d_day ON public.extract_rollup_7d USING btree (day)",
+ "idx_facts_belief_stream": "CREATE INDEX idx_facts_belief_stream ON public.facts USING btree (source_id, source_markdown_slug) WHERE (expired_at IS NULL)",
"idx_facts_dimension": "CREATE INDEX idx_facts_dimension ON public.facts USING btree (source_id, entity_slug, dimension, valid_from DESC) WHERE ((expired_at IS NULL) AND (dimension IS NOT NULL))",
"idx_facts_embedding_model": "CREATE INDEX idx_facts_embedding_model ON public.facts USING btree (source_id, embedding_model) WHERE (expired_at IS NULL)",
"idx_facts_entity_active": "CREATE INDEX idx_facts_entity_active ON public.facts USING btree (source_id, entity_slug, valid_from DESC) WHERE (expired_at IS NULL)",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
index 9c03feb845..0cff47f751 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
@@ -1087,6 +1087,7 @@
"idx_eval_candidates_created_at": "CREATE INDEX idx_eval_candidates_created_at ON public.eval_candidates USING btree (created_at DESC)",
"idx_eval_capture_failures_ts": "CREATE INDEX idx_eval_capture_failures_ts ON public.eval_capture_failures USING btree (ts DESC)",
"idx_extract_rollup_7d_day": "CREATE INDEX idx_extract_rollup_7d_day ON public.extract_rollup_7d USING btree (day)",
+ "idx_facts_belief_stream": "CREATE INDEX idx_facts_belief_stream ON public.facts USING btree (source_id, source_markdown_slug) WHERE (expired_at IS NULL)",
"idx_facts_dimension": "CREATE INDEX idx_facts_dimension ON public.facts USING btree (source_id, entity_slug, dimension, valid_from DESC) WHERE ((expired_at IS NULL) AND (dimension IS NOT NULL))",
"idx_facts_embedding_hnsw": "CREATE INDEX idx_facts_embedding_hnsw ON public.facts USING hnsw (embedding halfvec_cosine_ops) WHERE ((embedding IS NOT NULL) AND (expired_at IS NULL))",
"idx_facts_embedding_model": "CREATE INDEX idx_facts_embedding_model ON public.facts USING btree (source_id, embedding_model) WHERE (expired_at IS NULL)",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
index 6897e215b2..ee7ab297f3 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
@@ -1087,6 +1087,7 @@
"idx_eval_candidates_created_at": "CREATE INDEX idx_eval_candidates_created_at ON public.eval_candidates USING btree (created_at DESC)",
"idx_eval_capture_failures_ts": "CREATE INDEX idx_eval_capture_failures_ts ON public.eval_capture_failures USING btree (ts DESC)",
"idx_extract_rollup_7d_day": "CREATE INDEX idx_extract_rollup_7d_day ON public.extract_rollup_7d USING btree (day)",
+ "idx_facts_belief_stream": "CREATE INDEX idx_facts_belief_stream ON public.facts USING btree (source_id, source_markdown_slug) WHERE (expired_at IS NULL)",
"idx_facts_dimension": "CREATE INDEX idx_facts_dimension ON public.facts USING btree (source_id, entity_slug, dimension, valid_from DESC) WHERE ((expired_at IS NULL) AND (dimension IS NOT NULL))",
"idx_facts_embedding_hnsw": "CREATE INDEX idx_facts_embedding_hnsw ON public.facts USING hnsw (embedding halfvec_cosine_ops) WHERE ((embedding IS NOT NULL) AND (expired_at IS NULL))",
"idx_facts_embedding_model": "CREATE INDEX idx_facts_embedding_model ON public.facts USING btree (source_id, embedding_model) WHERE (expired_at IS NULL)",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
index 42b6b12d50..a8277151c5 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
@@ -1086,6 +1086,7 @@
"idx_eval_candidates_created_at": "CREATE INDEX idx_eval_candidates_created_at ON public.eval_candidates USING btree (created_at DESC)",
"idx_eval_capture_failures_ts": "CREATE INDEX idx_eval_capture_failures_ts ON public.eval_capture_failures USING btree (ts DESC)",
"idx_extract_rollup_7d_day": "CREATE INDEX idx_extract_rollup_7d_day ON public.extract_rollup_7d USING btree (day)",
+ "idx_facts_belief_stream": "CREATE INDEX idx_facts_belief_stream ON public.facts USING btree (source_id, source_markdown_slug) WHERE (expired_at IS NULL)",
"idx_facts_dimension": "CREATE INDEX idx_facts_dimension ON public.facts USING btree (source_id, entity_slug, dimension, valid_from DESC) WHERE ((expired_at IS NULL) AND (dimension IS NOT NULL))",
"idx_facts_embedding_model": "CREATE INDEX idx_facts_embedding_model ON public.facts USING btree (source_id, embedding_model) WHERE (expired_at IS NULL)",
"idx_facts_entity_active": "CREATE INDEX idx_facts_entity_active ON public.facts USING btree (source_id, entity_slug, valid_from DESC) WHERE (expired_at IS NULL)",
diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.json
index 4bd9d907f9..8d677641d6 100644
--- a/test/fixtures/goldens/migrations/records.json
+++ b/test/fixtures/goldens/migrations/records.json
@@ -9,6 +9,7 @@
],
"helpers": {
"ALIAS_TABLES": "cddd37c636af42d862c08ca7754a57dfe9d12576b769fa8f74a5f02c803f67a0",
+ "BELIEF_FACTS_STREAM_INDEX": "9e4491eb9e0b94924a58deea3feff1b315ec0efd25a77a4e6515b362beffbc92",
"BOUNDED_TIMELINE_CHECKPOINT": "385c4da3e28732343148795d6e9a86670813a7a7cfa1e52f8a5bb494680a3c0d",
"CHECKPOINT": "3c6ff909363c4ba1c9d730e748654ab90aa07549ddf4bf36b8f93c5f4ea3680b",
"CONTENT_CHUNKS_OCCURRENCE_INDEX": "7b692ba777b30399ab5a3b100eb40b3b9d1b3fb2322dc4dc808ba8a4d667912c",
@@ -3799,7 +3800,17 @@
"version": 248
},
{
- "handler": "absent",
+ "handler": {
+ "form": "arrow",
+ "helpers": [
+ "BELIEF_FACTS_STREAM_INDEX",
+ "buildIndexOnline",
+ "dropInvalidConcurrentIndex",
+ "migrationNotice",
+ "quietMigrationNotices"
+ ],
+ "sha256": "48c7bc5cb1a62090ed3b9f4e3426a3314453ee34e1fbaea990e7a87c929fb923"
+ },
"idempotent": true,
"name": "belief_ledger",
"sql": {
diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
index 49a87dffab..d5881ebc1e 100644
--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
@@ -1085,6 +1085,7 @@
"idx_eval_candidates_created_at": "CREATE INDEX idx_eval_candidates_created_at ON public.eval_candidates USING btree (created_at DESC)",
"idx_eval_capture_failures_ts": "CREATE INDEX idx_eval_capture_failures_ts ON public.eval_capture_failures USING btree (ts DESC)",
"idx_extract_rollup_7d_day": "CREATE INDEX idx_extract_rollup_7d_day ON public.extract_rollup_7d USING btree (day)",
+ "idx_facts_belief_stream": "CREATE INDEX idx_facts_belief_stream ON public.facts USING btree (source_id, source_markdown_slug) WHERE (expired_at IS NULL)",
"idx_facts_dimension": "CREATE INDEX idx_facts_dimension ON public.facts USING btree (source_id, entity_slug, dimension, valid_from DESC) WHERE ((expired_at IS NULL) AND (dimension IS NOT NULL))",
"idx_facts_embedding_hnsw": "CREATE INDEX idx_facts_embedding_hnsw ON public.facts USING hnsw (embedding halfvec_cosine_ops) WHERE ((embedding IS NOT NULL) AND (expired_at IS NULL))",
"idx_facts_embedding_model": "CREATE INDEX idx_facts_embedding_model ON public.facts USING btree (source_id, embedding_model) WHERE (expired_at IS NULL)",