A production-oriented architecture for turning "something for a late-night drive, not too sad, a bit nostalgic" into a real playlist — without hallucinating songs that don't exist.

If you've ever typed "rainy city, neon, heartbeat, but not depressing" into a music app and gotten back a playlist that feels like it was assembled by a committee, you already know the problem:

Music is multimodal, cultural, and vague. Tags like genre: indie or mood: chill collapse under the weight of how people actually describe what they want to hear.

Over the last year, the teams shipping real LLM-powered music features (NetEase's Muse Mix, Spotify's AI DJ / podcast generation, YouTube Music's discovery surfaces) have converged on a similar shape: not a bigger model, but a knowledge layer around the model.

This post is an architecture design doc for that knowledge layer — written for engineers who have to ship it, not just demo it.

  1. The Business Scenarios We Actually Have to Support

Before drawing boxes, here's what the app needs to do. Each scenario stresses the architecture differently.

Scenario User says… System must

S1 Natural-language playlist generation "45 min of focus music for coding at 2am, no vocals, slightly melancholic" Parse mood/tempo/context, retrieve real tracks, explain choices

S2 Conversational DJ "Ok now make it more energetic but keep the same vibe" Carry session context, mutate constraints, avoid whiplash

S3 Music Q&A / artist knowledge "Why does this song remind me of 2000s R&B?" Grounded answer over catalog + editorial + web-free facts

S4 Cold-start / new release discovery New user, new AI-generated track, no interactions Content understanding, not just collaborative filtering

S5 Creator tools "Write me a lo-fi loop in A minor at 85 BPM" Generate, moderate, store under user, attach rights metadata

The key insight: S1–S4 are retrieval-and-grounding problems. S5 is a generation-and-lineage problem. Both need a knowledge base, but they need different shapes of it.

  1. Why "Just RAG" Fails for Music

Classic RAG assumes: documents → chunks → vectors → retrieve → generate. For a music catalog this breaks in three places:

  1. The item is not the document. A track's "document" is audio + lyrics + editorial + listening context + rights metadata. One vector cannot represent all of that.
  2. The LLM will invent songs. Ask a raw LLM for "sad mandolin songs from 2011" and it will happily give you plausible-sounding tracks that don't exist in your catalog. NetEase's Melo paper reports 17.4% entity misidentification before they added grounding.
  3. Collaborative signal has no text. "Users who liked X also liked Y" is not natively representable in prose.

So the knowledge base is not one vector index. It is a federated knowledge system with a strict rule:

The LLM proposes; the catalog disposes. No track ID reaches the client unless the runtime verified it exists, is licensed for this user's region, and matches the parsed constraints.

  1. The Three Knowledge Planes

Plane A — Catalog Knowledge (what exists)

• Track / Album / Artist / Label entities in a graph (Neo4j or TigerGraph)

• Audio-derived features: BPM, key, energy, danceability, timbre embeddings (CLAP / HTS-AT)

• Text-derived features: lyrics embeddings, editorial tags, user-generated mood words

• Rights & availability: territory, subscription tier, explicit-content flag

Plane B — Taste Knowledge (what this user wants)

• Long-term taste vector (updated nightly, from full history)

• Short-term session vector (last ~20 events, in-memory)

• Explicit signals: likes, dislikes, "don't play this artist", tempo preferences

• Stored as soft tokens that get projected into the LLM's context at inference time — the same trick Spotify uses to personalize without retraining per user

Plane C — World Knowledge (what music means)

• Editorial articles, album reviews, artist bios, liner notes

• Cultural associations: "this was in Lost in Translation", "SoundCloud rap 2017"

• Stored as classic RAG chunks with provenance, used only for explanation and Q&A — never for track identity

Rule: Plane C can explain a recommendation, but it cannot originate one.

  1. High-Level Architecture

┌──────────────────────────────────────────────────────────┐
│ Client (iOS / Android / Web) │
│ ├─ Player │
│ ├─ Conversation UI │
│ └─ On-device mini-index (top 5k recent tracks, HNSW) │
└──────────────┬───────────────────────────────────────────┘
│ HTTPS / WebSocket
┌──────────────▼───────────────────────────────────────────┐
│ API Gateway + Auth + Rate Limit │
└──────────────┬───────────────────────────────────────────┘
│
┌──────────────▼───────────────────────────────────────────┐
│ Orchestrator (deterministic state graph) │
│ UNDERSTAND → PLAN → RETRIEVE → GROUND → RERANK → SAY │
│ │
│ (LLM calls only inside UNDERSTAND, PLAN, SAY) │
└──┬───────┬────────┬────────┬────────┬───────────────────┘
│ │ │ │ │
┌──▼──┐ ┌─▼──┐ ┌───▼──┐ ┌──▼───┐ ┌─▼──────┐
│Text │ │Audio│ │Collab│ │Graph │ │Editorial│
│Vec │ │Vec │ │Index │ │Store │ │RAG │
│Idx │ │Idx │ │(CF) │ │(KG) │ │(Plane C)│
└──┬──┘ └─┬──┘ └───┬──┘ └──┬───┘ └──┬─────┘
└──────┴────────┴───────┴────────┘
│
┌──────────▼──────────┐
│ Catalog Runtime │ ← the only source of truth
│ (TrackID, rights, │ for "what can play"
│ region, dislike) │
└─────────────────────┘

Why a deterministic state graph, not a free-form agent?

NetEase tried the ReAct-style loop first. It failed in production because intent-parsing errors compound across steps, and end-to-end success dropped below shipping threshold. Their fix — and ours — is a fixed 5–6 node graph where each failure mode has a named home you can swap without rewriting the controller.

  1. Node-by-Node Design

Node 1 — UNDERSTAND (LLM, structured output)

Input: raw utterance + session context.
Output: strict JSON, no prose.
{
"mood": ["melancholic", "nostalgic"],
"energy": [0.3, 0.55],
"tempo_bpm": [80, 110],
"vocals": "any",
"context": "late_night_driving",
"avoid": ["heavy_metal", "explicit"],
"target_count": 30,
"max_per_artist": 2,
"time_range": null,
"language": ["en", "zh"]
}

Validation is deterministic: out-of-range BPM? clamp. Unknown mood? drop. If JSON fails validation, retry once, then fall back to last-known-good intent.

Node 2 — PLAN (small LLM or even a policy table)

Maps intent → which retrievers to fire, with per-retriever k:
• Semantic (text index): k=200

• Audio-similarity (CLAP index): k=200

• Collaborative (user-vector neighbors): k=150

• Graph expansion (artist → similar artists → tracks): k=100

• Editorial/scene index (curated "late-night-driving" shelves): k=50

Node 3 — RETRIEVE (parallel, fan-out/fan-in)

Each retriever returns (track_id, score, reason).
Merge with Reciprocal Rank Fusion (simple, robust, beats learned fusion at small k):
def rrf(rank_lists, k=60):
scores = {}
for lst in rank_lists:
for rank, tid in enumerate(lst):
scores[tid] = scores.get(tid, 0) + 1 / (k + rank)
return sorted(scores, key=scores.get, reverse=True)

Node 4 — GROUND (the most important node)

This is where hallucinated songs die.

• Every candidate must resolve to a real TrackID in the catalog runtime.

• Resolve by (normalized_title, normalized_artist); require artist match for fuzzy title.

• Reject on ambiguity. Never guess.

• Apply hard filters: region license, explicit flag, user dislikes, already-played-in-session, max_per_artist.

• NetEase's three-layer grounding cut entity errors from 17.4% → 9.6% in production.

Node 5 — RERANK

Cross-encoder or lightweight LambdaMART over 200 → 30, optimizing:
• completion probability

• save / add-to-playlist probability

• skip-within-30s as the only reliable negative

• diversity penalty (MMR on artist + genre + language)

• scenario rules (bedtime → lower energy; workout → rising energy)

Node 6 — SAY (LLM, streaming)

Generates playlist title, description, and per-track one-liners only from grounded IDs. If grounding removed half the candidates, the explainer says "I kept 18 of the 30 I looked at — here's why the rest didn't make the cut." Honesty > polish.

  1. Multi-Modal Indexing: The Heart of the Knowledge Base

A track enters four indexes at ingest time:

Index Content Model Purpose

text_vec title + artist + lyrics + tags + editorial BGE-M3 / Qwen3-Embedding "songs about rain"

audio_vec mel-spectrogram, 30s clip CLAP / HTS-AT "sounds like this track"

collab_vec item2vec from playlists BPR / Swing "people who…"

graph entities + relations — artist → influencer → genre → era

New or AI-generated tracks start with zero collaborative signal — which is exactly why the audio+text planes matter. Spotify's shift toward Semantic IDs (quantizing content vectors into discrete tokens an LLM can autoregress) is one clean answer to "how do you let an LLM speak your catalog". We borrow the idea: each track gets a 5-token semantic ID, stored alongside its UUID.

  1. Freshness, Rights, and the Stuff That Breaks at 3am

Incremental indexing

• New track → audio analysis job (async, ~2s) → write to all indexes in a single transaction with a visible_at timestamp.

• Rights change (label pulls a territory) → tombstone in runtime, not a re-index. Grounding filters it out in <10ms.

Consistency

• Catalog DB is source of truth; vector/graph stores are derived.

• Every night: reconcile counts, repair orphans, rebuild hot-shard HNSW.

Privacy

• Taste vectors never leave the server unencrypted.

• On-device mini-index (see diagram) handles "play something from my library" offline; server handles discovery.

Cost control

• 80% of requests never touch the LLM: cached intent templates + retrieval-only path.

• The LLM runs only on UNDERSTAND and SAY. PLAN can be a decision table for the top 50 intents.

• Spotify's team found a ~1B-parameter model is enough for catalog-scale generation when the heavy lifting is done by retrieval and soft-token personalization. We run a 3B quant at the edge and a 7B–14B in the cluster, not 70B+.

  1. Evaluation: What We Actually Measure

Offline ≠ vibes. We track:

Layer Metric

Retrieval Recall@100 per channel, RRF gain vs single-channel

Grounding Hallucination rate (ungrounded IDs surfaced) — target < 0.1%

Ranking Completion@30s, skip@30s, save rate, add-to-playlist

Session Playlist dwell time, tracks-per-session, next-day return

Generation Explanation faithfulness (LLM-as-judge vs human spot-check)

System P50 / P99 latency, LLM cost per 1k generations

YouTube Music's discovery work showed the LLM's value came almost entirely from explanation layered on an existing retrieval+rank stack, not from LLM-originated candidates — a result worth remembering before you over-invest in generative retrieval.

  1. When Things Degrade

• LLM down → serve cached intent patterns; skip SAY; return grounded tracks with template explanations.

• Vector index stale → fall back to collaborative + editorial shelves.

• Grounding rejects >50% → widen title matching, drop artist requirement only for unambiguous titles, and log for review.

• Abusive prompt → refuse at UNDERSTAND; never pass to retrieval.

Every degradation path still returns real, licensed, playable tracks. A boring playlist beats a broken one.

  1. What We Deliberately Did Not Do

• No "one embedding to rule them all." Pure vector search lies; pure CF forgets new music.

• No free-form agent loop in the online path. Debugging non-determinism at 2am is not a personality trait.

• No LLM-generated TrackIDs, ever. Not even in tests.

• No training our own foundation model. In 2026, the leverage is in the knowledge layer, not in another 7B music LM.

TL;DR

A music-app knowledge base for LLMs is:
• Three planes (catalog / taste / world), not one vector store

• Multi-modal ingest (audio + text + collaborative + graph)

• A deterministic orchestration graph with a non-negotiable grounding node

• Soft-token personalization instead of per-user fine-tuning

• LLM for intent and explanation; retrieval for truth

The model is the brain. The knowledge base is the spine. Without the spine, the brain invents songs your users will never be able to play.

If you've shipped something adjacent — podcasts, short-video BGM, AI music generation, in-car audio — I'd love to compare notes in the comments. Specifically: how do you handle catalog drift when rights change mid-session? That's the one we're still iterating on.