Valkey: 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 Valkey.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Valkey cloud solution that delivers numerous advantages, including:
Valkey Adminweb UI included.- Unlimited message size and transfers.
- One-click updates for easy maintenance.
- 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 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, allowing for 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 generally the best distance metric for text embeddings. L2 and IP metrics are also supported.