-
Notifications
You must be signed in to change notification settings - Fork 66
Expose max_distance as an optional setting in multi vector queries #478
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
Changes from all commits
b731542
45898df
6d239f9
3624f42
618c31d
f5b47a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| import warnings | ||||||
| from typing import Any, Dict, List, Optional, Set, Union | ||||||
|
|
||||||
| from pydantic import BaseModel, field_validator, model_validator | ||||||
| from pydantic import BaseModel, Field, field_validator, model_validator | ||||||
| from redis.commands.search.aggregation import AggregateRequest, Desc | ||||||
| from typing_extensions import Self | ||||||
|
|
||||||
|
|
@@ -18,12 +18,20 @@ | |||||
| class Vector(BaseModel): | ||||||
| """ | ||||||
| Simple object containing the necessary arguments to perform a multi vector query. | ||||||
|
|
||||||
| Args: | ||||||
| vector: The vector values as a list of floats or bytes | ||||||
| field_name: The name of the vector field to search | ||||||
| dtype: The data type of the vector (default: "float32") | ||||||
| weight: The weight for this vector in the combined score (default: 1.0) | ||||||
| max_distance: The maximum distance for vector range search (default: 2.0, range: [0.0, 2.0]) | ||||||
| """ | ||||||
|
|
||||||
| vector: Union[List[float], bytes] | ||||||
| field_name: str | ||||||
| dtype: str = "float32" | ||||||
| weight: float = 1.0 | ||||||
| max_distance: float = Field(default=2.0, ge=0.0, le=2.0) | ||||||
|
|
||||||
justin-cechmanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| @field_validator("dtype") | ||||||
| @classmethod | ||||||
|
|
@@ -36,6 +44,15 @@ def validate_dtype(cls, dtype: str) -> str: | |||||
| ) | ||||||
| return dtype | ||||||
|
|
||||||
| @field_validator("max_distance") | ||||||
| @classmethod | ||||||
| def validate_max_distance(cls, max_distance: float) -> float: | ||||||
| if not isinstance(max_distance, (float, int)): | ||||||
| raise ValueError("max_distance must be a value between 0.0 and 2.0") | ||||||
|
Comment on lines
+50
to
+51
|
||||||
| if not isinstance(max_distance, (float, int)): | |
| raise ValueError("max_distance must be a value between 0.0 and 2.0") |
Copilot
AI
Feb 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate_max_distance currently rejects infinities but will still allow NaN (all comparisons to NaN are false, so it passes through). NaN would produce an invalid VECTOR_RANGE radius in the query string. Consider explicitly rejecting non-finite values (and also disallowing bool, since it’s an int subclass).
justin-cechmanek marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the multi-vector query from OR semantics (|) to AND semantics when combining vector range clauses. That’s a behavior change beyond “expose max_distance” and could be breaking for existing callers. If the AND behavior is intentional, it should be called out in the PR description/release notes (or consider preserving prior behavior via an option).
Uh oh!
There was an error while loading. Please reload this page.