13 min read
Lesson 5 of 6
Production Deployment & Cost Optimization
From the course AI Embeddings & Vector Databases
Deploying embeddings and vector search in production requires attention to cost, latency, and reliability.
Cost Optimization
Embedding costs add up at scale:
- Cache embeddings: Never re-embed the same text. Use a hash-based cache.
- Dimensionality reduction: OpenAI's text-embedding-3 models support native dimension reduction (3072 → 1024 → 512) with minimal quality loss.
- Open-source models: Run BGE or Nomic locally to eliminate per-token API costs. A single GPU can embed millions of documents per day.
- Batch processing: Embed during off-peak hours when cloud GPU costs are lower.
Latency Optimization
For real-time applications, every millisecond counts:
- Approximate search: Accept 95-99% recall for 10-100× speed improvement over exact search
- Quantized vectors: Store as int8 instead of float32 for 4× less memory and faster distance calculations
- Index tuning: Adjust HNSW parameters (ef_construction, M) for your recall/speed tradeoff
- Caching: Cache frequent queries and their results
Keeping Embeddings Fresh
Documents change. Your embeddings need to stay current:
- Incremental updates: Re-embed only changed documents, not the entire corpus
- Change detection: Hash document content and compare to stored hashes
- Versioning: Track which embedding model version was used — re-embed everything when upgrading models
- TTL (Time-To-Live): For time-sensitive content, automatically expire and refresh embeddings
Observability
Monitor your embedding pipeline:
- Embedding generation latency and error rates
- Index size growth and memory usage
- Query latency percentiles (p50, p95, p99)
- Retrieval quality metrics over time
- Cost per query breakdown (embedding + search + generation)
Key Takeaways
- •Cache embeddings aggressively and use dimensionality reduction to cut costs
- •Open-source embedding models eliminate API costs for high-volume use cases
- •Implement incremental updates and change detection to keep embeddings fresh
- •Monitor query latency percentiles and retrieval quality continuously
0 of 6 lessons marked complete
Progress is kept in this browser only.