Skip to content

Adds support for HYBRID_POLICY on KNN queries with filters #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2025

Conversation

bsbodden
Copy link
Collaborator

Add support for hybrid policy and epsilon parameters in vector searches

This PR adds support for configuring hybrid search policy for vector searches and epsilon for vector range queries in RedisVL, matching the capabilities available in Redis Vector Search.

Changes

Added features:

  1. Hybrid Policy Control for VectorQuery

    • Added hybrid_policy parameter with options BATCHES or ADHOC_BF
    • Added batch_size parameter for controlling batch size in BATCHES mode
    • Implemented methods to get/set these parameters
  2. EPSILON Support for VectorRangeQuery

    • Added epsilon parameter to control range query boundaries
    • Implemented methods to get/set this parameter
    • Properly adds epsilon to query attributes, not as direct parameter

Tests:

  • Added unit tests for new parameters and methods
  • Added integration tests that verify query construction but avoid execution with unsupported parameters

Description

Redis Vector Search allows fine-tuning of vector queries through hybrid policy selection and epsilon configuration. This PR exposes these parameters in RedisVL, giving users better control over performance and accuracy trade-offs:

  • Hybrid Policy: Controls how filters are applied during vector search:

    • BATCHES: Paginates through small batches of nearest neighbors
    • ADHOC_BF: Computes scores for all vectors passing the filter
  • Epsilon: For range queries, controls boundary expansion through radius * (1 + epsilon), enabling deeper search at the expense of performance

Copy link
Collaborator

@tylerhutcherson tylerhutcherson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great -- only question -- are the hybrid policy and batches params only for KNN queries or vector range queries too? Can you also add the docstring for those similar to how you did for the epsilon param?

@bsbodden
Copy link
Collaborator Author

Looks great -- only question -- are the hybrid policy and batches params only for KNN queries or vector range queries too? Can you also add the docstring for those similar to how you did for the epsilon param?

Did the same treatment for the VectorRangeQuery - added more tests and fix the docstrings.

@bsbodden bsbodden closed this Mar 25, 2025
@bsbodden bsbodden reopened this Mar 25, 2025
@tylerhutcherson tylerhutcherson changed the base branch from main to 0.5.0 March 25, 2025 01:18
@bsbodden bsbodden force-pushed the bsb/RAAE-541 branch 2 times, most recently from 2c05e2b to 7900a1e Compare March 25, 2025 01:36
@tylerhutcherson tylerhutcherson added the enhancement New feature or request label Mar 25, 2025
@tylerhutcherson tylerhutcherson merged commit fb99e86 into 0.5.0 Mar 25, 2025
36 checks passed
@tylerhutcherson tylerhutcherson deleted the bsb/RAAE-541 branch March 25, 2025 13:22
abrookins pushed a commit that referenced this pull request Apr 4, 2025
# Add support for hybrid policy and epsilon parameters in vector
searches

This PR adds support for configuring hybrid search policy for vector
searches and epsilon for vector range queries in RedisVL, matching the
capabilities available in Redis Vector Search.

## Changes

### Added features:
1. **Hybrid Policy Control for VectorQuery**
- Added `hybrid_policy` parameter with options `BATCHES` or `ADHOC_BF`
- Added `batch_size` parameter for controlling batch size in `BATCHES`
mode
   - Implemented methods to get/set these parameters

2. **EPSILON Support for VectorRangeQuery**
   - Added `epsilon` parameter to control range query boundaries
   - Implemented methods to get/set this parameter
   - Properly adds epsilon to query attributes, not as direct parameter

### Tests:
- Added unit tests for new parameters and methods
- Added integration tests that verify query construction but avoid
execution with unsupported parameters

## Description

Redis Vector Search allows fine-tuning of vector queries through hybrid
policy selection and epsilon configuration. This PR exposes these
parameters in RedisVL, giving users better control over performance and
accuracy trade-offs:

- **Hybrid Policy**: Controls how filters are applied during vector
search:
  - `BATCHES`: Paginates through small batches of nearest neighbors
  - `ADHOC_BF`: Computes scores for all vectors passing the filter

- **Epsilon**: For range queries, controls boundary expansion through
`radius * (1 + epsilon)`, enabling deeper search at the expense of
performance

---------

Co-authored-by: Tyler Hutcherson <tyler.hutcherson@redis.com>
abrookins pushed a commit that referenced this pull request Apr 4, 2025
# Add support for hybrid policy and epsilon parameters in vector
searches

This PR adds support for configuring hybrid search policy for vector
searches and epsilon for vector range queries in RedisVL, matching the
capabilities available in Redis Vector Search.

## Changes

### Added features:
1. **Hybrid Policy Control for VectorQuery**
- Added `hybrid_policy` parameter with options `BATCHES` or `ADHOC_BF`
- Added `batch_size` parameter for controlling batch size in `BATCHES`
mode
   - Implemented methods to get/set these parameters

2. **EPSILON Support for VectorRangeQuery**
   - Added `epsilon` parameter to control range query boundaries
   - Implemented methods to get/set this parameter
   - Properly adds epsilon to query attributes, not as direct parameter

### Tests:
- Added unit tests for new parameters and methods
- Added integration tests that verify query construction but avoid
execution with unsupported parameters

## Description

Redis Vector Search allows fine-tuning of vector queries through hybrid
policy selection and epsilon configuration. This PR exposes these
parameters in RedisVL, giving users better control over performance and
accuracy trade-offs:

- **Hybrid Policy**: Controls how filters are applied during vector
search:
  - `BATCHES`: Paginates through small batches of nearest neighbors
  - `ADHOC_BF`: Computes scores for all vectors passing the filter

- **Epsilon**: For range queries, controls boundary expansion through
`radius * (1 + epsilon)`, enabling deeper search at the expense of
performance

---------

Co-authored-by: Tyler Hutcherson <tyler.hutcherson@redis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants