Embedding Models and Vector Databases Explained
From the course RAG & Knowledge Bases: Ground AI in Your Data
To make RAG work, you need two key technologies: embedding models that convert text to numbers, and vector databases that store and search those numbers efficiently.
What Are Embeddings?
An embedding is a numerical representation of text — a list of numbers (a "vector") that captures the meaning of words, sentences, or documents.
- "The cat sat on the mat" → [0.12, -0.45, 0.78, ...] (1536 numbers)
- "A feline rested on the rug" → [0.11, -0.44, 0.79, ...] (very similar numbers!)
- "Stock prices rose sharply" → [-0.89, 0.23, -0.15, ...] (very different numbers)
Similar meanings produce similar vectors. This is how semantic search works — you find documents by meaning, not just keyword matching.
Popular Embedding Models
| Model | Dimensions | Provider | Best For |
|---|---|---|---|
| text-embedding-3-large | 3072 | OpenAI | Highest accuracy |
| text-embedding-3-small | 1536 | OpenAI | Good balance |
| Gemini text-embedding | 768 | Cost-effective | |
| Cohere embed-v3 | 1024 | Cohere | Multilingual |
| BGE-M3 | 1024 | Open source | Self-hosted |
| Nomic Embed | 768 | Open source | Local deployment |
What Are Vector Databases?
A vector database is optimized for storing and searching vectors. Unlike traditional databases that match exact values (SQL WHERE clauses), vector databases find the most similar vectors to a query — even if there's no exact match.
How Vector Search Works
- Store document embeddings with metadata
- Convert user query to an embedding
- Find the K nearest vectors (most similar documents)
- Return those documents ranked by similarity
Popular Vector Databases
Cloud-hosted:
- Pinecone — Fully managed, easy to start, scales well. Best for teams that want zero infrastructure.
- Weaviate Cloud — Supports hybrid search (vector + keyword). Good for complex queries.
- Qdrant Cloud — High performance, rich filtering. Good for production workloads.
Self-hosted / Open source:
- Chroma — Lightweight, Python-native. Perfect for prototyping and small projects.
- pgvector (PostgreSQL) — Add vector search to your existing Postgres database. Great if you're already using PostgreSQL.
- Milvus — Highly scalable, designed for billions of vectors. Enterprise-grade.
- FAISS (Facebook) — In-memory vector search library. Fast but no persistence built-in.
Choosing an Embedding Model
Key factors:
- Dimensions — Higher dimensions = more nuance but more storage/compute
- Speed — How fast are embedding API calls?
- Cost — Per-token pricing adds up at scale
- Language support — Some models handle multilingual content better
- Domain — Some models are fine-tuned for specific domains (code, medical, legal)
Best Practice: Test Before Committing
Embed a sample of your documents with 2-3 different models. Run test queries and compare retrieval quality. The best model for your use case depends on your specific documents and query patterns.
Key Takeaways
- •Embeddings convert text into numerical vectors that capture semantic meaning
- •Similar meanings produce similar vectors — enabling search by meaning
- •Vector databases are optimized for finding the most similar vectors efficiently
- •Popular options range from managed (Pinecone) to self-hosted (pgvector, Chroma)
- •Always test multiple embedding models on your actual data before choosing one
Progress is kept in this browser only.