Class VectorQuery

java.lang.Object
com.redis.vl.query.VectorQuery

public class VectorQuery extends Object
Represents a vector similarity search query
  • Method Details

    • builder

      public static VectorQuery.Builder builder()
      Create a builder
      Returns:
      Vector query builder
    • of

      public static VectorQuery.Builder of(String field, float[] vector)
      Create a VectorQuery with fluent API for float array
      Parameters:
      field - Vector field name
      vector - Query vector
      Returns:
      Vector query builder
    • of

      public static VectorQuery.Builder of(String field, double[] vector)
      Create a VectorQuery with fluent API for double array
      Parameters:
      field - Vector field name
      vector - Query vector
      Returns:
      Vector query builder
    • withNumResults

      public VectorQuery withNumResults(int newNumResults)
      Create a copy with modified numResults value
      Parameters:
      newNumResults - New number of results to return
      Returns:
      New VectorQuery instance
    • withK

      @Deprecated public VectorQuery withK(int newK)
      Deprecated.
      Use withNumResults() instead
      Create a copy with modified K value
      Parameters:
      newK - New K value
      Returns:
      New VectorQuery instance
    • withDistanceMetric

      public VectorQuery withDistanceMetric(VectorField.DistanceMetric metric)
      Create a copy with modified distance metric
      Parameters:
      metric - New distance metric
      Returns:
      New VectorQuery instance
    • withPreFilter

      public VectorQuery withPreFilter(String filter)
      Create a copy with modified pre-filter
      Parameters:
      filter - New pre-filter expression
      Returns:
      New VectorQuery instance
    • toQueryString

      public String toQueryString()
      Build the query string for Redis
      Returns:
      Query string
    • toParams

      public Map<String,Object> toParams()
      Convert to parameter map for query execution
      Returns:
      Parameters map
    • getField

      public String getField()
      Get the vector field name
      Returns:
      Field name
    • getVector

      public float[] getVector()
      Get the query vector
      Returns:
      Query vector as float array
    • getNumResults

      public int getNumResults()
      Get the number of results to return
      Returns:
      Number of results
    • getK

      @Deprecated public int getK()
      Deprecated.
      Use getNumResults() instead
      Get the K value (number of results)
      Returns:
      Number of results
    • getDistanceMetric

      public VectorField.DistanceMetric getDistanceMetric()
      Get the distance metric
      Returns:
      Distance metric
    • isReturnDistance

      public boolean isReturnDistance()
      Check if distance values should be returned
      Returns:
      True if distance values should be returned
    • isReturnScore

      public boolean isReturnScore()
      Check if similarity scores should be returned
      Returns:
      True if scores should be returned
    • getPreFilter

      public String getPreFilter()
      Get the pre-filter expression
      Returns:
      Pre-filter expression
    • getHybridField

      public String getHybridField()
      Get the hybrid search field
      Returns:
      Hybrid field name
    • getHybridQuery

      public String getHybridQuery()
      Get the hybrid search query
      Returns:
      Hybrid query string
    • getEfRuntime

      public Integer getEfRuntime()
      Get the EF runtime parameter for HNSW
      Returns:
      EF runtime value
    • setEfRuntime

      public void setEfRuntime(int efRuntime)
      Set the EF runtime parameter for HNSW
      Parameters:
      efRuntime - EF runtime value
    • getReturnFields

      public List<String> getReturnFields()
      Get the fields to return in results
      Returns:
      List of field names
    • getFilter

      public Filter getFilter()
      Get the filter query
      Returns:
      Filter instance
    • setFilter

      public void setFilter(Filter filter)
      Set the filter query
      Parameters:
      filter - Filter instance
    • getHybridPolicy

      public String getHybridPolicy()
      Get the hybrid search policy
      Returns:
      Hybrid policy
    • setHybridPolicy

      public void setHybridPolicy(String policy)
      Set the hybrid search policy
      Parameters:
      policy - Hybrid policy
    • getBatchSize

      public Integer getBatchSize()
      Get the batch size
      Returns:
      Batch size
    • setBatchSize

      public void setBatchSize(int batchSize)
      Set the batch size
      Parameters:
      batchSize - Batch size
    • isNormalizeVectorDistance

      public boolean isNormalizeVectorDistance()
      Check if vector distance should be normalized
      Returns:
      True if normalization is enabled
    • getSortBy

      public String getSortBy()
      Get the sort field
      Returns:
      Sort field name
    • isSortDescending

      public boolean isSortDescending()
      Check if sorting is descending
      Returns:
      True if descending
    • isInOrder

      public boolean isInOrder()
      Check if terms must be in order
      Returns:
      True if in-order is required
    • toString

      public String toString()
      Overrides:
      toString in class Object