Query syntax

Vector queries operate by searching a vector database to find vectors that are best matched to your query vector. This page provides details about how this works.

Finding similar vectors

Vector search queries use two strategies:

  • K-Nearest Neighbors (KNN): Finds the k closest vectors to your query vector.

Query syntax breakdown

FT.SEARCH index "(*)=>[KNN num_neighbours @my_vector_hash_key $my_vector_query_param]" PARAMS 2 my_vector_query_param "query_embedding" DIALECT 2
  • index: The name of the index containing your vector field.

  • (*): This is the only supported expression. Filtering is not supported.

  • =>: Separates the filter from the vector search.

  • [KNN num_neighbours @field $vector]: The KNN search expression. Replace num_neighbors with the chosen number of results and @field with your vector field's name.

  • PARAMS 2 my_vector_query_param "query_embedding":

    • The value 2 after PARAMS indicates that two additional arguments must be supplied.
    • my_vector_query_param is the query parameter's vector name, as specified in the KNN search expression.
    • Replace query_embedding with your embedded query vector.
  • DIALECT 2: Specifies that you're using query dialect version 2 or later (required for vector search).