Skip to content

fix: handle missing highlightScores from Exa API#253

Open
TejNadkarni wants to merge 2 commits intoMetaculus:mainfrom
TejNadkarni:fix/exa-highlight-scores-empty
Open

fix: handle missing highlightScores from Exa API#253
TejNadkarni wants to merge 2 commits intoMetaculus:mainfrom
TejNadkarni:fix/exa-highlight-scores-empty

Conversation

@TejNadkarni
Copy link
Copy Markdown

@TejNadkarni TejNadkarni commented May 9, 2026

Summary

The Exa API has stopped returning highlightScores alongside highlights in some responses. The current code iterates using zip(source.highlights, source.highlight_scores), which silently yields nothing when highlight_scores is an empty list — causing all highlights to be dropped even when the API returns valid content.

Observed behavior: 10 sources returned, 0 quotes collected, final output: "No search results found for the query using the search filter chosen".

Fix: Default missing scores to 1.0 per highlight when the scores array is empty.

# Before
for highlight, score in zip(source.highlights, source.highlight_scores):

# After
scores = source.highlight_scores or [1.0] * len(source.highlights)
for highlight, score in zip(source.highlights, scores):

I verified the fix by inspecting raw Exa API responses and confirming highlightScores is returned as [] while highlights contains valid content. A test case covering the empty highlightScores fallback has been added to test_exa_model.py.

The Exa API has stopped returning highlightScores in some responses,
causing zip(highlights, highlight_scores) to silently yield nothing
and all highlights to be dropped (0 quotes found despite 10+ sources).

Default to a score of 1.0 per highlight when the scores array is empty.
Copilot AI review requested due to automatic review settings May 9, 2026 07:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an Exa API response-shape regression where highlightScores may be missing/empty even when highlights is present, which previously caused all highlights to be dropped due to zip() truncation.

Changes:

  • Default highlight_scores to 1.0 per highlight when the scores list is empty.
  • Preserve highlight extraction and relevance-order sorting even when Exa returns highlightScores: [].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +147 to +148
scores = source.highlight_scores or [1.0] * len(source.highlights)
for highlight, score in zip(source.highlights, scores):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants