Back to Showcases
EntertainmentAdvanced

Music Streaming Playlist Generation

Typed co-listen edges plus MMR diversity over a graph frontier

Vector SearchTyped Co-Listen EdgesMMR Diversity (Vector Math)Hybrid Query
MMR Lambda
Diversity
96%+
Relevance
<5ms
Latency
All
Tests Passed

The Scenario

Song audio and lyric embeddings are stored for similarity, and CO_LISTEN and PLAYLIST_WITH edges are bulk-imported from real playlists and listening sessions, with provenance. A hybrid query seeds by similarity, traverses the co-listen edges to reach tracks genuinely played alongside the seed (including across genres), and ranks the surviving frontier. MMR then shapes the mix over that frontier, trading relevance against diversity. The jazz-to-electronic bridge is an authored edge grounded in real sessions, not an audio-similarity guess.

Key Results

  • Cross-genre bridges are authored co-listen edges, grounded in real sessions
  • MMR shapes the mix over the graph-built frontier, avoiding near-duplicates
  • Balanced playlists with both relevance and variety
  • Real-time playlist generation under 5ms
MMR Lambda
Diversity
96%+
Relevance
<5ms
Latency
All
Tests Passed

The Code

Everything above, in a few lines of Python.

python
# Structure first: reach co-listened tracks via typed edges.
frontier = (
    client.graph.query("songs")
    .vector_similar(seed_track_embedding, k=50)
    .traverse("CO_LISTEN", direction="outgoing")
    .vector_rank(seed_track_embedding, k=40)
    .return_nodes()
)

# Then shape the mix with MMR over that frontier (vector math).
playlist = client.math.mmr("songs",
    query_vector=seed_track_embedding,
    k=20,
    lambda_param=0.7  # Balance relevance vs diversity
)

Try it yourself

Clone the repo, spin up SwarnDB, and run this showcase in minutes.

View on GitHub