Module 1: What Are Vector Databases?
Understanding the Foundation of Modern AI Search
Introduction
Before we dive into specific databases and implementations, we need to understand what problem vector databases solve and why traditional databases fall short for AI applications.
By the end of this module, you'll understand:
- What vectors are and why they matter
- How vector databases differ from traditional databases
- The core operations every vector database supports
- When you need a vector database (and when you don't)
1.1 The Problem with Traditional Search
Keyword Matching Falls Short
Consider a customer support system with thousands of help articles. A user asks:
"My order hasn't arrived yet"
In a traditional database, you might search like this:
SELECT * FROM articles
WHERE content LIKE '%order%'
AND content LIKE '%arrived%'
This approach has problems:
- Synonyms: "package", "delivery", "shipment" won't match
- Meaning: "How to track my delivery" is relevant but won't match
- Phrasing: "Where is my package?" means the same thing but shares no keywords
Traditional search matches words. Users search for meaning.
The Semantic Gap
User query: "laptop for video editing"
Keyword match finds:
- "Laptop stands and accessories"
- "Video editing software tutorial"
- "Laptop repair services"
Semantic match should find:
- "MacBook Pro M3 Max with 36GB RAM"
- "ASUS ProArt Studiobook for creative professionals"
- "Best workstation laptops for content creators"
The difference between these results is the semantic gap—the difference between what words say and what they mean.
1.2 Enter Vectors: Capturing Meaning as Numbers
What is a Vector?
A vector is simply an array of numbers:
const vector = [0.1, -0.3, 0.8, 0.2, -0.5, 0.9, ...]
In the context of AI, vectors represent meaning. Text, images, audio—anything can be converted into a vector (called an embedding) that captures its semantic content.
Key insight: Similar things have similar vectors.
// These sentences would have similar vectors
const v1 = embed("The cat sat on the mat")
const v2 = embed("A feline rested on the rug")
// This sentence would have a very different vector
const v3 = embed("Stock prices fell sharply today")
How Similarity Works
Two vectors are similar if they point in similar directions. We measure this with distance or similarity metrics:
Cosine Similarity: Measures the angle between vectors
- 1.0 = identical direction (most similar)
- 0.0 = perpendicular (unrelated)
- -1.0 = opposite direction
// Conceptual example
cosineSimilarity(
embed("happy dog"),
embed("joyful puppy")
) // ≈ 0.92 (very similar)
cosineSimilarity(
embed("happy dog"),
embed("quarterly earnings report")
) // ≈ 0.12 (unrelated)
Vector Dimensions
Modern embedding models produce vectors with hundreds or thousands of dimensions:
- OpenAI text-embedding-3-small: 1,536 dimensions
- OpenAI text-embedding-3-large: 3,072 dimensions
- Cohere embed-v3: 1,024 dimensions
More dimensions = more nuance, but also more storage and compute.
1.3 What is a Vector Database?
A vector database is a specialized system designed to:
- Store millions or billions of vectors efficiently
- Index vectors for fast similarity search
- Query to find the most similar vectors to a given input
- Filter results based on metadata
- Scale to handle production workloads
Core Operations
Every vector database supports these fundamental operations:
1. Insert (Upsert)
await vectorDB.upsert({
id: "doc-123",
vector: [0.1, -0.3, 0.8, ...], // 1536 dimensions
metadata: {
title: "How to track your order",
category: "shipping",
lastUpdated: "2024-01-15"
}
})
2. Query (Similarity Search)
const results = await vectorDB.query({
vector: queryEmbedding,
topK: 10 // Return 10 most similar
})
// Returns:
// [
// { id: "doc-456", score: 0.95 },
// { id: "doc-789", score: 0.89 },
// ...
// ]
3. Filter (Metadata Filtering)
const results = await vectorDB.query({
vector: queryEmbedding,
topK: 10,
filter: {
category: "shipping",
lastUpdated: { $gte: "2024-01-01" }
}
})
4. Delete
await vectorDB.delete({ id: "doc-123" })
// or
await vectorDB.delete({ filter: { category: "deprecated" } })
1.4 Vector Databases vs. Traditional Databases
| Feature | Traditional DB | Vector DB |
|---|---|---|
| Primary Query | Exact match, range | Similarity |
| Data Type | Structured (rows/columns) | Vectors + metadata |
| Search Speed | O(log n) with indexes | O(log n) with ANN indexes |
| Use Case | Transactions, analytics | AI, search, recommendations |
| Example | "Find user with ID 123" | "Find users similar to this one" |
Can't I Just Use PostgreSQL?
You can—with pgvector. But there are tradeoffs:
PostgreSQL + pgvector:
- Great for small-medium datasets (< 1M vectors)
- Familiar SQL interface
- Single database for everything
- Limited scaling options
Purpose-built vector databases (Pinecone, Qdrant):
- Optimized for vector operations at scale
- Better performance for large datasets
- Managed infrastructure
- Advanced features (hybrid search, filtering)
We'll explore both approaches in this course.
1.5 When Do You Need a Vector Database?
You Need a Vector Database If:
-
Building RAG applications
- LLM needs access to your documents
- User queries need to find relevant context
-
Implementing semantic search
- Search by meaning, not keywords
- "Find articles about customer complaints" should work
-
Building recommendation systems
- "Similar products", "Related articles"
- Content-based filtering
-
Working with multimodal data
- Image similarity search
- Audio/video content matching
-
Large-scale similarity matching
- Deduplication
- Anomaly detection
You Might Not Need a Vector Database If:
-
Small dataset (< 10,000 items)
- In-memory search might be fast enough
- Simple solutions like FAISS in memory
-
Exact matching is sufficient
- Traditional full-text search works
- Users search by specific terms
-
Prototype phase
- Start simple, add vectors later
- Validate the use case first
1.6 The Vector Database Architecture
A typical vector database architecture includes:
┌─────────────────────────────────────────────────────┐
│ Application Layer │
│ (Your app, LangChain, AI SDK, etc.) │
└──────────────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Vector Database │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Index │ │ Storage │ │ Metadata │ │
│ │ (HNSW, │ │ (Vectors) │ │ (JSON, │ │
│ │ IVF...) │ │ │ │ filters) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Embedding Model (External) │
│ (OpenAI, Cohere, local models) │
└─────────────────────────────────────────────────────┘
Key components:
- Index: Data structure for fast similarity search (we'll cover this in Module 8)
- Storage: Where vectors and metadata are persisted
- Query Engine: Processes similarity queries and filters
- API Layer: HTTP/gRPC interface for applications
Key Takeaways
- Traditional databases match words; vector databases match meaning
- Vectors are arrays of numbers that capture semantic content
- Similar content produces similar vectors
- Vector databases are optimized for similarity search at scale
- The right choice depends on your scale, use case, and existing infrastructure
Exercise: Thinking in Vectors
Before moving on, consider these questions:
-
In your current or planned application, what searches would benefit from semantic understanding?
-
How large is your dataset? Would a simple solution suffice, or do you need a dedicated vector database?
-
Do you need to filter by metadata in addition to similarity? (e.g., "find similar documents from the last 30 days")
Write down your answers—they'll help you choose the right solution as we progress through the course.
Next up: Module 2 - Embeddings: Turning Text Into Numbers

