FT.SEARCH

FT.SEARCH searches the index with the provided query, and returns the specified values.

For details on query syntax, see Query syntax.

Syntax

FT.SEARCH index query
  [NOCONTENT]
  [TIMEOUT timeout]
  [PARAMS nargs name value [ name value ...]]
  [LIMIT offset num]
  DIALECT 2
  • index (required): This index you want to query.
  • query (required): This is your query. For details on query syntax, see Query syntax.
  • NOCONTENT (optional): This returns just the document IDs, and excludes the content.
  • TIMEOUT (optional): Lets you set a timeout value for the search command.
  • PARAMS (optional): The number of key value pairs times two.
  • [LIMIT offset num] (optional): Lets you choose pagination with an offset and a number count. If you don't use this parameter, the default is LIMIT 0 10, which returns at the most 10 keys.
  • DIALECT 2 (optional): Specifies your the dialect. The only supported dialect is dialect 2.

Command return

  • This command returns an array or an error message. The elements of the returned array represent the best matched results of the query. Each array element has the following:

  • The entry hash key

  • An array of the following:

    • Key value: [$score_as ] score_value
    • Distance value
    • Attribute name
    • Vector value

    If NOCONTENT is used, the array elements consist of just the document IDs.

Example

For this example, assume that you created an HNSW index on the hash field Vec. Suppose you already added some Hash entries which contain the following field names, and would like to find the best matching vector to a given input vector.

Hash field names:

  • Vec - the field value contains the actual vector.
  • some_hash_key - Some associated vector metadata.

To run a search use the FT.SEARCH command:

FT.SEARCH idx "*=>[KNN 3 @vec $BLOB EF_RUNTIME 40 AS score]" PARAMS 2 BLOB
"\x12\xa9\xf5\x6c" DIALECT 2

Return array:

[3, b'key_192', [b'__embedding_score', b'0.061539709568', b'embedding', b'd\xdeA?\xb7\\xbb>!\xb3\xd8>0\x94n?\xbd\xbco=WX\xe4>kN\x9e>\x1aV0>Z\x92*?\rD\x04>', b'some_hash_key', b'some_hash_key_value_192'], b'key_209', [b'__embedding_score', b'0.0803312063217', b'embedding', b's\xe1W?\xa4\x1d\xad>\xb8\x99Q?\xa9u ?6\xc8\xb2>=j5?!\x13\x96>~\x13\xb9=\xebcX?\x92\x86\xb8>', b'some_hash_key', b'some_hash_key_value_209'], b'key_821', [b'__embedding_score', b'0.0615693926811', b'embedding', b')\x1e\x03?\xa6\x10\xe0>^-\xa1\x00\x87>\x18u\xa2=\x06\xa2;>,\xeb=?\x0e%\xa4>', b'some_hash_key', b'some_hash_key_value_821']]