DEV Community

Cover image for Vector Databases: Types, Architecture, and Why They Power Modern Apps
Sameer Saleem
Sameer Saleem

Posted on

Vector Databases: Types, Architecture, and Why They Power Modern Apps

If you built an AI app in the early days of LLMs, you probably hit a wall pretty quickly: Large Language Models have no long-term memory. They forget who your user is, they don't know your company's proprietary documentation, and pasting 500-page PDFs directly into prompt context windows is expensive, slow, and prone to context rot.

Enter Vector Databases.

Whether you're building a Retrieval-Augmented Generation (RAG) pipeline, an autonomous AI agent with long-term memory, or a high-performance recommendation engine, vector databases have become core infrastructure.

Here is the complete guide to how vector databases work, the main types available, and why they matter for modern application development.


1. What is a Vector Database?

Traditional databases (like PostgreSQL, MySQL, or MongoDB) store scalar data—strings, integers, JSON objects—and rely on exact matches or range queries. If you search for "laptop", a traditional full-text index looks for the exact characters l-a-p-t-o-p. If your document contains "MacBook" or "portable computer", keyword search misses it completely unless manually tagged.

Vector databases, on the other hand, store high-dimensional vector embeddings.

"MacBook Air"       ---> [0.024, -0.198, 0.812, ... 1536 dimensions]
"Portable Computer" ---> [0.021, -0.201, 0.799, ... 1536 dimensions]
"Juicy Apple"       ---> [-0.512, 0.884, -0.012, ... 1536 dimensions]

Enter fullscreen mode Exit fullscreen mode

An embedding model (like OpenAI's text-embedding-3, Cohere, or an open-source model like bge-large-en) transforms unstructured data—text, images, audio, or video—into a sequence of floating-point numbers.

In this high-dimensional space:

  • Concepts with similar meanings are placed geometrically close to each other.
  • Unrelated concepts sit far apart.

A vector database indexes these numerical arrays so you can run Nearest Neighbor (k-NN) queries to find semantically similar items in milliseconds.

+--------------------------------------------------------------------------+
|                            THE VECTOR FLOW                               |
|                                                                          |
|  Unstructured Data   ===>   Embedding Model   ===>   High-Dim Vector     |
|  ("User Query")             (e.g., OpenAI)           [0.12, -0.45, ...]   |
|                                                               |          |
|                                                               v          |
|  Top K Results       <===   Vector DB Index   <===   Distance Search     |
|  (Nearest Neighbors)        (HNSW / IVF)             (Cosine/Dot Prod)   |
+--------------------------------------------------------------------------+

Enter fullscreen mode Exit fullscreen mode

2. How Similarity Search Works

Because calculating exact distances across billions of high-dimensional vectors is computationally impossible in real-time, vector databases use Approximate Nearest Neighbor (ANN) indexing algorithms:

  • HNSW (Hierarchical Navigable Small World): A multi-layer graph structure where top layers act as fast express lanes and lower layers pinpoint exact neighbors. It offers maximum accuracy and speed at the cost of higher RAM usage.
  • IVF (Inverted File Index): Groups vectors into Voronoi clusters. During queries, the database searches only within the nearest cluster centroids, drastically speeding up queries over massive datasets.
  • PQ (Product Quantization): Compresses vectors into smaller byte representations to save memory while preserving approximate distance metrics.

Distance Metrics

When querying vectors, the database calculates geometric distance using one of three metrics:

1. Cosine Similarity : Measures the ANGLE between vectors (best for normalized text).
2. Dot Product       : Measures ANGLE + MAGNITUDE (fastest for pre-normalized vectors).
3. Euclidean (L2)    : Measures STRAIGHT-LINE DISTANCE between vector endpoints.

Enter fullscreen mode Exit fullscreen mode

3. The Types of Vector Databases

Not all vector databases are built the same. The ecosystem has divided into distinct categories based on operational needs and scale:

Category Popular Examples Best Used For Trade-offs
Dedicated Vector DBs Pinecone, Qdrant, Milvus, Weaviate Massive scale (10M+ to Billions of vectors), low-latency requirements Extra infrastructure component to manage
Relational / SQL Extensions PostgreSQL + pgvector / pgvectorscale Teams already using SQL; moderate scale (<10M vectors) Shares CPU/RAM resources with primary database
Search Engine Extensions Elasticsearch, OpenSearch Hybrid keyword + vector search; heavy enterprise logs Higher memory footprint and query overhead
Embedded / In-Process Chroma, LanceDB, FAISS Local development, edge computing, mobile, zero-copy processing Limited multi-node horizontal scaling

4. Deep Dive into the Categories

A. Dedicated Vector Databases (Pinecone, Qdrant, Milvus)

Built ground-up specifically for high-dimensional arrays.

  • Qdrant (Rust-based): Renowned for fast payload filtering, payload indexing, and memory efficiency.
  • Pinecone (Managed Serverless): Offers zero-ops infrastructure with dynamic scaling and pay-per-query pricing.
  • Milvus (Distributed): Built for billion-scale enterprise deployments requiring GPU-accelerated indexing and cloud-native architecture.

B. Relational Extensions (pgvector on Postgres)

The most popular architectural movement is bringing vectors directly into relational data. With extensions like pgvector or pgvectorscale, you store embeddings inside a standard SQL column.

-- Creating a table with a 1536-dimensional vector column
CREATE TABLE knowledge_base (
    id SERIAL PRIMARY KEY,
    content TEXT,
    metadata JSONB,
    embedding vector(1536)
);

-- Creating an HNSW index for ultra-fast similarity search
CREATE INDEX ON knowledge_base 
USING hnsw (embedding vector_cosine_ops);

-- Performing a combined SQL + Vector query
SELECT content, metadata 
FROM knowledge_base 
WHERE metadata->>'category' = 'engineering'
ORDER BY embedding <=> '[0.012, -0.421, ...]' -- '<=>' is Cosine Distance
LIMIT 5;

Enter fullscreen mode Exit fullscreen mode

Why developers love pgvector: You perform joins, ACID transactions, metadata filters, and vector searches in a single SQL query without running a separate database service.

C. Embedded Vector Databases (LanceDB, Chroma)

Embedded databases run inside your application process (like SQLite). LanceDB, built on top of the Apache Arrow columnar format, allows zero-copy retrieval directly from disk or S3 buckets without loading everything into expensive RAM.


5. Why Vector Databases Are Essential in Application Development

1. Powering Production RAG (Retrieval-Augmented Generation)

LLMs hallucinate when asked about private enterprise data. RAG solves this by fetching real-time context before passing the query to the model.

import os
from pinecone import Pinecone
from langchain_openai import OpenAIEmbeddings

pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index("enterprise-kb")
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")

# 1. Convert user query to vector
query = "What is our company policy on remote work setup budgets?"
query_vector = embeddings.embed_query(query)

# 2. Retrieve top 3 semantically related internal documents
results = index.query(vector=query_vector, top_k=3, include_metadata=True)

# 3. Feed retrieved content into LLM context window
context = "\n".join([match["metadata"]["text"] for match in results["matches"]])

Enter fullscreen mode Exit fullscreen mode

2. Autonomous Agent Memory

Autonomous agents need short-term (scratchpad) and long-term (episodic) memory. By storing user interactions and agent execution steps in a vector store, agents recall past decisions and preferences seamlessly across long chat histories.

3. Hybrid Search (Dense + Sparse)

Pure vector search sometimes fails on exact code names, part numbers, or specific legal terms (e.g., looking for "Error 504" vs "Gateway Timeout").

Modern vector databases handle Hybrid Search—combining BM25 keyword scoring with dense vector similarity—to ensure exact name hits are never missed while keeping semantic context intact.

Final Score = (α * Sparse_BM25_Score) + ((1 - α) * Dense_Vector_Score)

Enter fullscreen mode Exit fullscreen mode

6. Architectural Decision Framework

When choosing your vector storage strategy, follow this quick playbook:

  • Starting a new project / < 5 Million vectors: Use PostgreSQL with `pgvector`. Keeping vectors alongside your existing database saves hours of synchronization overhead.
  • Building a client-side app / Local CLI tool: Use LanceDB or Chroma in-process.
  • Scale exceeds 10M+ vectors / Latency < 20ms required: Migrate to a dedicated vector database like Qdrant (for open-source/self-hosted control) or Pinecone (for serverless cloud simplicity).
  • Already deeply invested in Elastic / OpenSearch: Enable their built-in k-NN vector indexes to avoid spinning up new vendors.

Top comments (0)