Skip to content

fix: handle single-query exact search#218

Open
GioiaZheng wants to merge 1 commit into
beir-cellar:mainfrom
GioiaZheng:fix-exact-search-single-query
Open

fix: handle single-query exact search#218
GioiaZheng wants to merge 1 commit into
beir-cellar:mainfrom
GioiaZheng:fix-exact-search-single-query

Conversation

@GioiaZheng

Copy link
Copy Markdown

Why

DenseRetrievalExactSearch.search() clamps torch.topk with len(cos_scores[1]). When the input has a single query, cos_scores has shape (1, n_docs), so reading row 1 raises an IndexError before retrieval can return results.

Closes #217.
Closes #170.

What changed

  • Use cos_scores.shape[1] to clamp top_k by the corpus/document dimension.
  • Add a regression test that runs exact dense search with one query and two documents.

Validation

  • .venv\Scripts\python.exe -m pytest tests\retrieval\search\dense\test_exact_search.py
  • .venv\Scripts\python.exe -m ruff check beir\retrieval\search\dense\exact_search.py tests\retrieval\search\dense\test_exact_search.py
  • .venv\Scripts\python.exe -m ruff format --check beir\retrieval\search\dense\exact_search.py tests\retrieval\search\dense\test_exact_search.py

Risk / follow-up

Low risk. The change only corrects the top-k candidate limit to use the document dimension and leaves the ranking and heap logic unchanged.

@GioiaZheng

Copy link
Copy Markdown
Author

Quick status follow-up: this remains ready for review and mergeable against current main. The change is limited to correcting the document-axis top-k clamp plus a single-query regression test. Happy to adjust the fixture style or rebase if preferred.

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.

search/dense/exact_search failes at num_queries = 1 retriever.retrieve(corpus, queries) with len(queries)==1 errors

1 participant