Sangeetha-Grantha

Metadata Value
Status Active
Version 1.0.0
Last Updated 2026-11-02
Author Sangeetha Grantha Team
Document Type Runbook

Macro embeddings runbook


The collection and kshetra cards in Rasika search come from CYCLE_OVERVIEW and KSHETRA_OVERVIEW documents (search guide). Their text is regenerated from tags, cycle members and temples, so a data change or migration can leave the stored text and vectors behind. Run this after make migrate in every environment that serves search, and after any change to cycle membership, temple fields or kriti-to-temple links.

Everything here runs from tools/krithi-extract-enrich-worker with DATABASE_URL set for the intended environment. Do not use --include-macro for a macro refresh: it also walks every krithi in the catalogue. Use --macro-only.

1. Migrate

make migrate
make migrate-status

2. Check what is stale (no API call, no writes)

cd tools/krithi-extract-enrich-worker
uv run python scripts/embed_catalogue.py --macro-only --check

The check regenerates every overview from current data and compares it with the stored document and vector for the model’s profile (--model / --dims, default gemini-embedding-2 / 768). It reads the database and hashes locally; it needs no embedding credentials. A document is stale when it has no row, no vector for the profile, a vector hash that differs, a document hash that differs from its indexed text, or a regenerated hash that differs from the stored one (source data changed).

Up to date: exit code 0 and

Macro freshness | checked = <n> | stale = 0 (cycle 0, kshetra 0) | profile <id>

Stale: exit code 1 and one STALE <kind> <name>: <reasons> line per document. Go to step 3.

Without the worker, the first three conditions have this read-only form (zero rows means they hold; it cannot see source-data changes):

SELECT d.document_kind, COALESCE(d.tag_id, d.temple_id) AS anchor, e.content_hash AS vector_hash, d.content_hash
FROM search_documents d
LEFT JOIN document_embeddings e ON e.document_id = d.id
  AND e.profile_id = (SELECT id FROM embedding_profiles WHERE is_active)
WHERE d.document_kind IN ('CYCLE_OVERVIEW', 'KSHETRA_OVERVIEW') AND d.is_published
  AND (e.id IS NULL OR e.content_hash <> d.content_hash OR d.content_hash <> md5(d.indexed_content));

3. Re-embed the stale overviews

Preview first; this makes no API call and builds no embedding client:

uv run python scripts/embed_catalogue.py --macro-only --dry-run

would embed counts the overviews that will be sent. Each is one paid embedding call, so confirm the number matches step 2 (a handful, not the catalogue) before the real run, which needs the environment’s Gemini credentials and whoever owns the quota to agree:

uv run python scripts/embed_catalogue.py --macro-only

--force re-embeds every overview (about 106 calls); use it only after a deliberate text or profile change.

4. Prove it

Run step 2 again. It must report stale = 0 and exit 0. Record the line in the change or deployment notes. If the environment’s backend caches nothing across restarts, no restart is needed; search reads the vectors on each request.

Failure notes


Runbooks · Search guide