Skip to content

Comments

fix: Handle AttributeError in hybrid search with reranking (#17046)#19025

Merged
tjbck merged 1 commit intoopen-webui:devfrom
krishna-medapati:fix-hybrid-search-17046-clean
Nov 10, 2025
Merged

fix: Handle AttributeError in hybrid search with reranking (#17046)#19025
tjbck merged 1 commit intoopen-webui:devfrom
krishna-medapati:fix-hybrid-search-17046-clean

Conversation

@krishna-medapati
Copy link
Contributor

Description

Fixes #17046 - AttributeError when using hybrid search with reranking enabled.

Problem

The current code attempts to access collection_result.documents in the conditional check even after using hasattr(). Due to Python's short-circuit evaluation behavior, when collection_result is a list or doesn't have the documents attribute, the subsequent conditions still try to access .documents, causing an AttributeError.

Solution

Split the attribute existence checks from the content validation checks:

  1. First verify that both documents and metadatas attributes exist
  2. Then separately validate the document content in a second conditional block

Changes

  • Added separate conditional blocks for attribute existence checks vs content validation
  • Added hasattr() check for metadatas attribute (was missing)
  • Prevents AttributeError while maintaining all original validation logic
  • Added clarifying comments to explain the two-stage validation

Testing

Impact

This fix ensures that hybrid search with reranking works correctly without throwing AttributeError when the collection result doesn't have the expected structure.


Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note: Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.

…i#17046)

- Split attribute existence checks from document content checks
- Added hasattr() check for metadatas attribute
- Prevents AttributeError when collection_result is missing attributes
- Maintains all original validation logic

Fixes open-webui#17046
@tjbck
Copy link
Contributor

tjbck commented Nov 10, 2025

Thanks!

@tjbck tjbck merged commit 284764e into open-webui:dev Nov 10, 2025
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