The backbone of every RAG system, semantic search, and recommendation engine. The most practically important topic for SDEs building AI products in 2026.
An embedding is a vector of floating-point numbers (typically 384–3072 dimensions) that represents the semantic meaning of a piece of text.
The key property: semantically similar text maps to vectors that are close together in the vector space.
| Model | Dimensions | Cost | Best For |
|---|---|---|---|
| OpenAI text-embedding-3-small | 1536 | $0.02 / 1M tokens | Good balance of cost and quality. Default choice for most applications. |
| OpenAI text-embedding-3-large | 3072 | $0.13 / 1M tokens | Highest quality. Use when retrieval accuracy matters most. |
| Google text-embedding-004 | 768 | Free (with Gemini API) | Excellent free option. Required for Firestore native vector search. |
| sentence-transformers/all-MiniLM-L6-v2 | 384 | Free (local) | Fastest, smallest, runs on CPU. For prototyping or cost-sensitive setups. |
| BAAI/bge-large-en-v1.5 | 1024 | Free (local) | Best open-source model. Competitive with OpenAI on MTEB benchmarks. |
Measures the angle between vectors. Range: −1 (opposite) to 1 (identical direction).
Ignores magnitude — only direction matters.
For normalized vectors: dot product = cosine similarity. Faster to compute (no division).
Affected by magnitude — if vectors aren't normalized, higher-magnitude vectors dominate.
Straight-line distance in vector space. Range: 0 (identical) to ∞.
Affected by vector magnitude — less reliable for text embeddings.
You have 1 million documents, each embedded as a 768-dim vector. A user asks a question. You need the top-5 most similar documents.
Idea: trade a tiny bit of accuracy (miss ~2-5% of true nearest neighbors) for a massive speedup.
ANN algorithms return results that are "approximately" nearest neighbors — fast enough for production, accurate enough to be useful.
Hierarchical Navigable Small World graph:
| Database | Type | Best For | Key Characteristic |
|---|---|---|---|
| Pinecone | Managed SaaS | Getting started fast, no infra to manage | Fully managed, easiest to set up, closed source. Good free tier. |
| Qdrant | Open source (Rust) | Self-hosted production systems | Very fast, excellent metadata filtering, Docker or cloud. Best OSS option. |
| Weaviate | Open source | Hybrid search (keyword + vector) needed | BM25 + vector hybrid built-in. Good for production with mixed search needs. |
| Chroma | Open source (Python) | Prototyping, local development, learning | Simplest API, in-memory or persistent, zero infra. Not for high-scale production. |
| pgvector | PostgreSQL extension | Already using PostgreSQL, don't want another service | Add vector column to existing Postgres table. Limited scale vs dedicated vector DBs. |
| Firestore Vector | Managed (Google) | Firebase/GCP projects with Gemini embeddings | Native KNN search in Firestore (launched late 2024). Zero extra infrastructure. Best for Firebase apps. |
→ Firestore native vector search. Zero extra infrastructure, uses Gemini embeddings natively.
→ pgvector. Add vector column to existing tables. No new service to operate.
→ Pinecone. Best developer experience, production-ready immediately.
→ Qdrant. Best performance, excellent filtering, active community.
Query: "iPhone 15 Pro Max camera"