The search fails on huge query
Author: nishanthm-plivoCreated Jun 6, 2026Updated Jun 6, 2026
Describe the bug
Hybrid / full-text search throws a Postgres error tsquery stack too small on long queries (~100+ words) and returns no results. The raw query is passed straight into websearch_to_tsquery, for a long query the generated tsquery exceeds Postgres's node/stack limit and the FTS query fails. Semantic/vector-only search is unaffected — only the full-text leg dies, which silently breaks hybrid search.
To Reproduce
Code:
from r2r import R2RClient
c = R2RClient("http://localhost:7272")
# any query with 100+ words
long_q = ("how do i set up whatsapp messaging and configure webhooks for inbound "
"messages and delivery reports and also troubleshoot why my template is "
"stuck in review and what the rate limits are ... ") # ~100+ words
c.retrieval.search(query=long_q, search_settings={"use_hybrid_search": True})Output: R2RException: Internal Server Error (server log: "tsquery stack too small")
Expected behavior A long query shouldn't crash keyword search (standard BM25 — Lucene/ES, Qdrant sparse — has no such limit). Either:
- sanitize/cap the query terms before
websearch_to_tsquery - catch the FTS error and fall back to vector-only so hybrid still returns results instead of nothing.
Environment
- R2R: 3.6.6 (light/r2r-serve deploy)
- Postgres: 16.14 + pgvector
- Search mode: hybrid (use_hybrid_search=true) / full-text; vector-only unaffected
- OS: macOS
Source: SciPhi-AI/R2R