Skip to content

Commit 0902469

Browse files
OriNachumclaude
andcommitted
fix(ci): epsilon guard in cosine similarity (Sonar S1244); fence languages (MD040)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJc5yvfweHP2AEccKNeaVd
1 parent 22fb76e commit 0902469

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

lobes/assess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ def _cosine_similarity(a: list[float], b: list[float]) -> float:
608608
dot = sum(x * y for x, y in zip(a, b))
609609
norm_a = math.sqrt(sum(x * x for x in a))
610610
norm_b = math.sqrt(sum(x * x for x in b))
611-
if norm_a == 0.0 or norm_b == 0.0:
611+
# Norms are non-negative; below this epsilon the vector is degenerate and
612+
# the similarity is meaningless (and the division would explode).
613+
if norm_a < 1e-12 or norm_b < 1e-12:
612614
return 0.0
613615
return dot / (norm_a * norm_b)
614616

tests/fixtures/upgrade_compat/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Source commit: `main` @ `7fa624d1c891c2bc1c5934947d0d9379462605e0`
99

1010
Vendored verbatim via:
1111

12-
```
12+
```sh
1313
git show main:lobes/templates/docker-compose.yml > single/docker-compose.yml
1414
git show main:lobes/templates/env.example > single/env.example
1515
git show main:lobes/templates/fleet/docker-compose.yml > fleet/docker-compose.yml

tests/goldens/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This directory holds the **byte-for-byte** golden files
1818

1919
Regenerate all three with:
2020

21-
```
21+
```sh
2222
uv run python tests/goldens/regen.py
2323
```
2424

0 commit comments

Comments
 (0)