Vector Databases: Embeddings, Similarity Search, and AI
Understand the idea
How AI embeddings and similarity search turned high-dimensional vectors into core database tech.
The idea
The rise of AI and Large Language Models has made a vital part of modern web development. When working with AI, text, code, audio, and images are turned into -lists of numbers (often 768 to 3072 numbers long) where items with similar meanings end up close to each other in mathematical space.
Normal databases search simple values (like numbers, strings, or dates) using indexes that sort items in a single straight line. But vectors have hundreds or thousands of dimensions. You cannot sort high-dimensional vectors with greater-than or less-than comparisons.
Instead, a vector database performs similarity search: given a search query vector, it finds the closest matching vectors using distance formulas like Cosine Similarity. Comparing a search vector against millions of items one by one requires a slow . To make search sub-second fast, vector engines use smart graph-based indexing algorithms (like HNSW).
In practice, teams usually choose between:
- Integrated Vector Relational (e.g. pgvector in PostgreSQL): Stores vectors alongside regular tables in your existing database, allowing a direct between vectors and user tables.
- Dedicated Vector Databases (e.g. Pinecone, Qdrant): Separate standalone services built specifically for tens of millions of vectors.
What changes
| Dimension | PostgreSQL with pgvector | Dedicated Vector DB (Pinecone / Qdrant) |
|---|---|---|
| Architecture | Extension running inside your existing Postgres instance | Independent standalone cluster or managed SaaS |
| Metadata Joins | Direct SQL JOIN between embeddings and user/order tables | Requires syncing IDs or pre-filtering in API code |
| Operational Overhead | Zero extra services to manage or monitor | Separate cluster, auth tokens, backups, and network latency |
| Scale Sweet Spot | Up to millions of vectors (covers 95% of applications) | Tens of millions to billions of high-dimensional vectors |
The command
Semantic similarity search using vector dot product
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
The mistake
Check the result
Run the example to see cosine similarity score database documents against a query vector, ranking semantic relevance.
Guided challenge
Compare semantic similarity scores
Update the function to return true when scoreA is greater than scoreB (closer semantic relevance) and false otherwise.
Compare semantic similarity scores
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
EXPECTED RESULT
true false
Hints 0/1
Use all hints or make 3 failed checks (0/3).
Free exploration
Change this example and run it again. Each run is a new process. Nothing is saved.
Your variation
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 150 XP. You can always revisit it.