Redis®*: Querying

This documentation is part of the Vector search and RAG guide. View the full guide here: Semantic search, recommendations, and retrieval-augmented generation with Redis.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Redis cloud solution that provides a host of benefits, including:

  • Redis Commander web UI included.
  • Unlimited message size and transfers.
  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private, dedicated infrastructure.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Redis cloud hosting solution!

A K nearest neighbors (KNN) query looks like this. The vector is supplied as raw little-endian float32 bytes:

FT.SEARCH chunksIndex "*=>[KNN 5 @embedding $queryVector AS score]"
  PARAMS 2 queryVector "<rawBytes>"
  SORTBY score
  RETURN 2 content score
  DIALECT 2

To combine similarity search with filters, simply replace * with a filter expression:

FT.SEARCH chunksIndex "(@documentId:{doc42} @publishedAt:[1735689600 +inf])=>[KNN 5 @embedding $queryVector AS score]"
  PARAMS 2 queryVector "<rawBytes>"
  SORTBY score
  DIALECT 2

Vector queries require DIALECT 2. If you omit this, the query uses the older syntax and returns an error.