Sangeetha-Grantha

Metadata Value
Status Completed
Version 1.0.0
Last Updated 2026-06-06
Author Principal Data & AI Engineering review (for Seshadri)
Priority P0 (functional) — blocks safe resumption of TRACK-093

TRACK-107: AI Platform Lifecycle Uplift

Goal

Move the AI layer off retired and deprecated dependencies and onto a supported, cost-efficient, schema-true footing — so the extraction/enrichment pipeline keeps working and is ready to scale toward production. Covers four coupled changes (uplift findings F1–F5): SDK migration, model repoint, structured output, and Batch Mode. They share one blast radius (gemini_enricher.py), so they are one track.

Context — why this is urgent

The enrichment path is built on two dependencies that are end-of-life:

  1. Deprecated SDK. tools/krithi-extract-enrich-worker/src/gemini_enricher.py:59-62 imports google.generativeai and uses the genai.configure() + GenerativeModel() pattern. That package was deprecated 30 Nov 2025; its Gemini-API migration deadline (31 Aug 2025) has passed. pyproject.toml:27 pins google-generativeai>=0.8.0.
  2. Retired model. src/config.py:33-34 defaults SG_GEMINI_MODEL to "gemini-2.0-flash", which reached retirement on 1 June 2026.

Enrichment is currently gated off by default (SG_ENABLE_GEMINI_ENRICHMENT defaults False), which is the only reason this hasn’t already broken production. The moment it’s enabled — and TRACK-093’s import quality benefits from it — it calls a dead endpoint via an unsupported SDK. Fix this before resuming the 1,245-krithi Trinity import.

A useful detail: gemini_enricher.py:111 already passes a response_schema, so structured output is partially adopted — the migration preserves and formalises it rather than introducing it cold.

Architecture / Approach

Target the unified google-genai SDK (client-first), repoint to gemini-3.5-flash (GA, no announced retirement — skips the 2.5 Flash → Oct-2026 re-migration), bind the existing response_schema to a Pydantic model mirroring CanonicalExtractionDto, and route bulk/backfill enrichment through the Batch API (50% cost) while keeping interactive calls synchronous.

config.py (model = gemini-3.5-flash, env-overridable)
        │
gemini_enricher.py
   client = genai.Client(api_key=...)             # was genai.configure + GenerativeModel
   client.models.generate_content(
       model=cfg.model,
       contents=prompt,
       config=GenerateContentConfig(
           response_schema=CanonicalExtractionModel  # Pydantic, schema-constrained decode
       ))
        │
   ┌────┴─────────────────────────────┐
   │ interactive  → synchronous        │  ("Generate Variants" UI)
   │ backfill     → Batch API (−50%)   │  (TRACK-093 import, re-extraction)
   └───────────────────────────────────┘

Implementation Plan

Phase 1 — SDK migration (F3)

Phase 2 — Model repoint (F1, F2)

Phase 3 — Structured output hardening (F4)

Phase 4 — Batch Mode for bulk jobs (F5)

Phase 5 — Validate & document

Acceptance Criteria

Risks

Dependencies

Progress Log

Ref: application_documentation/sangeetha-grantha-state-of-nation-july-2026.md