| Metadata | Value |
|---|---|
| Status | Completed |
| Version | 1.0.0 |
| Last Updated | 2026-11-01 |
| Author | Sangeetha Grantha Team |
ID: TRACK-152 Status: Complete: Phases 0 to C merged; follow-ups listed in the Progress Log Owner: Seshadri Created: 2026-10-16 Updated: 2026-11-01
Let a Rasika search such as “sixth enclosure” or “fire lingam” return a cycle or kshetra card as well as kritis, using the CYCLE_OVERVIEW and KSHETRA_OVERVIEW documents that are already embedded.
CYCLE_OVERVIEW and 94 KSHETRA_OVERVIEW documents exist. KrithiSearchRepository joins search_documents d to krithis k ON d.krithi_id = k.id, so macro documents (which have tag_id or temple_id and no krithi_id) can never be returned. SemanticSearchResultItem.krithiId is non-null in the shared DTO, so the API contract also assumes every hit is a kriti.evaluate_retrieval.py directly against search_documents, not through the live API.Status: Accepted Accepted by: Seshadri (2026-10-24)
The best discriminating content in the index is the cycle and kshetra overview text, and it cannot reach a user. A query about an enclosure or a lingam returns kritis whose text happens to match, not the cycle or the shrine the user is asking about.
KRITHI, COLLECTION (slug) and KSHETRA (temple id). The join becomes a left join, or the macro documents are unioned, with published-only filtering for each anchor kind.krithiId.SemanticSearchResultItem.krithiId change must not break the frozen V1 decoders.krithiId.evaluate_retrieval.py outcomes, with no regression on kriti MRR 0.78 / Recall@5 87.1%.Repository and route tests including a V1-decoder compatibility test, retrieval probes through the API, presenter tests, simulator walk-through, make test, make test-integration, make check-docs.
Status: Accepted Accepted by: Seshadri (chat instruction) Accepted at: 2026-10-25
Written from the accepted Intent and its 2026-10-24 decisions, after reading KrithiSearchRepository, HybridSearchService, SemanticSearchRoutes, SearchDtos.kt, KtorCatalogueApi, SearchPresenter, CatalogueRepository (collections, overviewTagIds, cycleOverview), evaluate_retrieval.py with evals/retrieval_benchmarks.json, and TRACK-151’s Spec/Plan plus its Phase 1 code on claude/track-151-kshetra-contract-df8da3 (read with git show, not checked out): TempleEligibility.kt, CatalogueTempleDtos.kt, and the RasikaCatalogue* / ALL_PUBLISHED renames. Nothing is implemented, nothing was measured live (no database was started), and the carnatic-musicologist review was not run: this track adds read-only retrieval over existing reviewed documents and changes no seed, import, raga or tala content.
Names. This Spec uses the TRACK-151 Phase 0 names (RasikaCatalogueContract, RasikaCatalogueRoutes, CatalogueVisibility.ALL_PUBLISHED). The /v2/... URL paths are unchanged by that rename.
POST /v1/search/hybrid and /v1/search/semantic (KtorCatalogueApi.HYBRID_PATH / SEMANTIC_PATH). SemanticSearchRoutes serves both with optional admin auth; publishedOnly = !hasAdminRole(). Responses are SemanticSearchResponse(query, totalMatches, items: List<SemanticSearchResultItem>) with non-null krithiId.searchSemantic, searchHybrid) JOIN krithis k ON d.krithi_id = k.id, then fuse per kriti (ROW_NUMBER() OVER (PARTITION BY krithi_id ...), RRF 1/(60+rank)). Macro documents carry tag_id or temple_id and a null krithi_id (V66, chk_search_doc_anchor), so they can never appear.evaluate_retrieval.py scores macro probes (is_macro: true) with search_macro_documents: cosine ANN over CYCLE_OVERVIEW / KSHETRA_OVERVIEW documents of the active profile only, is_published, top-k 5, in both modes. Kriti probes use the hybrid or semantic path. Four probes are macro today: EVAL-31 (Kanyakumari, KSHETRA_OVERVIEW), SS-146-11, SS-146-12, TY-147-11 (CYCLE_OVERVIEW).EVAL-01..EVAL-31 battery measured in TRACK-145. retrieval_benchmarks.json now holds 54 probes (SS-146-*, TY-147-* added later); the evaluator loads 53 of them, because one is filtered as requires_human_approval, so that number is not the current 53-probe score. The Plan re-records both.listCollections / findCollection expose a tag only when it has at least one reviewed, published member (reviewedMemberRows); overviewTagIds() lists tags with a published CYCLE_OVERVIEW. Kshetra eligibility (TRACK-151 Phase 1): TempleEligibility.eligibleIds().A. Hit kinds and opt-in
KRITHI, COLLECTION, KSHETRA. KRITHI hits are exactly today’s SemanticSearchResultItem, same fields, same ranking, same krithiId non-null.COLLECTION, KSHETRA) exist only on new V2 endpoints (Intent decision 1):
POST /v2/catalogue/search/hybridPOST /v2/catalogue/search/semantic
Both take the unchanged SemanticSearchRequest body, are anonymous, and are published-only (no admin branch)./v1/search/hybrid and /v1/search/semantic are not changed: same paths, same DTO, no macro hit, no new field, and the same response for the same input. V1 and older apps never receive a hit without krithiId.B. Response contract (additive, V2-only types)
modules/shared/domain/.../model/catalogue/CatalogueSearchDtos.kt:
CatalogueSearchHitKindDto { KRITHI, COLLECTION, KSHETRA } (serialised as the names).CatalogueMacroHitDto: kind (COLLECTION or KSHETRA only), title, subtitle? (composer name for a collection; place or region for a kshetra), snippet (bounded excerpt of the matched overview, see 6), collectionSlug? (set only for COLLECTION), templeId? (set only for KSHETRA), memberCount? (collections), publishedKrithiCount? (kshetras), recordedGap (kshetras, default false), similarityScore, lexicalScore?, rrfScore?.CatalogueSearchResponseDto: query, totalMatches (kriti hits + macro hits), macroHits: List<CatalogueMacroHitDto> (default empty, at most 3), items: List<SemanticSearchResultItem>, exactTitleMatchId? (see 11).snippet is a prefix of the stored overview text cut at a sentence or word boundary, at most 240 characters, never generated at request time. The hit never carries the full overview; the detail screen does.CatalogueMacroHitDto (collectionSlug?, templeId?, exactly one non-null, enforced by a constructor check and a test). SemanticSearchResultItem and SemanticSearchResponse are not modified, so the frozen V1 decoders cannot break. (Intent asked for a nullable/additive change; making krithiId nullable on the existing item was rejected as the riskier way to get the same result. See open question 1.)encodeDefaults = true, explicitNulls = false. CatalogueV2Contract’s successor RasikaCatalogueContract gains SEARCH_HYBRID_PATH and SEARCH_SEMANTIC_PATH.:modules:shared:domain tests, a decoder configured like the frozen V1 client (strict SemanticSearchResponse, ignoreUnknownKeys = false) decodes the byte-for-byte recorded V1 fixture; and items of a V2 response decode as List<SemanticSearchResultItem> with that same strict decoder. In an API route test, /v1/search/hybrid for a macro-matching query returns zero items without krithiId and the same body as before the change (golden comparison on a seeded database).C. Retrieval and ranking
search_documents of kinds CYCLE_OVERVIEW and KSHETRA_OVERVIEW, run beside the existing kriti query with the same query vector (embedQueryCached; no extra embedding call). The kriti SQL, its JOIN krithis, RRF ranks and krithi_doc_rank partition are not edited, so kriti ordering and metrics cannot move. (A left join or union inside the kriti CTEs was rejected: macro rows would take ranks 1/(60+rank) and shift kriti scores. The Intent’s “left join or union” is satisfied by a union at the response level.)exactTitleMatchId is set when the normalised query equals a published kriti’s title_normalized or incipit_normalized. Clients render that kriti first, then the macro group, then the remaining kritis. When it is null, the macro group renders above all kritis. The kriti items array order is never altered by macro hits.MAX_MACRO_HITS = 3, not a request parameter. At most one hit per anchor (one per collection slug, one per temple): multi-chunk overviews (source_chunk_index) collapse to the best chunk.word_similarity(query, indexed_content) >= 0.3, ILIKE containment and all-token containment, the same lexical predicates as the kriti query), restricted to macro documents. Semantic: vector branch only. Ties break by similarity DESC, then anchor id.composerId and ragaId in the request are kriti-scoped: when either is set, macroHits is empty. (Mobile sends neither today.)resolveCompatibleProfile), so the two groups cannot mix embedding spaces.D. Published-only per anchor kind
d.is_published AND k.workflow_state = 'published'. For macro documents:
COLLECTION: document_kind = 'CYCLE_OVERVIEW', d.is_published, d.tag_id is in the set of tags that listCollections would return (at least one reviewed, published member). The set comes from one function in CatalogueRepository that listCollections, overviewTagIds consumers and search all call; search does not restate the rule. A tag whose overview is published but whose collection would 404 is never a hit.KSHETRA: document_kind = 'KSHETRA_OVERVIEW', d.is_published, d.temple_id is in TempleEligibility.eligibleIds() (TRACK-151 Phase 1). A recorded-gap temple (Kanyakumari) is eligible and returns recordedGap = true. Search never restates the eligibility rule.COLLECTION hit resolves in GET /v2/catalogue/collections/{slug} and every KSHETRA hit in GET /v2/catalogue/temples/{id} (a contract test asserts both for all macro documents in the seeded fixture; a 404 from a card is a defect).E. Acceptance on the probes (Intent decision 4)
evaluate_retrieval.py gains a --via-api <base-url> option that posts each probe to /v2/catalogue/search/{hybrid|semantic}, scores macroHits for is_macro probes (rank within the group) and items for the rest, and prints the same metrics. Acceptance, all required:
EVAL-31, SS-146-11, SS-146-12, TY-147-11, hit and reciprocal rank through the API equal the recorded evaluate_retrieval.py outcome for that probe (re-recorded in the Plan before any code, since per-probe results are not in the track files). A recorded hit at rank 4 or 5 cannot survive a cap of 3; if the baseline shows one, that is reported to Seshadri before coding, not hidden by changing the cap or the metric.items array for every non-macro probe is identical (same ids, same order) to the V1 endpoint’s output, hence MRR 0.780 and Recall@5 87.1% on the EVAL-01..EVAL-31 battery are unchanged, and the 53-probe baseline re-recorded in the Plan is unchanged to the digit.EVAL-01, 04, 09, 13, 17, 23) return an empty macro group, or the floor is raised until they do, without losing any macro probe above. Any other kriti probe that returns macro hits is listed with its hits for Seshadri’s review; it is not auto-counted as a failure (a query such as EVAL-24 about a fire lingam at Tiruvannamalai may legitimately surface its kshetra).make test and make test-integration pass; make test-frontend is unaffected (no admin-web change).F. Mobile (after the backend contract lands)
SearchPresenter holds macroHits and exactTitleMatchId beside discoveryItems; the screen shows a “Collections and kshetras” group with a card per hit. A COLLECTION card opens the TRACK-150 collection destination by slug; a KSHETRA card opens the TRACK-151 kshetra detail by id. A card shows kind label (text, not colour only), title, subtitle, snippet, and a recorded-gap marker for gap kshetras. Each card has a content description.KSHETRA card is rendered only when the kshetra detail destination exists in the app build (TRACK-151 Phase 2). Until then the client drops KSHETRA hits rather than showing a card that goes nowhere. Unknown future kinds are dropped, never crash.G. Out of scope
source_chunk_index chunking, changes to kriti ranking, facets (TRACK-153), Lexical-mode (/v2/catalogue/krithis?query=) macro results, admin-web search, composer/raga macro hits, a V1 field or path change, any migration, any write, and AUDIT_LOG entries (read-only).RasikaSearchRoutes.kt (or two handlers in RasikaCatalogueRoutes, Plan decides on file size) registers the two V2 POSTs, anonymous. A RasikaSearchService calls the existing HybridSearchService for kriti items (unchanged code path, publishedOnly = true) and a new macro search for the group, both with one embedded query vector. HybridSearchService gains a small method returning the vector/profile pair so the vector is embedded once; V1 behaviour is untouched.MacroSearchRepository (wired into SangitaDal beside krithiSearch) holds searchMacroHybrid / searchMacroSemantic. It takes the allowed tag ids (from the one collections-eligibility function) and temple ids (TempleEligibility.eligibleIds()) as uuid[] parameters, and filters d.tag_id = ANY(?) / d.temple_id = ANY(?) per kind. All access via DatabaseFactory.dbQuery { }, raw SQL style as in KrithiSearchRepository. It returns explicit DTO inputs, not rows.EXPLAIN and fixes this before anything else if the index path is chosen.tags.display_name_en, composer via the existing majority-composer helper, memberCount from the reviewed member set. Kshetra hit: name, place, publishedKrithiCount and recordedGap from TempleEligibility.snapshot(). Snippet from original_content (the stored overview), cut per requirement 6.CatalogueApi.searchHybrid/searchSemantic change return type to CatalogueSearchResponseDto on the V2 path; fixtures and fake API updated; SearchPresenter + SearchScreen gain the group. RasikaDestination already has collection destinations (TRACK-150); kshetra destinations arrive with TRACK-151 Phase 2.openapi/sangita-grantha.openapi.yaml gains the two V2 paths and schemas; application_documentation/03-api/search.md documents kinds, cap, floor, fallback and the unchanged V1 contract.KSHETRA hits need TempleEligibility (Phase 1, on an unmerged branch) and a detail destination (Phase 2). COLLECTION hits need neither. The Plan phases accordingly; no code may copy the eligibility rule in the meantime.AUDIT_LOG entry. Usage recording, if added, follows the collection route pattern and carries no personal data./v1/search serves admin. It must stay byte-identical for admin callers (unpublished included); the V2 routes never read the admin role.All four Intent questions are decided (2026-10-24). New, for acceptance:
SemanticSearchResultItem untouched and carry the nullable anchors in a new V2 CatalogueMacroHitDto (requirement 7), or also make krithiId nullable on the shared item as the Intent sketched? Recommendation: untouched; same safety, smaller blast radius.evaluate_retrieval.py and the live API probes? They embed the probe queries (a few dozen tiny Gemini calls), not documents; Intent forbids only paid document embedding runs.Status: Accepted Accepted by: Seshadri (chat instruction) Accepted at: 2026-10-25
Written from the Spec above; provisional until the Spec is accepted. Nothing is implemented. Phases land separately.
| Path | Phase | Change |
|---|---|---|
tools/krithi-extract-enrich-worker/scripts/evaluate_retrieval.py |
A | --via-api <base-url> option; scores macro probes on macroHits, others on items; no change to the DB-path scoring |
modules/shared/domain/.../model/catalogue/CatalogueSearchDtos.kt (new) |
A | CatalogueSearchHitKindDto, CatalogueMacroHitDto, CatalogueSearchResponseDto |
modules/shared/domain/.../catalogue/RasikaCatalogueDtos.kt (renamed in TRACK-151 Phase 0) |
A | SEARCH_HYBRID_PATH, SEARCH_SEMANTIC_PATH in RasikaCatalogueContract |
modules/shared/domain/src/commonTest/.../CatalogueSearchDtosTest.kt (new) and a V1 fixture |
A | Serialisation, anchor invariant, frozen-V1-decoder test |
modules/backend/dal/.../repositories/CatalogueRepository.kt |
A | Extract the single collections-eligibility function used by listCollections and search; behaviour of collections unchanged |
modules/backend/dal/.../repositories/MacroSearchRepository.kt (new), SangitaDal.kt |
A, B | Macro hybrid and semantic queries; COLLECTION in A, KSHETRA added in B |
modules/backend/api/.../services/HybridSearchService.kt |
A | Expose the embedded vector and bound profile for reuse; V1 behaviour unchanged |
modules/backend/api/.../services/RasikaSearchService.kt (new) |
A | Compose kriti items, macro group, exactTitleMatchId, cap, floor |
modules/backend/api/.../routes/RasikaSearchRoutes.kt (new), plugins/Routing.kt, di/AppModule.kt |
A | Two V2 POST routes, DI wiring |
modules/backend/api/src/test/.../routes/RasikaSearchRoutesTest.kt (new), SemanticSearchRoutesTest.kt |
A, B | V2 contract tests; V1 golden untouched-check |
modules/backend/dal/src/test/.../MacroSearchRepositoryTest.kt (new) |
A, B | Testcontainers, synthetic 768-dim vectors, per-anchor published-only cases |
openapi/sangita-grantha.openapi.yaml, application_documentation/03-api/search.md |
A | V2 paths, schemas, behaviour |
modules/shared/mobile-data/.../network/CatalogueApi.kt, KtorCatalogueApi.kt, repository/CatalogueRepository.kt, fixture/CatalogueFixtures.kt, DiscoveryCatalogueClientTest.kt |
C | V2 search call and fixtures |
modules/shared/presentation/.../search/SearchPresenter.kt, SearchScreen (and card composable), RasikaCopy.kt, tests |
C | Macro group state and cards, navigation to collection and kshetra detail |
conductor/tracks.md |
any | Status line only |
No migration, no AUDIT_LOG write, no modules/frontend change, no change to V1 routes or DTOs.
Phase 0: baseline and sign-off (no code)
make db + make migrate, the stack’s active embedding profile and GEMINI credentials available, run evaluate_retrieval.py --mode hybrid and --mode semantic. Record in the Progress Log: per-probe hit and reciprocal rank for all 53 probes, the 31-probe subtotal (expect MRR 0.780 / Recall@5 87.1%), the four macro probes’ ranks, and the number of macro documents by kind and how many are published and anchored to an eligible collection or temple.EXPLAIN for the macro vector query over the eligible set.Phase A: contract, backend, COLLECTION kind (separately landable; does not need TRACK-151)
MacroSearchRepository COLLECTION branch (hybrid, semantic, lexical-only), one-per-anchor collapse, cap, floor constants (initial placeholder), repository tests: reviewed-and-published collection returned; published overview on a tag with no reviewed member not returned; unpublished overview not returned; two chunks of one tag give one hit; no-profile lexical path returns the lexical macro hit; composer or raga filter empties the group.RasikaSearchService, routes, DI; route tests with the existing fake embedding client: V2 returns items identical to V1 for the same query, macroHits at most 3, exactTitleMatchId set for a typed full title, V1 body unchanged.evaluate_retrieval.py --via-api for the three CYCLE_OVERVIEW probes and the 53-probe kriti parity check; record results.search.md; make check-docs.Phase B: KSHETRA kind (blocked on TRACK-151 Phase 1 merged to main)
main once claude/track-151-kshetra-contract-df8da3 lands (do not branch from it, do not copy TempleEligibility). Confirm TempleEligibility.eligibleIds() and the RasikaCatalogue* / ALL_PUBLISHED names exist.d.temple_id = ANY(eligible), recordedGap, publishedKrithiCount from TempleEligibility.snapshot()); repository tests for each rule: draft-only temple not returned, overview-only temple (including Kanyakumari, recordedGap = true) returned, child-only-eligible parent, unpublished overview not returned.--via-api for EVAL-31 and the fire-lingam probe EVAL-24; update OpenAPI and docs.Phase C: Rasika mobile (COLLECTION cards need only Phase A; KSHETRA cards also need TRACK-151 Phase 2)
items fails the build.EXPLAIN recorded.EXPLAIN).make test, make test-integration with MacroSearchRepositoryTest, RasikaSearchRoutesTest, the V1 golden test and the V1-decoder compatibility test; --via-api output for the CYCLE_OVERVIEW probes equal to the recorded outcomes and an items parity report with zero differences; make check-docs.--via-api output for EVAL-31, EVAL-24; all macro hits resolve through their detail endpoints on the live stack (script output pasted)../gradlew :modules:shared:domain:allTests :modules:shared:mobile-data:allTests :modules:shared:presentation:allTests, presenter tests, and an iOS simulator walk-through against the live backend: a cycle query (for example the sixth-enclosure probe) shows a collection card that opens the collection; a fire-lingam query shows a kshetra card that opens the kshetra; a typed full title keeps its kriti first; an older-app V1 call is unchanged.git diff --check; make agent-evals only if CLAUDE.md or .claude/ change (none planned).EXPLAIN); stop if a macro rank exceeds 3.--via-api, docs.requires_human_approval. The 53-probe count replaces 54 throughout this file.main: PR #44 (6788237, mobile V2 data layer and Search), PR #45 (TRACK-153 Phase 0-1, 7c068cd), PR #46 (2a23bcf). Search shows the exact-title kriti first, then a “Collections and kshetras” group, then remaining kritis. Collection cards are live. KSHETRA hits are dropped by the client (kshetraDestinationAvailable=false) until TRACK-151 Phase 2 supplies a kshetra destination; checked in the iOS simulator with a temporary, uncommitted override.make migrate applied V68 (TRACK-154) on the dev database (now version 68); the macro-only indexer reported all 12 cycle and 94 kshetra overviews up to date.make migrate, then the macro-only indexer, to re-embed the 6 updated overviews (done locally).EVAL-31 scores 0.836 against a floor of 0.83; exact-title probes peak at 0.787.EVAL-22, SS-146-02, SS-146-03, Syama Sastri Ratnatrayam) and need a human look.KSHETRA cards when TRACK-151 Phase 2 lands.EVAL-31 0.836 against a floor of 0.83); (2) three new cards on non-macro probes need a human look; (3) other environments need make migrate and the macro-only indexer; (4) the implementation session reported about 1,000 paid Gemini embedding calls beyond what was authorised, reversed from a hash-verified backup; Seshadri to check Gemini usage in the console (not verified from here); (5) exact-title ordering was covered by tests but not seen in the simulator.