Skip to content

Commit d5b9fc2

Browse files
nodeeeeeeclaude
andcommitted
Prefer bge-m3 over weak filename-token alignment matches
The name-similarity fallback accepts a Jaccard overlap of just 0.05, so captions like "EE4802_IE4213 on 07_04_2026 (Tue)" would match "EE4802_IE4213_Assignment2-AY2526.pdf" (score ≈ 0.22) and shadow the semantic bge-m3 pick. Every 07-04/13-03/17-03/… caption this session ended up aligned to the 6-slide Assignment2 PDF instead of its true ann-dated lecture deck, producing truncated notes with no figures. When bge-m3 has a match AND the name match isn't backed by a numeric lecture-id extraction, prefer bge-m3 and log that we're overriding. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 09d9e9a commit d5b9fc2

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

semantic_alignment.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,26 @@ def process_course(course_id: int | str, use_jina: bool = False,
18951895
print(f" [mapping] {cap.name}{[s.name for s in slide_group]}")
18961896
else:
18971897
# ── Priority 2: automatic name/number matching ───────────────────
1898-
slide_group = _find_best_slide_group(cap, slides_by_num, all_slides)
1898+
name_match = _find_best_slide_group(cap, slides_by_num, all_slides)
1899+
# When a caption name shares coarse tokens with many slide files
1900+
# (e.g. "EE4802_IE4213 on 07_04_2026" matches every slide whose
1901+
# name also starts with "EE4802_IE4213"), the token-overlap
1902+
# heuristic at >0.05 threshold can return a wrong but non-empty
1903+
# match that then shadows bge-m3's semantic pick. If a bge-m3
1904+
# match exists AND the name match is weak / didn't come from a
1905+
# numeric lecture-id extraction, trust bge-m3 instead.
1906+
if name_match and cap.stem in bge_matches:
1907+
num = _lec_num(cap)
1908+
name_is_number_based = (num is not None and num in slides_by_num)
1909+
if not name_is_number_based and bge_matches[cap.stem] != name_match:
1910+
print(f" [bge-m3] {cap.name}{[s.name for s in bge_matches[cap.stem]]} "
1911+
f"(overriding weak name match {[s.name for s in name_match]})")
1912+
slide_group = bge_matches[cap.stem]
1913+
else:
1914+
slide_group = name_match
1915+
else:
1916+
slide_group = name_match
1917+
18991918
if not slide_group and cap.stem in bge_matches:
19001919
# ── Priority 3: BGE-M3 embedding match ──────────────────────
19011920
slide_group = bge_matches[cap.stem]

0 commit comments

Comments
 (0)