Tutorial: Embedding model migration in Azure AI Search using Python
This sample provides a keyless migration path for vector indexes:
- Baseline pipeline (
python/) for backup, restore, and re-embedding. - Embedding Function (
function/) with Entra-gated document/query routes. - Deployment helpers (
deployment/) to configure keyless hosting and end-to-end setup.
Important
This is a reference sample, not a production-ready drop-in. Validate E2E behavior in a representative test environment that mirrors your tenant auth, network, model deployments, quotas, and index schema before rollout.
Problem this sample solves
When customers need to move from one embedding model/dimension setup to another, a direct in-place change can break query compatibility and make rollback hard. They need a safe way to:
- create a verified baseline copy,
- regenerate vectors with the new model path, and
- publish to a new target index with controlled cutover.
Architecture (what connects to what)
Source Search Index
-> python/migrate.py backup (schema + docs + manifest)
-> python/migrate.py reembed (calls Function /document route)
-> migrated backup artifacts
-> python/migrate.py restore/reembed
-> New Target Search Index (new vectorizer/query route)
Query-time path after migration:
Search vectorizer (customWebApi /query route) -> Function -> embedding model
Example customer migration flow
Example: customer has products-v1 with old vectors and wants fast model vectors.
- Run
migrate.py backupagainstproducts-v1(source frozen). - Run
migrate.py restoreto validate baseline reproducibility on a new test index. - Run
migrate.py reembedwith:--model fast--dimensions <measured fast dimension>- Function auth/resource settings
- Create
products-v2-fastas a new target index. - Validate retrieval quality and operational behavior, then cut traffic to
products-v2-fast.
What happens after migration
- The migrated index is expected to become the active index for reads.
- Ongoing ingestion must produce vectors compatible with the migrated vector field and dimensions.
- Query vectorization must keep using the migrated customWebApi query route and same model family.
- Keep the old index only for rollback window; retire it after acceptance.
Choose your path
| If you need to... | Use |
|---|---|
| Back up, restore, and migrate vectors | python/README.md |
| Run the embedding Function app | function/README.md |
| Configure auth/hosting and optional deployment wiring | deployment/README.md |
| Start from one environment template | sample.env |
How this Python sample works (high level)
- Backup path: reads schema + documents from Search and writes local backup artifacts.
- Restore path: reads local backup artifacts and pushes documents into a new target index.
- Migration path: reads backup artifacts, regenerates vectors through the Function endpoints, writes a new migration artifact, then restores to a new target.
- Pipeline helper: can create an index + datasource + skillset + indexer + query vectorizer aligned to the Function routes.
Folder structure
python/: migration scripts, fixtures, and testsfunction/: Function implementation and auth/runtime helpersdeployment/: PowerShell setup/config scriptssample.env: consolidated non-secret environment template
Quickstart (humans)
- Install Python dependencies:
python -m pip install -r .\embedding-model-migration\python\requirements.txt
python -m pip install -r .\embedding-model-migration\function\requirements.txt
- Validate scripts locally:
python .\embedding-model-migration\python\test_samples.py
- Run backup and restore:
python .\embedding-model-migration\python\migrate.py --search-endpoint "https://<source>.search.windows.net" backup --source "<index>" --backup-dir ".\backup" --source-frozen
python .\embedding-model-migration\python\migrate.py --search-endpoint "https://<target>.search.windows.net" restore --target "<new-target-index>" --backup-dir ".\backup"
- Run migration:
python .\embedding-model-migration\python\migrate.py --search-endpoint "https://<target>.search.windows.net" reembed --target "<new-migrated-index>" --backup-dir ".\backup" --migration-dir ".\migration-output" --text-field "<text-field>" --vector-field "<vector-field>" --model fast --dimensions <D> --function-base "https://<function-app>.azurewebsites.net" --function-auth-resource-id "api://<app-id>"
Quickstart (agents/automation)
Execution contract:
- Stop on first nonzero exit.
- Require
--source-frozenfor backup. - Never reuse backup or migration output directories.
- Never reuse target index names.
- Use Entra bearer tokens only; no API keys or client secrets.
Safety boundaries
- This sample verifies index content and schema compatibility, but does not back up indexers, data sources, aliases, or external model resources.
- Non-retrievable/unstored fields are treated as non-recoverable and fail backup.
- Function query route and dimensions are validated before migration mutations.
- Review and adjust settings, retry policies, naming, and operational controls to your environment and requirements.
- After migration, keep indexing and query vectorization on the same model/dimensions path to avoid drift.