Part 1: Introduction to Vector Databases

← Back to Series Overview | Part 2: Vector Embeddings β†’

My Documentation Search Nightmare

It was 3 AM, and I was debugging why our engineering documentation search was completely useless.

The problem:

  • User searches: "how do I deploy a container"

  • Our docs literally had a page titled: "Kubernetes Deployment Guide"

  • Search returned ZERO results

Why? Our PostgreSQL full-text search looked for exact word matches:

  • Query: deploy, container

  • Doc title: kubernetes, deployment, guide

  • Match: NONE

I tried expanding synonyms manually (container β†’ docker β†’ kubernetes), but it was impossible to maintain. Our documentation had hundreds of pages.

User satisfaction was 41%. Developers were frustrated. The wiki was useless.

Then I discovered vector embeddings and semantic search.

The Transformation

I implemented pgvector and stored document embeddings. Same query, different results:

Search satisfaction jumped to 92% within a week.

The magic? Vector embeddings understand that:

  • "deploy container" β‰ˆ "kubernetes deployment"

  • "fix bug" β‰ˆ "debugging" β‰ˆ "troubleshoot"

  • "API authentication" β‰ˆ "REST security" β‰ˆ "OAuth implementation"

This article explains what vector databases are, why they matter, and when to use them.

What Is a Vector Database?

Simple definition: A database optimized for storing and searching multi-dimensional numeric arrays that represent the "meaning" of data.

Traditional Database Storage

Limitation: Only finds products with the word "laptop" in the name.

Vector Database Storage

Power: Finds products semantically similar to your query, even with different words.

Query: "portable computer for coding" Results:

  1. "MacBook Pro 14" Developer Edition"

  2. "ThinkPad X1 Carbon Programming Laptop"

  3. "Dell XPS 13 for Software Engineers"

None of these titles contain "portable," "computer," or "coding," but they're semantically similar.

How Vector Databases Work (The Simple Version)

Step 1: Convert text to vectors (embeddings)

What are these numbers? Coordinates in 1536-dimensional space that represent the "meaning" of the text.

Step 2: Store vectors in database

Step 3: Search by similarity

The <=> operator calculates cosine distance between vectors. Closer vectors = more similar meaning.

Real-World Use Cases I've Implemented

1. Documentation Search (The Problem I Started With)

Challenge: 500+ internal documentation pages, keyword search was useless.

Solution: Embedded all docs with text-embedding-3-small, stored in pgvector.

Results:

  • Search quality: 41% β†’ 92%

  • Average results: 0.3 β†’ 4.8 relevant pages

  • Time to find answer: 8 minutes β†’ 45 seconds

TypeScript implementation:

2. Customer Support Ticket Routing

Challenge: Route 1000+ daily tickets to correct team based on content, not just keywords.

Solution: Embedded ticket descriptions, found similar historical tickets, routed to same team.

Results:

  • Correct routing: 73% β†’ 91%

  • First response time: 4 hours β†’ 1.5 hours

  • Mis-routed tickets: 27% β†’ 9%

Key insight: "Payment not working" and "Card declined" are similar, even with different words.

3. E-commerce Product Recommendations

Challenge: Show "Similar Products" that actually make sense.

Solution: Embedded product descriptions, find nearest neighbors.

Results:

  • Click-through rate: 2.1% β†’ 8.7%

  • Add-to-cart from recommendations: 3x increase

  • Revenue from recommendations: $45k β†’ $189k monthly

When to Use Vector Databases

βœ… Perfect Use Cases

Semantic search - Find documents by meaning, not keywords

  • Documentation, knowledge bases, wikis

  • Customer support articles

  • Legal document discovery

  • Research paper search

Recommendations - Find similar items

  • Product recommendations

  • Content recommendations (articles, videos)

  • "Customers who bought this also bought..."

  • Job recommendations

RAG (Retrieval-Augmented Generation) - Give LLMs relevant context

  • Chatbots with company knowledge

  • Code completion with codebase context

  • Question answering from documents

Duplicate detection - Find semantically duplicate content

  • Duplicate support tickets

  • Similar bug reports

  • Plagiarism detection

  • Content moderation

Classification - Route or categorize by similarity

  • Support ticket routing

  • Email categorization

  • Intent classification

❌ When NOT to Use Vectors

Exact matches - Use traditional indexes

Aggregations and analytics - Use columnar databases

Transactional workloads - Use RDBMS

High cardinality filtering - Vectors don't replace WHERE clauses

Vector Databases vs Traditional Databases

Traditional Database: Exact Matching

Finds: Products with "laptop" in name Misses: "notebook computer," "portable workstation," "MacBook"

Vector Database: Semantic Matching

Finds: Laptops, notebooks, MacBooks, portable computers (all semantically similar) Power: Understands meaning, not just exact words

Why I Chose pgvector (PostgreSQL Extension)

I evaluated Pinecone, Weaviate, Qdrant, Milvus, and pgvector. Here's why I use pgvector for most projects:

βœ… Advantages

One database, not two

ACID transactions - Vectors stay consistent with your data Familiar SQL - Use existing PostgreSQL knowledge Lower costs - No separate vector database service ($0 β†’ $200/month saved) Simpler operations - One database to backup, monitor, scale Type safety - Prisma generates TypeScript types

⚠️ Limitations

Performance at massive scale - pgvector is great up to ~100M vectors. Beyond that, specialized DBs win.

Limited vector operations - Can't do complex graph traversals like some vector DBs.

Index flexibility - Fewer index types than specialized solutions.

For 90% of applications, pgvector is perfect. Start here, scale later if needed.

Vector Similarity Metrics (Quick Overview)

Vector databases use mathematical distance functions to find similar vectors:

Cosine Similarity (Most Common)

Measures angle between vectors. Good for: Text, embeddings from ML models.

Range: 0 (opposite) to 1 (identical)

Euclidean Distance (L2)

Straight-line distance between points. Good for: Spatial data, coordinates.

Range: 0 (identical) to ∞ (very different)

Dot Product

Magnitude AND angle. Good for: Normalized vectors, some ML models.

For text embeddings (OpenAI, Sentence Transformers), use cosine similarity.

My First Vector Search in 20 Lines

Here's the complete code to implement semantic search:

That's it. 20 lines for semantic search that understands meaning.

What's Next

In this article, you learned:

  • βœ… What vector databases are and why they matter

  • βœ… How they differ from traditional databases

  • βœ… Real use cases I've implemented

  • βœ… When to use vectors vs traditional search

  • βœ… Why I chose pgvector

  • βœ… Basic semantic search in 20 lines

Next: We'll dive deep into how embeddings actually work, how to generate them, and the math behind similarity search.


← Back to Series Overview | Part 2: Vector Embeddings Fundamentals β†’

Last updated