Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed

- Tier 2 content clustering keeps pairwise similarities in packed doubles instead of
Comment thread
Afloat16 marked this conversation as resolved.
Resolved
per-pair dictionary entries, reducing memory use for large skills without changing cluster scores.
- Direct Tier 1 validates the target, selected checks and LLM configuration before
preparing scanners, so configuration errors do not trigger downloads or stdout noise.
- Documentation-only CI follows imports through collected test modules and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

from array import array
from dataclasses import dataclass, field, replace
from itertools import combinations
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -108,11 +109,13 @@ def siblings(i: int, j: int) -> bool:
return group is not None and group == chunks[j].split_group

uf = UnionFind(n)
pair_scores: dict[tuple[int, int], float] = {}
# Row i contains the upper-triangle scores (i, i + 1), ..., (i, n - 1).
# Packed doubles avoid a tuple key and boxed float for every pair.
pair_scores = [array("d") for _ in range(n - 1)]

for i, j in combinations(range(n), 2):
score = unit_vector_similarity(units[i], units[j])
pair_scores[(i, j)] = score
pair_scores[i].append(score)
if score >= threshold and not siblings(i, j):
uf.union(i, j)

Expand All @@ -122,7 +125,7 @@ def siblings(i: int, j: int) -> bool:
continue

members = _merge_split_pieces([chunks[i] for i in indices])
scores = [pair_scores[(i, j)] for i, j in combinations(indices, 2) if not siblings(i, j)]
scores = array("d", (pair_scores[i][j - i - 1] for i, j in combinations(indices, 2) if not siblings(i, j)))

clusters.append(
ContentCluster(
Expand Down
17 changes: 17 additions & 0 deletions tests/deduplication/intra_skill/test_semantic_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ def test_path_compression(self) -> None:


class TestBuildClusters:
def test_separated_cluster_members_keep_their_pair_scores(self, make_chunk) -> None:
chunks = [
make_chunk(source_file=f"{index}.md", embedding=vector)
for index, vector in enumerate(
[[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0], [0.0, 0.6, 0.8], [0.96, 0.28, 0.0]]
)
]

clusters = build_clusters(chunks, threshold=0.75)

assert [[member.source_file for member in cluster.members] for cluster in clusters] == [
["0.md", "4.md"],
["1.md", "3.md"],
]
assert [cluster.max_similarity for cluster in clusters] == pytest.approx([0.96, 0.8])
assert [cluster.avg_similarity for cluster in clusters] == pytest.approx([0.96, 0.8])

def test_fewer_than_2_chunks_returns_empty(self, make_chunk) -> None:
assert build_clusters([make_chunk(embedding=[1.0, 0.0])]) == []
assert build_clusters([]) == []
Expand Down