Skip to content

Add optional score-based filtering to BaseRetriever with threshold support#21163

Open
Nithin00614 wants to merge 1 commit intorun-llama:mainfrom
Nithin00614:feature/retrieval-filtering
Open

Add optional score-based filtering to BaseRetriever with threshold support#21163
Nithin00614 wants to merge 1 commit intorun-llama:mainfrom
Nithin00614:feature/retrieval-filtering

Conversation

@Nithin00614
Copy link
Copy Markdown

Summary

This PR introduces an optional score-based filtering mechanism in BaseRetriever to improve the relevance of retrieved nodes.

Changes

  • Added enable_score_filter flag to toggle filtering
  • Added score_threshold parameter to control filtering behavior
  • Implemented _filter_nodes_by_score helper function
  • Integrated filtering into retrieval pipeline after recursive retrieval
  • Added unit tests to validate filtering behavior

Motivation

Currently, retrieved nodes may include low-relevance results. This feature allows users to filter nodes based on score, improving output quality and efficiency.

Tests

  • Added tests for:
    • Filtering enabled
    • Filtering disabled
    • Handling of None scores

All tests pass successfully.

Impact

  • Backward compatible (disabled by default)
  • Improves retrieval quality when enabled.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant