余弦相似度 · 看朝向有多近
Cosine Similarity · Compare Where Vectors Point
dot product ÷ magnitudes → cosine of the angle
先在点积页看到方向对齐会改变乘加结果;这里再除去两支向量的长度,只留下夹角带来的相似度。
The dot-product lesson showed that alignment changes the multiply-add result. Here we divide out both magnitudes, leaving similarity due to angle.
01 · 先别看公式
01 · Before the formula
一支箭头画得更长,就应该被判定为“意思更像”吗?
Should a longer arrow automatically count as “more similar in meaning”?
cos θ
02
拖动“电机故障”查询方向
Rotate the “Motor Fault” Query
唯一变量:查询角度
One variable: query angle
最像
Nearest
D1
cos θ
1.00
−1 … 1
夹角Angle gap
0°
越小越同向
smaller means aligned
03
从点积接出 4 个零件
Four Parts That Extend Dot Product
S1-07 → S1-08
DOT PRODUCT
先算对齐乘加
Start with alignment
q⃗·d⃗ 同时受夹角和两边长度影响。
q⃗·d⃗ depends on angle and both magnitudes.
NORMALIZE
除去长度 Divide out magnitude
除以 ‖q⃗‖‖d⃗‖ 后,不再奖励“画得更长”。
Dividing by ‖q⃗‖‖d⃗‖ removes the reward for being longer.
ANGLE
只留下夹角Keep only angle
同向接近 1,垂直接近 0,反向接近 −1。
Same direction approaches 1, perpendicular 0, opposite −1.
RANK
按分数重排Rank by score
查询一旋转,所有文档分数都要重算。
Rotating the query recomputes every document score.
04
最小机制:点积除以两边长度
Minimal Mechanism: Dot Product over Both Magnitudes
normalized dot product
cos(q⃗,d⃗) = (q⃗·d⃗) / (‖q⃗‖ ‖d⃗‖)
上方所有向量长度不同,但排名只随夹角变化。把查询拖到任一文档方向即可验证其分数接近 1。
The vectors above have different lengths, yet ranking follows angle. Align the query with any document to verify its score approaches 1.
旋转 q⃗
Rotate q⃗与每个 d⃗ 的夹角变化angle to every d⃗ changes
计算 cos θ
Compute cos θ长度影响被消掉
magnitude influence is removed
排行榜刷新
Ranking refreshes
最同向者排前most aligned ranks first
05
边界实验:很像,但版本已经过期
Boundary Test: Highly Similar, but Outdated
主动制造失败Create a failure
让旧版维修指南排到第一 Rank the old repair guide first
它的方向和查询最接近,所以余弦分数很高;但“相似”没有检查日期、权限或事实状态。
Its direction best matches the query, so cosine score is high. Similarity does not check date, permissions, or factual status.
尚未执行。先观察正常的角度排序。
Not run yet. Inspect the normal angle-based ranking first.
✗
箭头越长,余弦相似度越高。
Longer arrows always have higher cosine similarity. → ✓
长度被归一化,主要比较方向。
Magnitudes are normalized; direction drives the score.
✗ 分数 1 就代表事实正确。
A score of 1 means factually correct. → ✓
1 只说明表示方向一致。
1 only means the representations align.
✗
余弦排序不需要过滤。 Cosine ranking needs no filtering.
→ ✓
版本、权限和元数据仍要单独校验。
Version, permission, and metadata still need checks.
06 · 一句话带走
06 · One line to keep
余弦相似度用夹角而非长度比较方向有多接近;拖动查询能验证排名会变,但高相似不等于内容有效。
Cosine similarity compares directional alignment rather than length. Drag the query to verify rankings change—but a high score does not make content valid.