Redis®*: Creating a vector index

This documentation is part of the Vector search and RAG guide. You can view the complete guide here: Semantic search, recommendations, and retrieval-augmented generation with Redis.

👋 Welcome to the Stackhero documentation!

Stackhero provides a ready-to-use Redis cloud solution that delivers numerous advantages, including:

  • Redis Commander web interface included.
  • Unlimited message size and transfers.
  • One-click simplified updates.
  • Optimal performance and enhanced security thanks to a private, dedicated infrastructure.

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

To declare a vector field, specify its dimension and distance metric. The dimension should match your embedding model: for example, 1536 for OpenAI text-embedding-3-small, 768 for many open-source models, and so on.

FT.CREATE chunksIndex
  ON HASH
  PREFIX 1 chunk:
  SCHEMA
    content TEXT
    documentId TAG
    publishedAt NUMERIC
    embedding VECTOR HNSW 6
      TYPE FLOAT32
      DIM 1536
      DISTANCE_METRIC COSINE

HNSW creates a graph index that keeps queries fast even as your collection grows, making it a good choice above a few thousand vectors. For small collections where exact results are a priority, you can use FLAT for brute-force search.

COSINE is the recommended metric for most text embedding models. You can also choose L2 or IP depending on your use case.