|
| 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 |
0 commit comments