Vector search is becoming an important part of applications that use semantic search, recommendation systems, chatbots, and Retrieval-Augmented Generation (RAG). Instead of searching only for matching words, these applications compare numerical representations of data called embeddings.
For example, a document search application may convert every document into a vector and store it in Redis. When a user asks a question, the application converts that question into another vector and searches for documents with similar vectors.
This approach works well, but it introduces a memory challenge. Embeddings can contain hundreds or thousands of dimensions, and a large application may need to store millions of them. Redis must also maintain an index that helps find similar vectors quickly.
As the number of vectors increases, memory usage can become a major concern. Simply adding more memory is not always the best solution, especially when the application needs to handle a growing collection of documents or product records.
Vector compression provides another option. It reduces the memory required to represent vectors and can improve search efficiency. However, compression also changes how accurately the original vector values are represented. If the compression level is too aggressive, the search may return different results from those users actually need.
Redis provides several vector indexing and compression options to help developers manage this trade-off. The important part is choosing the right method and measuring its effect on actual search results.
Why Redis Vector Indexes Need Compression
A vector is an array of numerical values generated by an embedding model. Each value represents part of the information captured by the model.
For example, a small vector might look like this:
[0.21, -0.45, 0.83, 0.17, -0.62]
Real application embeddings are usually much larger. A vector may contain 384, 768, 1536, or even more dimensions, depending on the embedding model.
Consider an application storing one million vectors, each containing 1536 floating-point values. If every value uses 32-bit floating-point storage, the raw vector data alone requires approximately 5.72 GiB of memory.
This calculation does not include the additional memory needed for the vector index, document metadata, Redis keys, and other application data.
The actual memory requirement can therefore be considerably higher.
Compression reduces the amount of information required to represent each vector. Instead of storing every dimension using its original precision, Redis can use fewer bits to represent the values.
This saves memory, but it introduces a trade-off. A compressed vector is an approximation of the original vector. As a result, the distance calculated between two compressed vectors may differ from the distance calculated using their original values.
That difference can affect which documents appear at the top of a search result.
The goal is not to make every compressed vector identical to its original representation. The goal is to reduce memory while keeping the search results useful for the application's requirements.
Understanding Quantization
Quantization is one of the main techniques used to compress vector data.
A simple way to understand it is to imagine storing a measurement that originally uses many decimal places.
For example:
Original value: 0.738491
Compressed value: 0.74
The compressed value uses less precision, but it is close to the original value.
Vector quantization applies a similar idea to the dimensions of an embedding. It represents numerical values using a smaller number of bits.
A 32-bit floating-point value uses four bytes. An 8-bit representation uses one byte. Therefore, storing vector dimensions with 8-bit values can significantly reduce the memory needed for the vector data itself.
However, the actual memory savings for a complete index depend on additional structures, such as graph connections and metadata.
Quantization can also affect different dimensions differently. A good compression method should represent the important structure of the vector data rather than simply reducing every value without considering the data distribution.
This is why Redis provides different compression methods and indexing options.
Using HNSW Compression With SQ8
Redis supports HNSW vector indexes for approximate nearest-neighbor search. HNSW builds a graph that helps the search process find nearby vectors without comparing the query against every vector in the collection.
Redis 8.12 adds SQ8 compression support for HNSW vector fields.
SQ8 is an 8-bit scalar quantization method. It reduces the precision used to represent vector dimensions, which lowers the memory required for vector storage.
Consider a document search application where every document has a 1536-dimensional embedding.
A Redis Search index can be created using the following command:
FT.CREATE documents
ON HASH
PREFIX 1 docs:
SCHEMA
doc_embedding VECTOR HNSW 8
TYPE FLOAT32
DIM 1536
DISTANCE_METRIC COSINE
COMPRESSION SQ8
This command creates an index named documents over Redis hashes with the docs: prefix.
The doc_embedding field contains the vector data. The index uses HNSW for approximate nearest-neighbor search, FLOAT32 for the input vector type, 1536 dimensions, and cosine distance for comparing vectors.
The COMPRESSION SQ8 setting enables 8-bit scalar quantization for the indexed vectors.
There are a few important restrictions to understand:
- HNSW compression supports FLOAT32 and FLOAT16 vector fields.
- It supports the available distance metrics for the HNSW vector field.
- The compression option applies to in-memory vector indexes.
- Disk-based vector indexes ignore the COMPRESSION setting.
These details matter when selecting an index for a production environment. Do not assume that adding COMPRESSION SQ8 to every vector index will enable compression.
Why Training Threshold Matters
Compression needs to understand the values it is going to represent.
Redis uses a training process for compressed HNSW fields. When SQ8 is enabled, Redis initially stores vectors at full precision until the field reaches the configured TRAINING_THRESHOLD.
Once enough vectors have been collected, Redis learns the quantization parameters from those vectors and moves them into compressed storage.
For example:
FT.CREATE documents
ON HASH
PREFIX 1 docs:
SCHEMA
doc_embedding VECTOR HNSW 8
TYPE FLOAT32
DIM 1536
DISTANCE_METRIC COSINE
COMPRESSION SQ8
TRAINING_THRESHOLD 10000
In this example, Redis uses 10,000 vectors as the training threshold.
The exact threshold should depend on the size and characteristics of the dataset. A very small sample may not represent the range of values found in the complete collection. A larger sample may provide better training information, but it also means more vectors remain at full precision during the initial collection period.
One important detail is that vectors remain searchable while Redis is collecting training data and after the compression migration takes place.
You can also set the training threshold to zero:
TRAINING_THRESHOLD 0
This skips the training period and causes vectors to be quantized immediately without learning parameters from a sample.
That may be useful in some situations, but it can reduce search accuracy. For an application where search quality matters, it is better to evaluate a representative training sample before choosing this setting.
Using SVS-VAMANA for Compressed Vector Search
HNSW is not the only option available in Redis.
Redis introduced SVS-VAMANA indexing in Redis 8.2. It uses a graph-based search approach designed to work with vector compression.
SVS-VAMANA is useful when an application needs to reduce memory usage while maintaining good approximate search performance.
Consider the following index definition:
FT.CREATE documents
ON HASH
PREFIX 1 docs:
SCHEMA
doc_embedding VECTOR SVS-VAMANA 12
TYPE FLOAT32
DIM 1536
DISTANCE_METRIC COSINE
GRAPH_MAX_DEGREE 40
CONSTRUCTION_WINDOW_SIZE 250
COMPRESSION LVQ8
This example creates an SVS-VAMANA index with LVQ8 compression.
The configuration includes several important settings.
GRAPH_MAX_DEGREE controls the maximum number of connections maintained for graph nodes. Increasing it can improve the quality of the search graph, but it also increases graph memory usage.
CONSTRUCTION_WINDOW_SIZE controls how many candidates are considered during graph construction. A larger value can produce a better-quality graph, but index construction takes more time.
COMPRESSION LVQ8 selects an 8-bit locally adaptive vector quantization method.
The best values depend on the dataset and search requirements. Avoid increasing every graph parameter at the same time because it becomes difficult to understand which change actually improves the results.
Choosing Between LVQ and LeanVec Compression
SVS-VAMANA supports several compression methods, including LVQ and LeanVec variants.
These methods provide different trade-offs between memory usage, search speed, and recall.
LVQ compression
Locally-adaptive Vector Quantization uses information from individual vectors to improve how their values are represented.
Instead of applying the same representation strategy without considering the structure of each vector, LVQ uses per-vector normalization and quantization.
Redis supports several LVQ configurations:
Compression | General purpose |
|---|
LVQ8 | Single-level 8-bit compression |
LVQ4 | Higher compression with fewer bits |
LVQ4x4 | Two-level compression |
LVQ4x8 | Two-level compression with additional precision for refinement |
Two-level compression is useful because the first representation can help identify likely search candidates, while additional information can help improve their ranking.
For example, LVQ4x8 uses a first level with four bits per dimension and a second level with eight bits for residual information.
The first level supports efficient candidate retrieval. The second level provides additional information that can improve ranking accuracy.
LeanVec compression
LeanVec combines dimensionality reduction with vector quantization.
This is particularly useful when embeddings have many dimensions and the application needs to reduce the amount of information processed during search.
Redis supports LeanVec4x8 and LeanVec8x8.
The REDUCE parameter controls the reduced dimension used by LeanVec.
For example:
FT.CREATE documents
ON HASH
PREFIX 1 docs:
SCHEMA
doc_embedding VECTOR SVS-VAMANA 12
TYPE FLOAT32
DIM 1536
DISTANCE_METRIC COSINE
COMPRESSION LeanVec4x8
REDUCE 768
The original vectors have 1536 dimensions, while the REDUCE setting specifies 768 dimensions for the reduced representation.
Reducing dimensions can improve memory usage and search speed, but aggressive reduction may remove information that is important for distinguishing similar documents.
For this reason, test different REDUCE values against your actual search data rather than choosing the smallest possible value.
There is also an important deployment consideration. Some advanced LVQ and LeanVec optimizations depend on Intel-specific software and hardware support. On Redis Open Source and non-Intel platforms, SVS-VAMANA compression may fall back to basic 8-bit scalar quantization instead of using those advanced optimizations.
Do not assume that selecting LVQ or LeanVec automatically means the same compression implementation will run on every platform.
Compare Search Accuracy Before and After Compression
Reducing memory is useful only when the resulting search quality is acceptable.
A compressed index may return results that are slightly different from an uncompressed index. The difference can be small for one dataset and much larger for another.
The right way to evaluate compression is to compare its search results against a reference search using the original vectors.
One useful measurement is Recall@K.
Recall@K measures how many of the expected top K results are present in the results returned by the approximate search.
For example, suppose an exact search returns these five documents:
doc-101
doc-205
doc-310
doc-415
doc-520
A compressed index returns:
doc-101
doc-205
doc-310
doc-600
doc-520
Four of the five expected results are present.
The Recall@5 value is:
Recall@5 = 4 / 5 = 0.80
This means the approximate search recovered 80% of the reference top-five results.
For a production application, this measurement should be calculated across many representative queries, not just one example.
You should also compare the ranking of results. Two indexes may return the same documents but place them in different positions. That difference can matter when users usually inspect only the first few results.
Redis vector search documentation also provides ways to compare approximate search results with more accurate reference results. For vector sets, the VSIM TRUTH option can be used to compare approximate results with a linear scan. For Redis Search indexes, create a suitable reference evaluation using the original vectors and compare the resulting top-K documents.
Tune Search Parameters Along With Compression
Compression is only one part of vector search performance.
An index can use a good compression method and still return poor results because its graph construction or search parameters are not suitable for the dataset.
For SVS-VAMANA, SEARCH_WINDOW_SIZE controls the number of candidates considered during search.
Increasing the search window generally improves recall because Redis can examine more candidates. However, it also increases the amount of work required for each query.
For example:
FT.CREATE documents
ON HASH
PREFIX 1 docs:
SCHEMA
doc_embedding VECTOR SVS-VAMANA 12
TYPE FLOAT32
DIM 1536
DISTANCE_METRIC COSINE
GRAPH_MAX_DEGREE 40
CONSTRUCTION_WINDOW_SIZE 250
SEARCH_WINDOW_SIZE 100
COMPRESSION LVQ8
The SEARCH_WINDOW_SIZE value is set to 100 in this example.
You can compare the results with a larger value to see whether additional candidates improve the quality of the returned documents.
Do not change compression, graph construction, and search parameters together during testing. Change one group of settings at a time so you can understand its effect.
For HNSW indexes, search-time parameters such as EF_RUNTIME also affect the number of candidates considered and the resulting recall. The correct setting depends on the application's latency requirements and the quality of results it needs.
Build a Practical Compression Testing Process
Before changing a production index, create a representative test dataset.
The dataset should contain the same type of embeddings that the application will use. If the application searches product descriptions, test with product description embeddings. If it searches technical documents, use representative technical documents.
A useful testing process looks like this:
First, build a reference index using full-precision vectors. Run a collection of representative queries and save the top results.
Next, build a compressed index using the same vectors. Start with a less aggressive compression method and a reasonable training threshold.
Run the same queries against the compressed index. Compare Recall@K, result ranking, query latency, index memory, and index construction time.
Then test alternative compression settings. For example, compare SQ8 with an SVS-VAMANA configuration or compare different LVQ and LeanVec variants where the platform supports them.
The results should be recorded in a table:
Measurement | Full precision | Compressed index |
|---|
Index memory | Record measured value | Record measured value |
Recall@10 | Reference value | Measured value |
Average query latency | Measured value | Measured value |
High-percentile latency | Measured value | Measured value |
Index construction time | Measured value | Measured value |
Do not use assumed performance improvements in place of measurements. Memory savings and recall depend on the embedding model, dataset distribution, dimensions, index parameters, and Redis deployment.
Once the results meet the application's requirements, test the compressed index under realistic load before using it in production.
Important Considerations When Reloading Compressed Indexes
Compression behavior during index reloads deserves special attention.
Redis rebuilds and retrains compressed HNSW fields from the original source vectors when an index is reloaded, such as from an RDB file or during replication.
Because the training process can produce different quantization parameters, approximate distances and rankings after reload are not guaranteed to match the results produced before reload.
This does not mean the index becomes incorrect. It means approximate search results can change slightly because the compressed representation may be different.
Applications that depend on stable search rankings should include reload and recovery scenarios in their testing process.
There is another detail to consider with the training threshold. If deletions reduce the number of vectors below the configured threshold, a reload can return the field to the full-precision accumulation state until enough vectors are added again.
This behavior should be considered when planning large-scale data deletion, index rebuilding, and replication.
Common Mistakes to Avoid
Choosing the strongest compression without measuring recall
The highest compression level is not automatically the best option.
A smaller index may return less useful results. Test the compression method against the actual queries your application receives.
Ignoring the training dataset
Compression methods that learn parameters from the vector data need a representative sample.
If the training vectors do not reflect the complete dataset, the compressed representation may not work as expected.
Changing several parameters together
Changing compression, graph degree, construction settings, and search window size in one experiment makes the results difficult to understand.
Adjust parameters in controlled steps and record each result.
Assuming every compression method is available everywhere
Some SVS-VAMANA compression optimizations depend on Intel-specific support and licensing conditions.
Check the actual Redis build and deployment platform before selecting an advanced compression option.
Ignoring recovery and reload behavior
An index that performs well immediately after creation should also be tested after restart, restore, and replication.
Compression training and approximate rankings may change during index reconstruction.
Conclusion
Vector compression helps Redis applications manage large embedding collections without requiring every vector dimension to remain in its original representation.
Redis provides several approaches, including SQ8 compression for HNSW indexes and LVQ and LeanVec options for SVS-VAMANA indexes. These methods offer different balances between memory usage, search speed, and result quality.
The important decision is not simply choosing the smallest representation. It is finding a compression method that keeps search results useful for the application's requirements.
Start with a full-precision reference, test compressed indexes using representative queries, measure Recall@K, and compare memory and latency under realistic conditions. Also test index reloads and the actual hardware and Redis build used in production.
A smaller vector index is valuable, but only when it continues to return the information users expect.
Join the conversation! Your thoughts help the community grow.