Related Tips: Cosine Similarity Score Badge

Date: 2026-07-26 Status: Approved

Goal

Make the "Related Tips" section on tip pages nerdier by showing the actual cosine similarity score for each related tip, rendered as a small monospace badge: cos θ = 0.512. No bar, no percentage, no graph — raw score only.

Background

Relatedness is computed offline by deno task related (_og/build-related.ts) from OpenRouter embeddings. topKNeighbors() in _lib/related-tips.ts already returns {slug, score} per neighbor, but build-related.ts currently drops the score when writing _og/related.json (entries are {slug, tip_number} only). The score exists — it just isn't persisted or displayed.

Embeddings are cached in _og/.cache/ (keyed by content hash), so regenerating the index with a new format requires no API calls when no tip content changed.

Changes

1. _lib/related-tips.ts — rounding helper

Add a pure helper roundScore(score: number): number that rounds to 3 decimal places (e.g. 0.51234…0.512). Three decimals keeps related.json diffs stable and free of float noise while preserving enough precision to distinguish neighbors.

2. _og/build-related.ts — persist the score

Index entries become:

{ "slug": "…", "tip_number": 200, "score": 0.512 }

using roundScore(). After the code change, run deno task related once to regenerate _og/related.json (cache hit — no key/network needed) and commit the JSON.

3. _config.ts — carry score through

4. _includes/tip.vto — render the badge

The related-card header line (currently just Tip {{ tip_number }}) becomes a flex row:

Error handling / edge cases

Testing

Out of scope