Skip to content

Vector Databases

What Is a Vector Database?

A vector database is a specialised database designed to store, index, and search high-dimensional vectors (arrays of numbers), typically produced by machine learning models such as:

  • Text embeddings (NLP)
  • Image embeddings (computer vision)
  • Audio embeddings
  • Recommendation system features

Instead of querying by exact values (e.g. WHERE name = 'x'), vector databases query by similarity:

“Find items most similar to this item.”

Why Do Vector Databases Exist?

Traditional databases struggle with semantic similarity.

Example:

  • Query: “A red sports car”
  • Stored text: “Ferrari 488 in crimson”

A relational or document DB sees different words resulting in no match

A vector DB sees similar meaning resulting in a high similarity score

Vector databases enable:

  • Semantic search
  • AI-powered retrieval (RAG)
  • Recommendation systems
  • Clustering and classification
  • Fraud/anomaly detection

Core Concept: Embeddings

An embedding is a numeric representation of data in a high-dimensional space.

Example (simplified):

"cat"  → [0.12, 0.98, -0.45, ...]
"dog"  → [0.10, 0.95, -0.40, ...]
"car"  → [-0.88, 0.01, 0.76, ...]
  • “cat” and “dog” vectors are close
  • “car” is far away

Modern embeddings typically have:

  • 384, 768, 1024, or 1536 dimensions
  • Generated by models like OpenAI, HuggingFace, Cohere, etc.

How Vector Databases Work (High Level)

flowchart LR
    A[Raw Data: Text / Image / Audio] --> B[Embedding Model]
    B --> C[Vector: float]
    C --> D[Vector Database]
    Q[User Query] --> B
    B --> C2[Query Vector]
    C2 --> D
    D --> R[Top-K Similar Results]

Key Steps

  1. Convert data into vectors
  2. Store vector array + metadata
  3. Index vectors for fast similarity search
  4. Query with a vector
  5. Return nearest neighbours

Similarity Search (The Core Operation)

Vector databases use distance metrics:

Metric Meaning
Cosine similarity Angle between vectors (most common for text)
Euclidean distance Straight-line distance
Dot product Magnitude-weighted similarity

Example (Cosine Similarity)

Similarity = 1 → identical meaning
Similarity = 0 → unrelated
Similarity < 0 → opposite meaning

Indexing: Why Vector Search Is Fast

Brute-force comparison is too slow for millions of vectors.

Vector DBs use Approximate Nearest Neighbour (ANN) algorithms:

  • HNSW (Hierarchical Navigable Small World graphs)
  • IVF (Inverted File Index)
  • PQ (Product Quantization)

These trade perfect accuracy for huge performance gains.

“Vector databases prioritise recall and latency over exactness using ANN indexing.”

What Makes a Database a “Vector Database”?

Core features:

  • Native vector data type (float[])
  • ANN indexing
  • Similarity search APIs
  • Metadata filtering
  • Hybrid queries (vector + structured)
  • Horizontal scaling
Database Type Notes
Pinecone Managed SaaS Very popular, easy
Weaviate Open-source / managed Strong hybrid search
Milvus Open-source High performance
Qdrant Open-source Rust-based, fast
Chroma Open-source Dev-focused
Azure AI Search Managed Vector + keyword
PostgreSQL + pgvector Extension Simple workloads

Vector DB vs Traditional Databases

Vector DB vs Relational (SQL Server, PostgreSQL)

Feature Relational DB Vector DB
Exact lookups
Joins
Transactions Limited
Semantic similarity
ANN indexing

SQL Server (even in .NET 10 ecosystems) is not suitable for large-scale vector similarity search.

Vector DB vs Document DB (MongoDB)

Aspect MongoDB Vector DB
Text search Keyword-based Semantic
AI workloads Weak Strong
Similarity search Limited Native

Hybrid Approaches

Very common pattern:

SQL / NoSQL → metadata
Vector DB → semantic search

Vector Databases in RAG (Retrieval Augmented Generation)

This is the killer use case.

flowchart TD
    Q[User Question] --> E[Embedding Model]
    E --> VQ[Query Vector]
    VQ --> VDB[Vector DB]
    VDB --> D[Relevant Documents]
    D --> LLM[LLM]
    LLM --> A[Final Answer]

Used to:

  • Chat with documents
  • Internal knowledge bots
  • Code assistants
  • Customer support AI

C# / .NET Usage Example (Conceptual)

Store vectors

float[] embedding = GetEmbedding("Product description");

await vectorDb.UpsertAsync(
    id: "product-123",
    vector: embedding,
    metadata: new { Category = "Shoes", Price = 120 }
);

Query vectors

var results = await vectorDb.QueryAsync(
    vector: queryEmbedding,
    topK: 5,
    filter: x => x.Category == "Shoes"
);

Most vector DBs provide:

  • REST APIs
  • gRPC
  • SDKs (some have C# clients, many use HTTP)

Advantages of Vector Databases

Strengths

  • Semantic understanding
  • Extremely fast similarity search
  • Scales to millions/billions of vectors
  • Essential for modern AI systems
  • Supports hybrid search
  • Enables RAG and recommendations

Disadvantages / Limitations

Weaknesses

  • Not transactional
  • No joins
  • Approximate results
  • Requires ML embedding step
  • Data is opaque (hard to reason about vectors)
  • Higher infra cost
  • Harder to debug than SQL

When NOT to Use a Vector Database

Do not use one if:

  • You only need keyword search
  • You need strict transactional guarantees
  • Data volume is tiny
  • Exact matching is required
  • Queries are simple WHERE clauses

Summary

A vector database stores high-dimensional embeddings and enables fast similarity search using approximate nearest neighbour algorithms. It is designed for semantic queries rather than exact matching and is foundational for modern AI systems such as RAG, recommendation engines, and semantic search.

Vector databases differ from relational or document databases by prioritising distance metrics, ANN indexing, and retrieval speed over transactions and joins. They are often used alongside traditional databases rather than replacing them.

Key Points

  • “Semantic similarity instead of exact matching”
  • “Approximate Nearest Neighbour indexing”
  • “Embedding-based retrieval”
  • “Hybrid search with metadata filters”
  • “Core component of Retrieval Augmented Generation”

Further Reading