Batch Embedding Quality Checks
What you'll learn: How to validate embedding outputs to catch errors before they corrupt your vector database.
Why Quality Checks Matter
When you process thousands or millions of documents through batch embedding pipelines, you can't manually inspect every result. But silently corrupted embeddings—wrong dimensions, null values, or bizarre distributions—will ruin retrieval quality. Quality checks act as automated inspectors that catch problems immediately.
Think of it like a factory production line: you don't wait until customers complain to check if bottles are filled correctly. You install sensors that verify each batch meets specifications.
Three Essential Checks
1. Dimension Validation
Every embedding from a given model should have the same dimension. If you expect 768-dimensional vectors but suddenly get 384, something broke. Check the shape of each batch:
expected_dim = 768
if embeddings.shape[1] != expected_dim:
raise ValueError(f"Expected {expected_dim} dims, got {embeddings.shape[1]}")
2. Null/NaN Detection
API failures or encoding errors can produce null or NaN values. These poison similarity calculations:
import numpy as np
if np.isnan(embeddings).any():
raise ValueError("NaN values detected in embeddings")
3. Distribution Verification
Embeddings should have reasonable value ranges (typically -1 to 1 for normalized vectors). Calculate basic statistics:
mean = np.mean(embeddings)
std = np.std(embeddings)
# Flag if mean drifts far from 0 or std is suspiciously low
if abs(mean) > 0.5 or std < 0.01:
print(f"Warning: unusual distribution (mean={mean}, std={std})")
When to Run Checks
Run these checks after each batch completes, before writing to your vector database. Log failures and skip bad batches rather than corrupting your index.
Key Takeaway: Dimension validation, null detection, and distribution checks are your safety net—they catch embedding pipeline failures before bad data reaches production.