Date: 2026-07-26 Status: Approved
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.
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.
_lib/related-tips.ts — rounding helperAdd 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.
_og/build-related.ts — persist the scoreIndex 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.
_config.ts — carry score throughRelatedRef gains an optional score?: number.data.relatedTips,
attach the entry's score to the resolved ref.related: front-matter override path (hand-picked tip numbers) stays
score-less; score remains undefined there. No tip currently uses the
override._includes/tip.vto — render the badgeThe related-card header line (currently just Tip {{ tip_number }}) becomes
a flex row:
Tip 200 (unchanged styling).cos θ = 0.512 in font-mono text-xs, same muted opacity as the
tip-number label.related.score !== undefined — cards from a
front-matter override (or a stale index without scores) render exactly as
today.toFixed(3)).related.json (no score field): builds fine; badges are
simply absent. No hard dependency on the new field.related: override: cards render without badges.roundScore() in _lib/related-tips_test.ts (typical value,
already-round value, boundary rounding).topKNeighbors tests already pin score computation.deno task serve: badge visible on a tip page, aligned
right, mono font.