Skip to content

feat(recall): add opt-in BM25 query term cap#2567

Merged
benfrank241 merged 2 commits into
vectorize-io:mainfrom
r266-tech:fix/bm25-query-term-cap-2528
Jul 7, 2026
Merged

feat(recall): add opt-in BM25 query term cap#2567
benfrank241 merged 2 commits into
vectorize-io:mainfrom
r266-tech:fix/bm25-query-term-cap-2528

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

Fixes #2528 by adding an opt-in cap for PostgreSQL native BM25 query terms.

Native to_tsquery currently OR-joins every normalized query token. For very long recall/consolidation queries, that can produce a huge query that matches too much of a large bank. This adds HINDSIGHT_API_BM25_MAX_QUERY_TERMS so deployments can bound the native tsquery term list.

Compatibility notes:

  • The default is 0, which preserves the existing uncapped behavior.
  • Positive values cap only PostgreSQL native BM25 term preparation.
  • VectorChord, pg_textsearch, PGroonga, and pg_search continue to receive the raw query text.
  • Oracle accepts the expanded dialect argument but keeps its existing behavior.

Tests

uv run --python 3.12 --project hindsight-api-slim --group dev ruff format --check hindsight-api-slim/hindsight_api/engine/search/retrieval.py hindsight-api-slim/hindsight_api/config.py hindsight-api-slim/hindsight_api/engine/sql/base.py hindsight-api-slim/hindsight_api/engine/sql/postgresql.py hindsight-api-slim/hindsight_api/engine/sql/oracle.py hindsight-api-slim/tests/test_multilingual_bm25.py hindsight-api-slim/tests/test_recall_config.py
uv run --python 3.12 --project hindsight-api-slim --group dev ruff check hindsight-api-slim/hindsight_api/engine/search/retrieval.py hindsight-api-slim/hindsight_api/config.py hindsight-api-slim/hindsight_api/engine/sql/base.py hindsight-api-slim/hindsight_api/engine/sql/postgresql.py hindsight-api-slim/hindsight_api/engine/sql/oracle.py hindsight-api-slim/tests/test_multilingual_bm25.py hindsight-api-slim/tests/test_recall_config.py
uv run --python 3.12 --project hindsight-api-slim --group dev pytest hindsight-api-slim/tests/test_multilingual_bm25.py hindsight-api-slim/tests/test_recall_config.py -q

Codex adversarial review: approved after reworking the cap to be opt-in and keeping legacy config/dialect behavior compatible.

@benfrank241 benfrank241 merged commit 7143684 into vectorize-io:main Jul 7, 2026
85 of 86 checks passed
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.

recall: unbounded BM25 tsquery makes keyword recall O(bank_size) on long query text — stalls large-bank consolidation

2 participants