feat(search): add semantic lyrics search and ai-assisted worship service planning via gemini embeddings

Synced from GitHub: hymns-for-worship/issues#193 opened by @vaughanje on 2025-11-05T16:16:12Z


This might sound crazy, but this would be a great supplement to a topical index. So many times I think “I want a song about topic XYZ” but doesn’t fit neatly in the topic list, and I read through lyrics of 50 songs trying fit exactly what I want. If I could ask AI, “find songs that combines the idea of Jesus’s kingship and our submission to him.” or something like that, it would be a huge time saver.

Another step further would be “Help me create a song service related to the Sovereignty of God”. Then we could tweak it. But small steps first.

Another option, I would be willing to build my own AI agent, if I could query the database lyrics of songs that we know. A public API for lyrics queries would be helpful, but I don’t know about copyright issues around that. Even an MCP server we could use with Claude or other AI tools could be used.

@rodydavis commented on GitHub at 2025-12-19T14:04:01Z:

Been working on a lot of AI features! It will be apart of the pro plan too.

@rodydavis commented on GitHub at 2025-12-19T14:04:29Z:

I have thought about making a MCP server too and been experimenting with it as well

@rodydavis commented on GitHub at 2026-03-27T16:26:53Z:

Experiments have gone well, will probably include some features on the pro version

Automated Issue Triage

Metadata Updates:

  • Verified label: enhancement (58)
  • Updated title: feat(search): add semantic lyrics search and ai-assisted worship service planning via gemini embeddings

Codebase Analysis & Implementation Touchpoints:

  1. Backend Embedding & Generation Service (packages/hfw_server/ai):
    • [packages/hfw_server/ai/main.go](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_server/ai/main.go) and embed.go already establish the PocketBase Gemini client (google.golang.org/genai) with /ai/embed and /ai/generate/text endpoints.
  2. Lyrics Embedding Index & Vector Search:
    • Pre-compute text embeddings for all hymn stanzas, choruses, and topics, storing vector representations in SQLite (sqlite-vec / Turso vector extensions) or PostgreSQL pgvector.
  3. Client UI & Service Planner:
    • Expose natural language thematic query inputs (e.g., “songs about God’s sovereignty and grace”) that call the semantic endpoint and recommend worship service sets.

Architecture Review & Recommended 3-Track Split (Nov 2026)

Current Repo Reality:

  • Raw Backend Scaffolding Only (packages/hfw_server/ai/): main.go, embed.go, and text.go (mounted in packages/hfw_server/main.go:183) expose /ai/embed (google.golang.org/genai + sqlite-vec-go-bindings float32 serialization), /ai/generate/text, and a chat_messages hook — untouched since Oct 13, 2026.
  • Unused Vector Config in hfw_cms: packages/hfw_cms/wrangler.jsonc (and scripts/prepare-celld-deploy.mjs) enables the sqlite_vec compatibility flag, but no vector tables, lyric embedding generation pipeline, or semantic query endpoints exist yet.
  • No Client Semantic Search or Planner UI: Neither hfw_flutter (iOS/Android), hfw_jaspr, nor hfw_dl implements natural-language semantic search or AI worship planning.
  • MCP Status: packages/hfw_server/admin/mcp.go is entirely commented out. packages/hfw_cms and packages/hfw_dl recently shipped browser WebMCP tool surfaces (c6b94db, ae9031c, e.g. search_downloadable_hymns), which are browser-side tools rather than a public/external MCP server for Claude or third-party AI agents.

Recommended Next Step (Keep on Roadmap & Split into 3 Tracks):
This issue bundles three independent deliverables with different technical, legal, and monetization requirements:

  1. Track 1 (Keep in #224) — Semantic Lyrics Search: Pre-compute Gemini embeddings for hymn stanzas/choruses/topics, store in a vector index (sqlite-vec or Postgres pgvector), expose a semantic query API, and add natural-language search UI.
  2. Track 2 (Split) — AI-Assisted Worship Service Planner: Thematic set-list generation + tweakable playlist output (depends on Track 1 + monetization alignment with #9 regarding Basic vs. Pro tier).
  3. Track 3 (Split) — Public Lyrics Query API / External MCP Server: Requires explicit hymn copyright/licensing review before exposing lyrics externally to third-party AI agents.