Package com.redis.vl.query
Class VectorQuery.Builder
java.lang.Object
com.redis.vl.query.VectorQuery.Builder
- Enclosing class:
VectorQuery
Builder for VectorQuery
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the VectorQuerydistanceMetric(VectorField.DistanceMetric distanceMetric) Set the distance metricSet the EF runtime parameter for HNSWSet the vector field namehybridField(String hybridField) Set the hybrid search fieldhybridQuery(String hybridQuery) Set the hybrid search queryinOrder(boolean inOrder) Set whether terms must be in orderk(int k) Deprecated.Use numResults() insteadnormalizeVectorDistance(boolean normalize) Set whether to normalize vector distancenumResults(int numResults) Set the number of results to returnSet the pre-filter expressionreturnDistance(boolean returnDistance) Set whether to return distance valuesreturnFields(String... fields) Set the fields to return in resultsreturnFields(List<String> fields) Set the fields to return in resultsreturnScore(boolean returnScore) Set whether to return similarity scoressearchBufferCapacity(Integer searchBufferCapacity) Set the search buffer capacity parameter for SVS-VAMANA algorithm.searchWindowSize(Integer searchWindowSize) Set the search window size parameter for SVS-VAMANA algorithm.skipDecodeFields(String... fields) Set fields that should not be decoded from binary format (varargs).skipDecodeFields(List<String> skipDecodeFields) Set fields that should not be decoded from binary format.Set the sort field using SortField.Set the sort field (defaults to ascending).Set the sort field with explicit direction.Set the sort fields (supports multiple fields, but only first is used).sortDescending(boolean descending) Set whether to sort in descending orderuseSearchHistory(String useSearchHistory) Set the use search history parameter for SVS-VAMANA algorithm.vector(double[] vector) Set the query vectorvector(float[] vector) Set the query vectorSet the distance metric (alternative method)withEfRuntime(int efRuntime) Set the EF runtime parameter for HNSW (alternative method)withHybridSearch(String field, String query) Set hybrid search parameterswithK(int k) Deprecated.Use numResults() insteadwithPreFilter(String filter) Set the pre-filter expression (alternative method)withReturnDistance(boolean returnDistance) Set whether to return distance values (alternative method)withReturnScore(boolean returnScore) Set whether to return similarity scores (alternative method)
-
Constructor Details
-
Builder
public Builder()Create a new Builder instance
-
-
Method Details
-
field
Set the vector field name- Parameters:
field- Field name- Returns:
- This builder
-
vector
Set the query vector- Parameters:
vector- Query vector as float array- Returns:
- This builder
-
vector
Set the query vector- Parameters:
vector- Query vector as double array- Returns:
- This builder
-
numResults
Set the number of results to return- Parameters:
numResults- Number of results- Returns:
- This builder
-
k
Deprecated.Use numResults() insteadSet the K value (number of results)- Parameters:
k- Number of results- Returns:
- This builder
-
withK
Deprecated.Use numResults() insteadSet the K value (number of results)- Parameters:
k- Number of results- Returns:
- This builder
-
distanceMetric
Set the distance metric- Parameters:
distanceMetric- Distance metric- Returns:
- This builder
-
withDistanceMetric
Set the distance metric (alternative method)- Parameters:
metric- Distance metric- Returns:
- This builder
-
returnDistance
Set whether to return distance values- Parameters:
returnDistance- True to return distances- Returns:
- This builder
-
withReturnDistance
Set whether to return distance values (alternative method)- Parameters:
returnDistance- True to return distances- Returns:
- This builder
-
returnScore
Set whether to return similarity scores- Parameters:
returnScore- True to return scores- Returns:
- This builder
-
withReturnScore
Set whether to return similarity scores (alternative method)- Parameters:
returnScore- True to return scores- Returns:
- This builder
-
preFilter
Set the pre-filter expression- Parameters:
preFilter- Pre-filter expression- Returns:
- This builder
-
withPreFilter
Set the pre-filter expression (alternative method)- Parameters:
filter- Pre-filter expression- Returns:
- This builder
-
hybridField
Set the hybrid search field- Parameters:
hybridField- Hybrid field name- Returns:
- This builder
-
hybridQuery
Set the hybrid search query- Parameters:
hybridQuery- Hybrid query string- Returns:
- This builder
-
withHybridSearch
Set hybrid search parameters- Parameters:
field- Hybrid field namequery- Hybrid query string- Returns:
- This builder
-
efRuntime
Set the EF runtime parameter for HNSW- Parameters:
efRuntime- EF runtime value- Returns:
- This builder
- Throws:
IllegalArgumentException- if efRuntime is not positive
-
withEfRuntime
Set the EF runtime parameter for HNSW (alternative method)- Parameters:
efRuntime- EF runtime value- Returns:
- This builder
- Throws:
IllegalArgumentException- if efRuntime is not positive
-
searchWindowSize
Set the search window size parameter for SVS-VAMANA algorithm.Controls the KNN search window size. Must be positive.
Python PR #439: SVS-VAMANA runtime parameter support
- Parameters:
searchWindowSize- Search window size (must be positive)- Returns:
- This builder
- Throws:
IllegalArgumentException- if searchWindowSize is not positive
-
useSearchHistory
Set the use search history parameter for SVS-VAMANA algorithm.Controls search buffer usage. Valid values: "OFF", "ON", "AUTO"
Python PR #439: SVS-VAMANA runtime parameter support
- Parameters:
useSearchHistory- Search history mode (OFF, ON, or AUTO)- Returns:
- This builder
- Throws:
IllegalArgumentException- if useSearchHistory is not one of: OFF, ON, AUTO
-
searchBufferCapacity
Set the search buffer capacity parameter for SVS-VAMANA algorithm.Controls compression tuning. Must be positive.
Python PR #439: SVS-VAMANA runtime parameter support
- Parameters:
searchBufferCapacity- Search buffer capacity (must be positive)- Returns:
- This builder
- Throws:
IllegalArgumentException- if searchBufferCapacity is not positive
-
returnFields
Set the fields to return in results- Parameters:
fields- Field names- Returns:
- This builder
-
returnFields
Set the fields to return in results- Parameters:
fields- List of field names- Returns:
- This builder
-
normalizeVectorDistance
Set whether to normalize vector distance- Parameters:
normalize- True to normalize- Returns:
- This builder
-
sortBy
Set the sort field (defaults to ascending).Python equivalent: sort_by="price"
- Parameters:
sortBy- Sort field name- Returns:
- This builder
-
sortBy
Set the sort field with explicit direction.Python equivalent: sort_by=("price", "DESC")
- Parameters:
field- Field name to sort bydirection- Sort direction ("ASC" or "DESC", case-insensitive)- Returns:
- This builder
- Throws:
IllegalArgumentException- if direction is invalid
-
sortBy
Set the sort field using SortField.Python equivalent: sort_by=("rating", "DESC") or using SortField.desc("rating")
- Parameters:
sortField- SortField specifying field and direction- Returns:
- This builder
- Throws:
IllegalArgumentException- if sortField is null
-
sortBy
Set the sort fields (supports multiple fields, but only first is used).Python equivalent: sort_by=[("price", "DESC"), ("rating", "ASC"), "stock"]
Note: Redis Search only supports single-field sorting. When multiple fields are provided, only the first field is used and a warning is logged.
- Parameters:
sortFields- List of SortFields- Returns:
- This builder
-
sortDescending
Set whether to sort in descending order- Parameters:
descending- True for descending- Returns:
- This builder
-
inOrder
Set whether terms must be in order- Parameters:
inOrder- True for in-order matching- Returns:
- This builder
-
skipDecodeFields
Set fields that should not be decoded from binary format.- Parameters:
skipDecodeFields- List of field names- Returns:
- This builder
- Throws:
IllegalArgumentException- if list contains null values
-
skipDecodeFields
Set fields that should not be decoded from binary format (varargs).- Parameters:
fields- Field names- Returns:
- This builder
- Throws:
IllegalArgumentException- if any field is null
-
build
Build the VectorQuery- Returns:
- VectorQuery instance
-