Skip to content

Commit b60f60f

Browse files
committed
docs: add migration documentation, concept guides, and benchmarks
- docs/concepts/index-migrations.md: migration concepts and architecture - docs/user_guide/how_to_guides/migrate-indexes.md: step-by-step migration guide - docs/api/cli.rst: CLI reference for rvl migrate commands - tests/benchmarks/: migration benchmark scripts and visualization - Updated field-attributes, search-and-indexing, and user guide indexes
1 parent 9a5ae78 commit b60f60f

14 files changed

Lines changed: 5661 additions & 8 deletions

docs/api/cli.rst

Lines changed: 614 additions & 0 deletions
Large diffs are not rendered by default.

docs/concepts/field-attributes.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Key vector attributes:
267267
- `dims`: Vector dimensionality (required)
268268
- `algorithm`: `flat`, `hnsw`, or `svs-vamana`
269269
- `distance_metric`: `COSINE`, `L2`, or `IP`
270-
- `datatype`: `float16`, `float32`, `float64`, or `bfloat16`
270+
- `datatype`: Vector precision (see table below)
271271
- `index_missing`: Allow searching for documents without vectors
272272

273273
```yaml
@@ -281,6 +281,48 @@ Key vector attributes:
281281
index_missing: true # Handle documents without embeddings
282282
```
283283

284+
### Vector Datatypes
285+
286+
The `datatype` attribute controls how vector components are stored. Smaller datatypes reduce memory usage but may affect precision.
287+
288+
| Datatype | Bits | Memory (768 dims) | Use Case |
289+
|----------|------|-------------------|----------|
290+
| `float32` | 32 | 3 KB | Default. Best precision for most applications. |
291+
| `float16` | 16 | 1.5 KB | Good balance of memory and precision. Recommended for large-scale deployments. |
292+
| `bfloat16` | 16 | 1.5 KB | Better dynamic range than float16. Useful when embeddings have large value ranges. |
293+
| `float64` | 64 | 6 KB | Maximum precision. Rarely needed. |
294+
| `int8` | 8 | 768 B | Integer quantization. Significant memory savings with some precision loss. |
295+
| `uint8` | 8 | 768 B | Unsigned integer quantization. For embeddings with non-negative values. |
296+
297+
**Algorithm Compatibility:**
298+
299+
| Datatype | FLAT | HNSW | SVS-VAMANA |
300+
|----------|------|------|------------|
301+
| `float32` | Yes | Yes | Yes |
302+
| `float16` | Yes | Yes | Yes |
303+
| `bfloat16` | Yes | Yes | No |
304+
| `float64` | Yes | Yes | No |
305+
| `int8` | Yes | Yes | No |
306+
| `uint8` | Yes | Yes | No |
307+
308+
**Choosing a Datatype:**
309+
310+
- **Start with `float32`** unless you have memory constraints
311+
- **Use `float16`** for production systems with millions of vectors (50% memory savings, minimal precision loss)
312+
- **Use `int8`/`uint8`** only after benchmarking recall on your specific dataset
313+
- **SVS-VAMANA users**: Must use `float16` or `float32`
314+
315+
**Quantization with the Migrator:**
316+
317+
You can change vector datatypes on existing indexes using the migration wizard:
318+
319+
```bash
320+
rvl migrate wizard --index my_index --url redis://localhost:6379
321+
# Select "Update field" > choose vector field > change datatype
322+
```
323+
324+
The migrator automatically re-encodes stored vectors to the new precision. See {doc}`/user_guide/how_to_guides/migrate-indexes` for details.
325+
284326
## Redis-Specific Subtleties
285327

286328
### Modifier Ordering
@@ -304,6 +346,53 @@ Not all attributes work with all field types:
304346
| `unf` | ✓ | ✗ | ✓ | ✗ | ✗ |
305347
| `withsuffixtrie` | ✓ | ✓ | ✗ | ✗ | ✗ |
306348

349+
### Migration Support
350+
351+
The migration wizard (`rvl migrate wizard`) supports updating field attributes on existing indexes. The table below shows which attributes can be updated via the wizard vs requiring manual schema patch editing.
352+
353+
**Wizard Prompts:**
354+
355+
| Attribute | Text | Tag | Numeric | Geo | Vector |
356+
|-----------|------|-----|---------|-----|--------|
357+
| `sortable` | Wizard | Wizard | Wizard | Wizard | N/A |
358+
| `index_missing` | Wizard | Wizard | Wizard | Wizard | N/A |
359+
| `index_empty` | Wizard | Wizard | N/A | N/A | N/A |
360+
| `no_index` | Wizard | Wizard | Wizard | Wizard | N/A |
361+
| `unf` | Wizard* | N/A | Wizard* | N/A | N/A |
362+
| `separator` | N/A | Wizard | N/A | N/A | N/A |
363+
| `case_sensitive` | N/A | Wizard | N/A | N/A | N/A |
364+
| `no_stem` | Wizard | N/A | N/A | N/A | N/A |
365+
| `weight` | Wizard | N/A | N/A | N/A | N/A |
366+
| `algorithm` | N/A | N/A | N/A | N/A | Wizard |
367+
| `datatype` | N/A | N/A | N/A | N/A | Wizard |
368+
| `distance_metric` | N/A | N/A | N/A | N/A | Wizard |
369+
| `m`, `ef_construction` | N/A | N/A | N/A | N/A | Wizard |
370+
371+
*\* `unf` is only prompted when `sortable` is enabled.*
372+
373+
**Manual Schema Patch Required:**
374+
375+
| Attribute | Notes |
376+
|-----------|-------|
377+
| `phonetic_matcher` | Enable phonetic search |
378+
| `withsuffixtrie` | Suffix/contains search optimization |
379+
380+
**Example manual patch** for adding `index_missing` to a field:
381+
382+
```yaml
383+
# schema_patch.yaml
384+
version: 1
385+
changes:
386+
update_fields:
387+
- name: category
388+
attrs:
389+
index_missing: true
390+
```
391+
392+
```bash
393+
rvl migrate plan --index my_index --schema-patch schema_patch.yaml
394+
```
395+
307396
### JSON Path for Nested Fields
308397

309398
When using JSON storage, use the `path` attribute to index nested fields:

docs/concepts/index-migrations.md

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
---
2+
myst:
3+
html_meta:
4+
"description lang=en": |
5+
Learn how RedisVL index migrations work and which schema changes are supported.
6+
---
7+
8+
# Index Migrations
9+
10+
Redis Search indexes are immutable. To change an index schema, you must drop the existing index and create a new one. RedisVL provides a migration workflow that automates this process while preserving your data.
11+
12+
This page explains how migrations work and which changes are supported. For step by step instructions, see the [migration guide](../user_guide/how_to_guides/migrate-indexes.md).
13+
14+
## Supported and blocked changes
15+
16+
The migrator classifies schema changes into two categories:
17+
18+
| Change | Status |
19+
|--------|--------|
20+
| Add or remove a field | Supported |
21+
| Rename a field | Supported |
22+
| Change field options (sortable, separator) | Supported |
23+
| Change key prefix | Supported |
24+
| Rename the index | Supported |
25+
| Change vector algorithm (FLAT, HNSW, SVS-VAMANA) | Supported |
26+
| Change distance metric (COSINE, L2, IP) | Supported |
27+
| Tune algorithm parameters (M, EF_CONSTRUCTION) | Supported |
28+
| Quantize vectors (float32 to float16/bfloat16/int8/uint8) | Supported |
29+
| Change vector dimensions | Blocked |
30+
| Change storage type (hash to JSON) | Blocked |
31+
| Add a new vector field | Blocked |
32+
33+
**Note:** INT8 and UINT8 vector datatypes require Redis 8.0+. SVS-VAMANA algorithm requires Redis 8.2+ and Intel AVX-512 hardware.
34+
35+
**Supported** changes can be applied automatically using `rvl migrate`. The migrator handles the index rebuild and any necessary data transformations.
36+
37+
**Blocked** changes require manual intervention because they involve incompatible data formats or missing data. The migrator will reject these changes and explain why.
38+
39+
## How the migrator works
40+
41+
The migrator uses a plan first workflow:
42+
43+
1. **Plan**: Capture the current schema, classify your changes, and generate a migration plan
44+
2. **Review**: Inspect the plan before making any changes
45+
3. **Apply**: Drop the index, transform data if needed, and recreate with the new schema
46+
4. **Validate**: Verify the result matches expectations
47+
48+
This separation ensures you always know what will happen before any changes are made.
49+
50+
## Migration mode: drop_recreate
51+
52+
The `drop_recreate` mode rebuilds the index in place while preserving your documents.
53+
54+
The process:
55+
56+
1. Drop only the index structure (documents remain in Redis)
57+
2. For datatype changes, re-encode vectors to the target precision
58+
3. Recreate the index with the new schema
59+
4. Wait for Redis to re-index the existing documents
60+
5. Validate the result
61+
62+
**Tradeoff**: The index is unavailable during the rebuild. Review the migration plan carefully before applying.
63+
64+
## Index only vs document dependent changes
65+
66+
Schema changes fall into two categories based on whether they require modifying stored data.
67+
68+
**Index only changes** affect how Redis Search indexes data, not the data itself:
69+
70+
- Algorithm changes: The stored vector bytes are identical. Only the index structure differs.
71+
- Distance metric changes: Same vectors, different similarity calculation.
72+
- Adding or removing fields: The documents already contain the data. The index just starts or stops indexing it.
73+
74+
These changes complete quickly because they only require rebuilding the index.
75+
76+
**Document dependent changes** require modifying the stored data:
77+
78+
- Datatype changes (float32 to float16): Stored vector bytes must be re-encoded.
79+
- Field renames: Stored field names must be updated in every document.
80+
- Dimension changes: Vectors must be re-embedded with a different model.
81+
82+
The migrator handles datatype changes automatically. Other document dependent changes are blocked because they require application level logic or external services.
83+
84+
## Vector quantization
85+
86+
Changing vector precision from float32 to float16 reduces memory usage at the cost of slight precision loss. The migrator handles this automatically by:
87+
88+
1. Reading all vectors from Redis
89+
2. Converting to the target precision
90+
3. Writing updated vectors back
91+
4. Recreating the index with the new schema
92+
93+
Typical reductions:
94+
95+
| Metric | Value |
96+
|--------|-------|
97+
| Index size reduction | ~50% |
98+
| Memory reduction | ~35% |
99+
100+
Quantization time is proportional to document count. Plan for downtime accordingly.
101+
102+
## Why some changes are blocked
103+
104+
### Vector dimension changes
105+
106+
Vector dimensions are determined by your embedding model. A 384 dimensional vector from one model is mathematically incompatible with a 768 dimensional index expecting vectors from a different model. There is no way to resize an embedding.
107+
108+
**Resolution**: Re-embed your documents using the new model and load them into a new index.
109+
110+
### Storage type changes
111+
112+
Hash and JSON have different data layouts. Hash stores flat key value pairs. JSON stores nested structures. Converting between them requires understanding your schema and restructuring each document.
113+
114+
**Resolution**: Export your data, transform it to the new format, and reload into a new index.
115+
116+
### Adding a vector field
117+
118+
Adding a vector field means all existing documents need vectors for that field. The migrator cannot generate these vectors because it does not know which embedding model to use or what content to embed.
119+
120+
**Resolution**: Add vectors to your documents using your application, then run the migration.
121+
122+
## Downtime considerations
123+
124+
With `drop_recreate`, your index is unavailable between the drop and when re-indexing completes.
125+
126+
**CRITICAL**: Downtime requires both reads AND writes to be paused:
127+
128+
| Requirement | Reason |
129+
|-------------|--------|
130+
| **Pause reads** | Index is unavailable during migration |
131+
| **Pause writes** | Redis updates indexes synchronously. Writes during migration may conflict with vector re-encoding or be missed |
132+
133+
Plan for:
134+
135+
- Search unavailability during the migration window
136+
- Partial results while indexing is in progress
137+
- Resource usage from the re-indexing process
138+
- Quantization time if changing vector datatypes
139+
140+
The duration depends on document count, field count, and vector dimensions. For large indexes, consider running migrations during low traffic periods.
141+
142+
## Sync vs async execution
143+
144+
The migrator provides both synchronous and asynchronous execution modes.
145+
146+
### What becomes async and what stays sync
147+
148+
The migration workflow has distinct phases. Here is what each mode affects:
149+
150+
| Phase | Sync mode | Async mode | Notes |
151+
|-------|-----------|------------|-------|
152+
| **Plan generation** | `MigrationPlanner.create_plan()` | `AsyncMigrationPlanner.create_plan()` | Reads index metadata from Redis |
153+
| **Schema snapshot** | Sync Redis calls | Async Redis calls | Single `FT.INFO` command |
154+
| **Enumeration** | FT.AGGREGATE (or SCAN fallback) | FT.AGGREGATE (or SCAN fallback) | Before drop, only if quantization needed |
155+
| **Drop index** | `index.delete()` | `await index.delete()` | Single `FT.DROPINDEX` command |
156+
| **Quantization** | Sequential HGET + HSET | Sequential HGET + batched HSET | Uses pre-enumerated keys |
157+
| **Create index** | `index.create()` | `await index.create()` | Single `FT.CREATE` command |
158+
| **Readiness polling** | `time.sleep()` loop | `asyncio.sleep()` loop | Polls `FT.INFO` until indexed |
159+
| **Validation** | Sync Redis calls | Async Redis calls | Schema and doc count checks |
160+
| **CLI interaction** | Always sync | Always sync | User prompts, file I/O |
161+
| **YAML read/write** | Always sync | Always sync | Local filesystem only |
162+
163+
### When to use sync (default)
164+
165+
Sync execution is simpler and sufficient for most migrations:
166+
167+
- Small to medium indexes (under 100K documents)
168+
- Index-only changes (algorithm, distance metric, field options)
169+
- Interactive CLI usage where blocking is acceptable
170+
171+
For migrations without quantization, the Redis operations are fast single commands. Sync mode adds no meaningful overhead.
172+
173+
### When to use async
174+
175+
Async execution (`--async` flag) provides benefits in specific scenarios:
176+
177+
**Large quantization jobs (1M+ vectors)**
178+
179+
Converting float32 to float16 requires reading every vector, converting it, and writing it back. The async executor:
180+
181+
- Enumerates documents using `FT.AGGREGATE WITHCURSOR` for index-specific enumeration (falls back to `SCAN` only if indexing failures exist)
182+
- Pipelines `HSET` operations in batches (100-1000 operations per pipeline is optimal for Redis)
183+
- Yields to the event loop between batches so other tasks can proceed
184+
185+
**Large keyspaces (40M+ keys)**
186+
187+
When your Redis instance has many keys and the index has indexing failures (requiring SCAN fallback), async mode yields between batches.
188+
189+
**Async application integration**
190+
191+
If your application uses asyncio, you can integrate migration directly:
192+
193+
```python
194+
import asyncio
195+
from redisvl.migration import AsyncMigrationPlanner, AsyncMigrationExecutor
196+
197+
async def migrate():
198+
planner = AsyncMigrationPlanner()
199+
plan = await planner.create_plan("myindex", redis_url="redis://localhost:6379")
200+
201+
executor = AsyncMigrationExecutor()
202+
report = await executor.apply(plan, redis_url="redis://localhost:6379")
203+
204+
asyncio.run(migrate())
205+
```
206+
207+
### Why async helps with quantization
208+
209+
The migrator uses an optimized enumeration strategy:
210+
211+
1. **Index-based enumeration**: Uses `FT.AGGREGATE WITHCURSOR` to enumerate only indexed documents (not the entire keyspace)
212+
2. **Fallback for safety**: If the index has indexing failures (`hash_indexing_failures > 0`), falls back to `SCAN` to ensure completeness
213+
3. **Enumerate before drop**: Captures the document list while the index still exists, then drops and quantizes
214+
215+
This optimization provides 10-1000x speedup for sparse indexes (where only a small fraction of prefix-matching keys are indexed).
216+
217+
**Sync quantization:**
218+
```
219+
enumerate keys (FT.AGGREGATE or SCAN) -> store list
220+
for each batch of 500 keys:
221+
for each key:
222+
HGET field (blocks)
223+
convert array
224+
pipeline.HSET(field, new_bytes)
225+
pipeline.execute() (blocks)
226+
```
227+
228+
**Async quantization:**
229+
```
230+
enumerate keys (FT.AGGREGATE or SCAN) -> store list
231+
for each batch of 500 keys:
232+
for each key:
233+
await HGET field (yields)
234+
convert array
235+
pipeline.HSET(field, new_bytes)
236+
await pipeline.execute() (yields)
237+
```
238+
239+
Each `await` is a yield point where other coroutines can run. For millions of vectors, this prevents your application from freezing.
240+
241+
### What async does NOT improve
242+
243+
Async execution does not reduce:
244+
245+
- **Total migration time**: Same work, different scheduling
246+
- **Redis server load**: Same commands execute on the server
247+
- **Downtime window**: Index remains unavailable during rebuild
248+
- **Network round trips**: Same number of Redis calls
249+
250+
The benefit is application responsiveness, not faster migration.
251+
252+
## Learn more
253+
254+
- [Migration guide](../user_guide/how_to_guides/migrate-indexes.md): Step by step instructions
255+
- [Search and indexing](search-and-indexing.md): How Redis Search indexes work

docs/concepts/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ How RedisVL components connect: schemas, indexes, queries, and extensions.
2626
Schemas, fields, documents, storage types, and query patterns.
2727
:::
2828

29+
:::{grid-item-card} 🔄 Index Migrations
30+
:link: index-migrations
31+
:link-type: doc
32+
33+
How RedisVL handles migration planning, rebuilds, and future shadow migration.
34+
:::
35+
2936
:::{grid-item-card} 🏷️ Field Attributes
3037
:link: field-attributes
3138
:link-type: doc
@@ -62,6 +69,7 @@ Pre-built patterns: caching, message history, and semantic routing.
6269
6370
architecture
6471
search-and-indexing
72+
index-migrations
6573
field-attributes
6674
queries
6775
utilities

0 commit comments

Comments
 (0)