vd.migration#
Migration utilities for moving data between backends.
Provides functions to migrate collections between different vector database backends while preserving all data, metadata, and embeddings.
Functions
|
Copy a collection with flexible source/target specification. |
|
Migrate all (or selected) collections from one client to another. |
|
Migrate a collection from one backend to another. |
- vd.migration.copy_collection(source, target, *, batch_size=100, preserve_vectors=True)[source]#
Copy a collection with flexible source/target specification.
- Parameters:
source (
tuple[str,str] |Collection) – Either a Collection object or (backend_name, collection_name) tupletarget (
tuple[str,str,dict] |Collection) – Either a Collection object or (backend_name, collection_name, config) tuplebatch_size (
int) – Batch size for copyingpreserve_vectors (
bool) – Whether to preserve vectors
- Returns:
Migration statistics
- Return type:
Examples
>>> import vd >>> # Copy between backends >>> stats = vd.copy_collection( ... source=('memory', 'docs'), ... target=('chroma', 'docs', {'persist_directory': './data'}), ... )
- vd.migration.migrate_client(source_client, target_client, *, collection_names=None, batch_size=100, preserve_vectors=True, progress_callback=None)[source]#
Migrate all (or selected) collections from one client to another.
- Parameters:
source_client (
Client) – Source database clienttarget_client (
Client) – Target database clientcollection_names (
Optional[list[str]]) – Specific collections to migrate. If None, migrates all.batch_size (
int) – Batch size for migrationpreserve_vectors (
bool) – Whether to preserve vectorsprogress_callback (
Optional[Callable[[str,int,int],None]]) – Function called with (collection_name, current, total)
- Returns:
Overall migration statistics
- Return type:
Examples
>>> import vd >>> source = vd.connect('memory') >>> target = vd.connect('chroma', persist_directory='./backup') >>> stats = vd.migrate_client(source, target)
- vd.migration.migrate_collection(source_collection, target_collection, *, batch_size=100, preserve_vectors=True, progress_callback=None, skip_existing=False)[source]#
Migrate a collection from one backend to another.
- Parameters:
source_collection (
Collection) – Source collection to migrate fromtarget_collection (
Collection) – Target collection to migrate tobatch_size (
int) – Number of documents to migrate per batchpreserve_vectors (
bool) – Whether to preserve pre-computed vectorsprogress_callback (
Optional[Callable[[int,int],None]]) – Function called with (current, total) to report progressskip_existing (
bool) – If True, skip documents that already exist in target
- Returns:
Migration statistics with keys:
total: Total documents in source
migrated: Number of documents migrated
skipped: Number of documents skipped
failed: Number of failures
errors: List of error messages
- Return type:
Examples
>>> import vd >>> # Create source and target >>> source_client = vd.connect('memory') >>> target_client = vd.connect('chroma', persist_directory='./data') >>> source = source_client.get_collection('my_docs') >>> target = target_client.create_collection('my_docs') >>> >>> # Migrate >>> stats = vd.migrate_collection(source, target) >>> print(f"Migrated {stats['migrated']} documents")