Sangeetha-Grantha

Metadata Value
Status Completed
Version 1.1.0
Last Updated 2026-09-26
Author Sangeetha Grantha Team

Track: Rasika Semantic Search

ID: TRACK-143 Status: Completed Owner: Seshadri Created: 2026-09-22 Updated: 2026-09-22

Goal

Port the Curator Console’s existing Hybrid and Semantic composition search to the Rasika mobile app, as a client of the search API that already serves the console.

Context

Intent

Status: Accepted Accepted by: Seshadri Accepted at: 2026-09-22

Problem

I want the semantic search that already exists on the Curator Console brought to the Rasika mobile app. The console Kritis page (KrithiList.tsx) lets a curator switch Lexical / Hybrid / Semantic. Hybrid is the default. A query such as “Dikshithar Kamalamba Navavarna Krithis” returns ranked compositions with title and melody (composer, raga, tala), a matched-content snippet, a kind badge (Overview or Passage), and a relevance treatment: Hybrid Match when both sides hit, otherwise a Semantic % or Lexical % badge, plus the breakdown RRF / Sem % / Lex %. Semantic mode shows a single “% Match”. An empty query falls back to ordinary lexical browse. Hybrid and Semantic are not paged; the console asks for 30 results and captions them as “Top discovery results” ranked by Reciprocal Rank Fusion or dense similarity.

Rasika does not have that. Explore (SearchScreen / SearchPresenter in modules/shared/presentation) is an explicit Search submit over Krithis, Ragas, and Composers. Krithi results come from GET /v2/catalogue/krithis through CatalogueApi.searchKrithis: paged, published catalogue rows (title, incipit, composer, raga sequence, tala) rendered on KrithiCard. There is no mode toggle, no passage from the embedding index, and no relevance score. application_documentation/03-api/search.md already says Rasika does not call the vector-search routes. TRACK-140 kept AI discovery out of the first delivery.

Proposed outcome

On Rasika Explore, a rasika should be able to search compositions the way the console already searches them in Hybrid and Semantic: by mixed exact-and-related wording, and by meaning, then open the composition in the existing reader.

This is a port of the existing feature, not a new search backend. The API is already there and the shared DTOs are already in commonMain:

In scope: a Rasika client of those two endpoints, on the existing Explore krithi search, in the shared Compose UI and mobile-data layer. Curator Lexical stays what it is — GET /v1/admin/krithis/search, admin-only, all workflow states — and Rasika must not call it. Rasika’s current catalogue search remains the lexical/browse path for known titles, incipits, and lines, and for Ragas and Composers. Raga and composer UUID filters already exist on the discovery request; whether Explore forwards the filters it already has is a Spec decision.

Out of scope unless a later accepted Spec says otherwise: redesigning the Curator Console; a new embedding model, index, or Flyway migration; re-embedding the corpus; generative or chat answers. Indexing stays the TRACK-108 tools. Hybrid with no active profile already degrades to lexical search over search_documents, which is not the same as catalogue browse; Semantic with no profile returns an empty list. The port consumes that behavior; it does not replace it.

Affected users and systems

Constraints

Open questions

Closed by Seshadri on 2026-09-22. Do not reopen these in the Plan.

Spec

Status: Accepted Accepted by: Seshadri Accepted at: 2026-09-22

Requirements

Rasika Explore gains Hybrid and Semantic composition search as a client of the existing discovery API. Lexical catalogue search stays. Curator Console search stays.

  1. Modes, Krithis only. On the Krithis category, Explore offers three modes: Lexical, Hybrid, and Semantic. The initial mode is Hybrid. Ragas and Composers have no mode control and keep calling GET /v2/catalogue/ragas and GET /v2/catalogue/composers.
  2. Lexical path unchanged. Lexical still calls CatalogueRepository.searchKrithis → GET /v2/catalogue/krithis with the committed query, the applied raga and composer ids, and the current page size and page. Paging stays PAGE_SIZE × MAX_PAGES (3), with Load more. The result header stays “N in this library” and “Title order”. The card stays KrithiCard with the catalogue incipit as the snippet. Rasika must not call GET /v1/admin/krithis/search.
  3. Hybrid and Semantic calls. Hybrid calls POST /v1/search/hybrid. Semantic calls POST /v1/search/semantic. Both send SemanticSearchRequest and decode SemanticSearchResponse from modules/shared/domain/.../SearchDtos.kt. Do not fork those DTOs. The body is query = the trimmed committed query, composerId = null, ragaId = null, limit = 30. Send 30 explicitly. The DTO default of 20 is not the Rasika cap.
  4. Anonymous and published-only. The post uses the same anonymous HTTP client as the catalogue. It sends the existing session and interaction headers (analytics metadata, not credentials). It does not send Authorization. The server already sets publishedOnly = !hasAdminRole().
  5. No new filter wiring. The filter sheet, chips, draft/applied facets, and the raga and composer pickers stay as they are and remain available on Krithis. Applied ragaId and composerId are sent only on the Lexical catalogue GET. Hybrid and Semantic ignore them. Do not add a language filter. Do not search ragas or composers as entities through the discovery API.
  6. Cap 30, no next page. Hybrid and Semantic request limit 30 once. hasMore is false. There is no Load more control and no offset. totalMatches is the number of rows in items (the server sets it to items.size). Do not display it as a library total and do not reuse RasikaCopy.resultCount (“N in this library”) for these modes. The result header is the fixed caption Top matches, with no count and without “Title order”.
  7. Server empty-query and no-profile behavior stays. Do not replace it with catalogue browse.
    • A blank or whitespace query on Hybrid or Semantic is still posted. HybridSearchService.execute trims it and returns SemanticSearchResponse with totalMatches 0 and items empty. Show the existing empty state. Do not call GET /v2/catalogue/krithis instead.
    • No active embedding profile: Hybrid returns lexical retrieval over search_documents (which can be empty even when the catalogue has rows). Semantic returns an empty list. Show what the server returned. Do not fall back to the catalogue.
    • An incompatible profile or embedder failure is HTTP 503 with ErrorResponse { "message": string } from StatusPages. Show a retryable error using that message when the body has message. Do not treat 503 as an empty result list. The catalogue error envelope { code, message } is not what this route returns.
  8. Discovery card. One card per SemanticSearchResultItem. Tap calls the existing onOpenKrithi(krithiId) reader. The heart uses the existing favourite callback with krithiId and title. Fields shown:
    • Title: title.
    • Raga line: ragaName when non-null. This is the primary raga name from the search join (LEFT JOIN ragas ON primary_raga_id), not the catalogue raga sequence and not a ragamalika badge. Do not call the reader API to enrich the card.
    • Subline: composerName, then talaName when non-null, in the same muted composer · tala pattern as KrithiCard.
    • Snippet: matchedContent as stored, including the plain-ASCII raga form. Do not transliterate, strip, or rewrite it. Visual cap is the same as the catalogue snippet: bodySmall, inkMuted, maxLines 2, ellipsis.
    • Quiet rank, specified below. No other score chrome.
  9. Quiet rank. A score is a rank, not a musicological claim. Do not show documentKind (COMPOSITION_OVERVIEW or SECTION_PASSAGE). Do not show a Hybrid Match badge, an “RRF” label, “Sem %”, “Lex %”, or “% Match”.
    • Hybrid uses rrfScore only. Render it unlabeled, exactly four digits after the decimal, in muted labelSmall / inkMuted (example: 0.0325). Do not convert it to a percent. RRF is 1/(60 + rank) per branch, so a top hit is on the order of 0.016–0.033, not a 0–1 probability. Do not display similarityScore or lexicalScore on a Hybrid card, including when one of them is 0 (that is how the console chooses Hybrid Match vs Semantic % vs Lexical %). If rrfScore is null, show no rank numeral.
    • Semantic uses similarityScore only (1 - cosine distance, non-null). Render the nearest integer percent of similarityScore * 100, half up, with a % suffix and no other word (example: 0.874 → 87%), in the same muted style. lexicalScore and rrfScore are null on this route and are not shown.
  10. Offline. Do not cache, prefetch, or synthesize Hybrid or Semantic rows when the network is unavailable. Surface the existing unavailable/error path.
  11. Read-only. No AUDIT_LOG write. No Flyway migration. Do not edit database/migrations/V58__semantic_search_pgvector.sql. Do not re-embed the corpus or change the embedding client.
  12. Out of scope. Curator KrithiList.tsx and its badges. Admin lexical search. Generative or chat answers. New embedding index. Redesign of the filter sheet. Raga and Composer tabs.

Design

Where it lives

Screens and states (Krithis)

State What the rasika sees Call
Before the first submit Existing idle copy. Mode chips visible. Hybrid selected. None
Lexical submit Existing catalogue list, filters applied, Load more, “N in this library”, “Title order” GET /v2/catalogue/krithis
Hybrid submit Discovery cards, caption “Top matches”, no Load more POST /v1/search/hybrid with limit 30 and null filter ids
Semantic submit Same chrome as Hybrid, semantic quiet rank POST /v1/search/semantic with limit 30 and null filter ids
Empty items Existing empty state Whichever mode was submitted. Hybrid/Semantic empty is not replaced with catalogue browse
Loading Existing loading state. A newer submit or mode change cancels the older request (the presenter already uses generation) —
503 / network failure Existing retryable error No invented rows
Filter sheet Unchanged. Apply still commits facets and refetches. In Hybrid or Semantic the refetch still sends null filter ids —
Switch to Ragas or Composers Mode chips hidden. Existing directory search and paging Catalogue GETs only
Switch back to Krithis The selected mode is still the one the rasika left Refetch in that mode if a search was already committed

Mode chips sit with the Krithis tools (category row / filter row), labels Lexical, Hybrid, Semantic. Changing mode resets the page, clears the other mode’s rows, and refetches when a query has been committed. openDirectory and applyCommittedQuery still land on Krithis and then follow the current mode (initial mode Hybrid).

Rank fields, from the code

KrithiSearchRepository.toSemanticItem(hybridScores = true) sets lexicalScore and rrfScore only for hybrid. Semantic calls toSemanticItem(hybridScores = false), so those two are null and similarityScore is the cosine similarity (0 when the SQL value is null). Hybrid order is rrf_score DESC. Semantic order is similarity DESC.

Flagged concerns

Open questions carried forward

None. The Intent questions are closed:

Question Decision
Auth No admin token. No new server auth test. Client test asserts no Authorization header.
Modes Lexical, Hybrid, and Semantic on Krithis. Default Hybrid.
Score chrome Snippet plus quiet rank. Hybrid shows unlabeled rrfScore to four decimals. Semantic shows similarityScore as a whole percent. No curator badges.
Offline Unsupported.
Snippet matchedContent as stored, including the plain-ASCII raga form.
Paging limit 30. No next page. totalMatches is not a catalogue total.
Filters Unchanged catalogue-lexical wiring. Not sent on Hybrid or Semantic. Raga and Composer tabs stay catalogue search.
OpenAPI Add both posts in this port.

Plan

Status: Accepted Accepted by: Seshadri Accepted at: 2026-09-22

Seshadri authorized proceeding (“Go with the plan”) in the same instruction that accepted the Spec. This Plan was written from the accepted Spec and then implemented. It does not reopen the closed Intent decisions.

openDirectory(Ragas) and openDirectory(Composers) stay catalogue directory loads. Home shortcuts and openDirectoryLoadsRagasWithoutPriorQuery depend on that. applyCommittedQuery lands on Krithis and follows the current mode (initial Hybrid). openDirectory(Krithis) follows the current mode as well. Switching away and back keeps the mode.

Files that change

No backend route change, no Flyway, no V58 edit, no AUDIT_LOG, no re-embedding, no KrithiList.tsx edit, no new DTO.

Order of work

  1. Anonymous discovery posts on the catalogue client, repository, and fixtures, including the 503 { message } mapping.
  2. Presenter mode, separate discovery list, and the Krithis screen (chips, card, “Top matches”).
  3. Presenter and client tests. Lexical catalogue assertions sit under an explicit Lexical selection. Default submit is Hybrid.
  4. OpenAPI and the two living API docs.
  5. ./gradlew :modules:shared:mobile-data:jvmTest :modules:shared:presentation:jvmTest --console=plain

Risks

Proof

make test is the backend suite and make test-frontend is the Curator web app. This change is shared KMP. The existing Gradle tasks, already used in CI, are the proof:

./gradlew :modules:shared:mobile-data:jvmTest :modules:shared:presentation:jvmTest --console=plain

Implementation Plan

Progress Log

UX validation follow-up — 2026-09-22

The user’s follow-up request authorizes validation and reimagining the hybrid search UI without a required mode-button selection. This supersedes the original always-visible mode-chip design and the presentation of inactive discovery filters; API routing, ranks, cap, and filter semantics remain unchanged.

Follow-up validation results

Bottom navigation follow-up

The user flagged cropped labels in the native screenshots. Retain icon-and-text navigation for discoverability. The custom tab bar now reserves navigation-bar insets, extends its teal background behind the system area, and uses a 72 dp minimum item height with vertical padding so labels can grow with text scaling. This fixes the edge-to-edge overlap rather than hiding the labels.

Bottom-bar validation: presentation JVM tests and Android debug build passed (BUILD SUCCESSFUL). Android screenshots show all four labels fully visible at 100% and 150% system text size; original text scale restored. Development restart verified with backend OK and frontend HTTP 200. iOS was not rerun for this inset-only follow-up.

Critical validation — 2026-09-24

Reviewed commit 973e78a together with the current search-options and bottom-navigation follow-ups against the accepted Spec and its UX amendment.