Vector Databases: A Complete Guide (in progress)

How Vector Databases Power AI, LLMs, and Semantic Search

A vector database is a specialized database designed to store, index, and search vector embeddings. Instead of searching by exact keywords or IDs, it searches by meaning (semantic similarity).


Vector databases have become a core component of modern AI applications such as ChatGPT, recommendation systems, semantic search, image search, and Retrieval-Augmented Generation (RAG).


What is a Vector?

A vector is simply a list of numbers that represents the meaning of data.


For example, the sentence:

"The cat is sleeping on the sofa."


might become:

[0.12, -0.45, 0.87, 0.91, ..., 0.33]


Instead of storing the sentence alone, AI models convert it into hundreds or thousands of numbers.


Common embedding sizes:

384 dimensions

768 dimensions

1024 dimensions

1536 dimensions

3072 dimensions

The closer two vectors are, the more similar their meanings.



Why Not Use SQL?

Suppose your database contains:


Text

I love dogs

My puppy is adorable

Cats are independent

This is semantic search.



Traditional Database vs Vector Database

Traditional DBVector DB
Stores rowsStores vectors
Exact matchingSimilarity matching
SQL queriesNearest-neighbor search
IDs, text, numbersEmbeddings
Uses indexes like B-treeUses ANN indexes
Good for transactionsGood for AI search



How Embeddings are Created

Data
  ↓
Embedding Model
  ↓
Vector


Example:
"The weather is nice"
  ↓
OpenAI Embedding Model
  ↓
[0.14, 0.22, -0.71, ...]


Popular embedding models:

  • OpenAI text-embedding models
  • Sentence Transformers
  • BERT
  • E5
  • Cohere Embed
  • Gemini Embeddings



Vector Database Architecture





Components

1. Original Data

Can be:

  • PDFs
  • Images
  • Videos
  • Audio
  • Emails
  • Web pages
  • SQL records


2. Embedding

Every item is converted into numbers.

Example:


Product A

Embedding

[0.11, -0.29, ...]


3. Metadata

Besides vectors, metadata is stored.

Example:

{

  "id": 1001,

  "category": "Electronics",

  "country": "UAE",

  "price": 599

}


This allows filtering.

Example:

Find similar laptops

WHERE country = UAE


4. Vector Index

This is the heart of a vector database.


Without an index:

Compare against, 1 million vectors, One by one Slow


With an ANN index:

Jump directly, Near the answer, Milliseconds



Similarity Search

When a user searches:

"I need a gaming laptop"


The query becomes:

Embedding

Vector

Compare with database

Most similar vectors



Distance Metrics

The database measures how close vectors are.


Cosine Similarity

Most common.


Measures angle: Small angle = High similarity


Range: -1 to 1

1 = identical


Euclidean Distance

Straight-line distance.


Smaller = More similar


Dot Product

Often used for recommendation systems.


Manhattan Distance

Measures city-block distance.

Less common.



Approximate Nearest Neighbor (ANN)

Searching every vector is slow.

Instead: ANN algorithms search intelligently.


Popular algorithms:

  • HNSW (most common)
  • IVF
  • PQ
  • ScaNN
  • DiskANN


Example:

Instead of checking

10 million vectors


ANN checks only

2000 vectors

Returns almost identical result








Metadata Filtering

Example:

Find

Similar restaurants

ONLY

Dubai

Rating > 4.5

This combines vector similarity with structured filtering.



Popular Vector Databases

DatabaseOpen SourceManaged
PineconeNoYes
MilvusYesYes
QdrantYesYes
WeaviateYesYes
ChromaYesLimited
pgvector (PostgreSQL)YesYes
Elasticsearch Vector SearchYesYes
Redis Vector SearchYesYes
MongoDB Atlas Vector SearchNoYes



Example Workflow

Suppose you build an AI chatbot.


Step 1

Store company manuals.

Step 2

Split into chunks.

Step 3

Create embeddings.

Step 4

Store in vector database.

Step 5

User asks:

"How do I reset my router?"

Create embedding.

Search nearest vectors.

Return relevant documentation.

LLM generates answer.



Vector Database in RAG

User Question

      │

      ▼

Embedding Model

      │

      ▼

Vector Database

      │

Top Similar Documents

      │

      ▼

LLM

      │

      ▼

Final Answer


Without a vector database:

LLM relies only on training data.


With one:

LLM can answer using your private documents.



Real-World Use Cases

AI Chatbots

  • Company knowledge bases
  • Customer support
  • Internal documentation

Semantic Search

  • Google-like enterprise search
  • Document search
  • PDF search

Recommendation Systems

  • Movies
  • Music
  • Shopping
  • News

Image Search

  • "Find similar images"
  • Face recognition
  • Medical imaging

Fraud Detection

  • Similar transaction detection

Code Search

  • Search source code by intent

Healthcare

  • Similar patient records
  • Medical literature search

Cybersecurity

  • Threat intelligence
  • Log similarity


Advantages

  • Understands meaning instead of exact words.
  • Fast semantic search over millions or billions of vectors.
  • Essential for RAG and AI assistants.
  • Supports hybrid search (vector + keyword).
  • Scales to very large datasets.
  • Stores metadata for filtered searches.

Limitations

  • Embedding generation adds computational cost.
  • Results depend on embedding quality.
  • High-dimensional indexes can use significant memory.
  • Updates may require index maintenance.
  • Traditional SQL queries alone cannot replace vector similarity search.


Best Practices

  • Use a high-quality embedding model suited to your data.
  • Split long documents into meaningful chunks before embedding.
  • Store metadata (author, category, date, language, etc.) to enable filtering.
  • Choose the right similarity metric (Cosine is the most common for text).
  • Use hybrid search (keyword + vector) for better accuracy.
  • Re-embed content when your embedding model changes.


Example: Building a RAG System in .NET

a common architecture is:


PDF / Website / SQL

        │

        ▼

Document Loader

        │

        ▼

Text Chunking

        │

        ▼

Embedding Model

(OpenAI, Azure OpenAI, etc.)

        │

        ▼

Vector Database

(Pinecone / Qdrant / pgvector / Milvus)

        │

        ▼

Similarity Search

        │

        ▼

Relevant Context

        │

        ▼

LLM (GPT)

        │

        ▼

AI Response


Popular .NET libraries include:

  • Microsoft Semantic Kernel for orchestrating AI workflows.
  • Microsoft.Extensions.AI for a unified AI abstraction.
  • Qdrant.Client, Pinecone SDKs, or Npgsql with pgvector for vector storage.
  • Azure AI Search if you're using the Azure ecosystem and want integrated vector search.


When should you use a vector database?

Use one when you need:

  • AI chatbots that answer from your own documents.
  • Semantic search rather than keyword search.
  • Recommendation engines.
  • Image, audio, or code similarity search.
  • RAG applications with LLMs.


If your application only performs standard CRUD operations, relational joins, and exact lookups, a traditional relational database is usually sufficient. Many modern applications combine both: a relational database for transactional data and a vector database (or vector extension such as pgvector) for AI-powered search and retrieval.


Comments