Valkey: Creating a vector index

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

👋 Welcome to the Stackhero documentation!

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

  • Valkey Admin 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 Valkey cloud hosting solution!

Declare a vector field by specifying its dimension and distance metric. The dimension should match your model: for example, 1536 for OpenAI text-embedding-3-small, or 768 for many open source models.

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

HNSW creates a graph index, providing fast approximate searches even as your collection grows large. This is recommended for collections larger than a few thousand vectors. For small collections, you can use FLAT for exact, brute-force search.

COSINE is usually the best distance metric for text embeddings. L2 and IP metrics are also supported.