Heuristic:AI Northstar Tech Vector io Adaptive Batch Size Reduction
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Vector_Databases, Error_Handling |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Automatically reduce batch size by a factor of 3/4 or 2/3 when API or database errors occur during batch data retrieval or upsertion, retrying until success or a minimum threshold is reached.
Description
When exporting or importing vector data in batches, API rate limits, payload size limits, and transient network errors can cause batch operations to fail. Instead of aborting the entire operation, the code catches the exception, reduces the current batch size by multiplying it by 3/4 (0.75) or 2/3 (~0.67), and retries. This adaptive reduction continues until the batch size drops below a minimum threshold (typically 1/100th of the original), at which point the error is treated as non-recoverable and re-raised. Different vector database backends use slightly different reduction factors and thresholds.
Usage
Use this heuristic when you are batch fetching or upserting vectors and encountering intermittent API errors such as rate limiting, payload-too-large responses, or timeouts. It is applied automatically in the Pinecone export/import, Milvus import, and Qdrant import implementations. The `--batch_size` CLI argument controls the initial batch size; the adaptive logic kicks in automatically on errors.
The Insight (Rule of Thumb)
- Action: On batch operation failure, multiply the current batch size by 3/4 (Pinecone export) or 2/3 (Pinecone import, Milvus import) and retry without advancing the cursor.
- Value: Reduction factor of 0.75 for export fetches, ~0.67 for imports. Minimum threshold is `BATCH_SIZE / 100` (Pinecone import) or `1` (Pinecone export, Milvus import).
- Trade-off: Smaller batches are slower overall but more resilient to rate limits and payload constraints. Each retry wastes the failed request's time but avoids total operation failure.
- Compatibility: Applied in Pinecone export (`fetch_size * 3 // 4`), Pinecone import (`int(2 * current_batch_size / 3)`), Milvus import (`current_batch_size * 2 // 3`), and Qdrant import (parallel batch upsert with retries).
Reasoning
Vector database APIs impose per-request limits on payload size, number of items, and request rate. When batches exceed these limits, the API returns errors (429, 413, timeouts). Rather than failing the entire export/import, reducing the batch size adaptively finds the largest batch size that the API will accept under current conditions. The 3/4 factor (Pinecone export) is gentler, preserving throughput on marginal failures. The 2/3 factor (imports) is more aggressive, quickly dropping to sizes that fit within stricter import API constraints. The minimum threshold prevents infinite retry loops when errors are non-transient (e.g., malformed data).
The default batch sizes vary by backend:
- Pinecone export: `MAX_FETCH_SIZE = 1,000` (initial fetch size)
- Pinecone import: `BATCH_SIZE = 1,000` (default)
- Milvus import: `BATCH_SIZE = 1,000` (default)
- Qdrant import: `BATCH_SIZE = 64` (default, lower due to parallel threads)
- Re-embedding: `BATCH_SIZE = 96` (default, balanced for embedding API rate limits)
Code Evidence
Pinecone export adaptive fetch size reduction from `pinecone_export.py:546-552`:
except Exception as e:
if fetch_size < 1:
raise Exception("Could not fetch vectors")
tqdm.write(
f"Error fetching vectors: {e}. Trying with a smaller batch size "
f"(--batch_size): {fetch_size}"
)
fetch_size = fetch_size * 3 // 4
continue
Pinecone import batch reduction with minimum threshold from `pinecone_import.py:271-276`:
except Exception as e:
tqdm.write(
f"Error upserting vectors for index '{compliant_index_name}', {e}"
)
if current_batch_size < BATCH_SIZE / 100:
tqdm.write("Batch size is not the issue. Aborting import")
raise e
current_batch_size = int(2 * current_batch_size / 3)
tqdm.write(f"Reducing batch size to {current_batch_size}")
continue
Milvus import batch reduction from `milvus_import.py:208-212`:
except Exception as e:
tqdm.write(f"Error inserting data: {e}")
# reduce batch size
current_batch_size = current_batch_size * 2 // 3
tqdm.write(f"Reducing batch size to {current_batch_size}")
continue
Default batch size constants from `pinecone_export.py:23-27`:
PINECONE_MAX_K = 10_000
MAX_TRIES_OVERALL = 150
MAX_FETCH_SIZE = 1_000
THREAD_POOL_SIZE = 30
Qdrant import batch size with parallel threads from `qdrant_import.py:311-321`:
BATCH_SIZE = self.args.get("batch_size", 64) or 64
batches = list(divide_into_batches(points, BATCH_SIZE))
num_parallel_threads = self.args.get("parallel", 5) or 5
with concurrent.futures.ThreadPoolExecutor(
max_workers=num_parallel_threads
) as executor, tqdm(
total=total_points,
desc=f"Uploading points in batches of {BATCH_SIZE} in {num_parallel_threads} threads",
) as pbar:
Re-embedding batch size default from `reembed.py:427-431`:
parser.add_argument(
"--batch_size",
type=int,
help="Batch size for reembedding",
default=96,
)
Related Pages
- Principle:AI_Northstar_Tech_Vector_io_Batched_Data_Retrieval
- Principle:AI_Northstar_Tech_Vector_io_Batched_Data_Upsertion
- Principle:AI_Northstar_Tech_Vector_io_Re_embedding
- Implementation:AI_Northstar_Tech_Vector_io_ExportVDB
- Implementation:AI_Northstar_Tech_Vector_io_ImportVDB
- Implementation:AI_Northstar_Tech_Vector_io_Reembed