Skip to content

Fix: Handle whitespace-only question in /retrieval endpoint - #12831

Merged
KevinHuSh merged 1 commit into
infiniflow:mainfrom
Achieve3318:fix/retrieval-whitespace-validation
Jan 27, 2026
Merged

KevinHuSh merged 1 commit into
infiniflow:mainfrom
Achieve3318:fix/retrieval-whitespace-validation

Conversation

@Achieve3318

Copy link
Copy Markdown

Description

This PR fixes issue #12805 by adding validation to handle whitespace-only questions in the /retrieval endpoint.

Problem

Sending a single space " " as the question parameter to /retrieval crashes the request with an AssertionError. This happens because:

  1. The endpoint doesn't trim or validate the question parameter
  2. A whitespace-only string is treated as valid input
  3. The retrieval logic only checks for empty strings (which are falsy), but " " is truthy
  4. Invalid match expressions are constructed, causing an assertion failure in the Elasticsearch layer

Solution

  • Trim whitespace from the question parameter before processing
  • Return an empty result for whitespace-only or empty questions
  • Prevents the AssertionError and provides expected behavior

Changes

  • Added whitespace trimming and validation in api/apps/sdk/doc.py
  • Returns empty result early if question is empty after trimming

Testing

  • Tested with single space input - now returns empty result instead of crashing
  • Tested with empty string - returns empty result
  • Tested with normal questions - works as expected

Fixes #12805

- Trim whitespace from question parameter before processing
- Return empty result for whitespace-only or empty questions
- Prevents AssertionError when single space is sent as question
- Fixes issue infiniflow#12805
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐖api The modified files are located under directory 'api/apps/sdk' 🐞 bug Something isn't working, pull request that fix bug. labels Jan 26, 2026
@Achieve3318

Copy link
Copy Markdown
Author

Hi, @yingfeng @claude @rantav
Could you review my PR, please?
Thank you

@KevinHuSh KevinHuSh added the ci Continue Integration label Jan 27, 2026
@KevinHuSh
KevinHuSh marked this pull request as draft January 27, 2026 01:45
@KevinHuSh
KevinHuSh marked this pull request as ready for review January 27, 2026 01:45
@Achieve3318

Copy link
Copy Markdown
Author

Hi, @KevinHuSh
When can my PR be reviewed?

@KevinHuSh
KevinHuSh merged commit e77168f into infiniflow:main Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐖api The modified files are located under directory 'api/apps/sdk' 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Sending a single space as the question to /retrieval crashes (AssertionError)

2 participants