Skip to content

Commit bec36dd

Browse files
mogeryclaude
andcommitted
feat(api/search): cap highlights at top_k=12 per page
Send top_k=12 on the query-highlights batch request so each page keeps at most the 12 highest-scoring spans after thresholding. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6b7249b commit bec36dd

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

apps/api/src/search/highlight-model.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ describe("generateHighlightsBatch", () => {
6363
query: "q1",
6464
lines: ["a one", "b one"],
6565
});
66-
// Threshold + budget are always sent so the cutoff matches the trained format.
66+
// Threshold + top_k + budget are always sent so the cutoff matches the trained format.
6767
expect(typeof sent.requests[0].threshold).toBe("number");
68+
expect(typeof sent.requests[0].top_k).toBe("number");
6869
expect(typeof sent.requests[0].max_highlight_chars).toBe("number");
6970
});
7071

apps/api/src/search/highlight-model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { config } from "../config";
1414
// Experimental score cutoff for keeping a span, tuned against the line-span
1515
// format the model was trained on.
1616
const HIGHLIGHT_THRESHOLD = 0.08;
17+
// Cap on how many spans to keep per page after thresholding (highest-scoring).
18+
const HIGHLIGHT_TOP_K = 12;
1719
// Character budget per page; the service keeps the highest-scoring spans until
1820
// the budget is reached (measured on raw span text).
1921
const MAX_HIGHLIGHT_CHARS = 800;
@@ -80,6 +82,7 @@ export async function generateHighlightsBatch(
8082
query: item.query,
8183
lines: item.lines,
8284
threshold: HIGHLIGHT_THRESHOLD,
85+
top_k: HIGHLIGHT_TOP_K,
8386
max_highlight_chars: MAX_HIGHLIGHT_CHARS,
8487
})),
8588
}),

0 commit comments

Comments
 (0)