Skip to content
Merged
Changes from all 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
16 changes: 11 additions & 5 deletions adapters/code_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,14 @@ def _ground_single(
# collapses to BM25-only.
# 2. Rank symbols within each qualifying file (relevant ones
# come first).
matched_ids: set[int] = set()
matched_scores: dict[int, float] = {}
if tokens:
try:
validated = self._validate_with_threshold(tokens, fuzzy_threshold)
matched_ids = {v["symbol_id"] for v in validated if v.get("symbol_id")}
for v in validated:
sid = v.get("symbol_id")
if sid:
matched_scores[sid] = max(matched_scores.get(sid, 0), v["match_score"])
except Exception as exc:
logger.debug("[ground] fuzzy validate failed for '%s': %s", description[:60], exc)

Expand All @@ -225,10 +228,12 @@ def _ground_single(
try:
rows = db.lookup_by_name(name)
for row in rows:
matched_ids.add(row["id"])
matched_scores[row["id"]] = max(matched_scores.get(row["id"], 0), 100.0)
except Exception as exc:
logger.debug("[ground] symbol name lookup failed for '%s': %s", name, exc)

matched_ids = set(matched_scores)

# Stage 1: multi-file fused retrieval (FC-2 fix, v0.4.6).
# Previously this stage took only the top-1 BM25 hit via next(),
# which collapsed multi-file features to a single anchor — the
Expand Down Expand Up @@ -273,7 +278,7 @@ def _ground_single(
relevant_ids = matched_ids & file_symbol_ids
ranked = sorted(
file_symbols,
key=lambda r: (r["id"] not in relevant_ids, r["start_line"]),
key=lambda r: (r["id"] not in relevant_ids, -matched_scores.get(r["id"], 0)),
)
for row in ranked[:per_file_budget]:
code_regions.append({
Expand All @@ -294,8 +299,9 @@ def _ground_single(
# Unchanged from v0.4.5 semantics.
if not code_regions and matched_ids:
try:
score_ranked_ids = sorted(matched_scores, key=matched_scores.get, reverse=True)
code_regions = self._regions_from_symbol_ids(
sorted(matched_ids)[:max_symbols], db, description,
score_ranked_ids[:max_symbols], db, description,
)
except Exception as exc:
logger.warning("[ground] fuzzy fallback failed: %s", exc)
Expand Down