Vector Databases

Gen AI · Retrieval & Embeddings

Theory

A vector database stores embeddings together with the original text and metadata, and answers one main question fast: which stored vectors are nearest to this query vector? Comparing the query with every vector one by one (exact search) is fine for thousands of items but too slow for millions, so vector databases build approximate nearest-neighbour (ANN) indexes that trade a tiny amount of accuracy for a large speed gain.

Options range from dedicated vector databases to vector extensions and vector column types inside existing relational databases and data warehouses, which keeps vectors next to your regular tables. Real queries almost always combine similarity with metadata filters, such as "most similar tickets, only for this customer, only from the last 90 days", and return the top-k matches with their scores.

Why we use it

Searching millions of vectors by brute force is too slow for a live app. A vector database indexes them for fast nearest-neighbour search and combines that with normal filters such as date, category or permissions.

When to use it

Use one when you have many embeddings to search in real time, as in RAG or semantic search. For a few thousand vectors, an in-memory array or a vector column in your existing database is often enough.

How it works

  1. Question arrives from the app
  2. Embed the question into a query vector
  3. Apply metadata filters such as category or user access
  4. ANN index finds the nearest stored vectors
  5. Is the score above the minimum relevance? Yes: Keep the chunk in the results. No: Drop the weak match.
  6. Return the top-k chunks with text and scores

Example

# Pseudocode using a vector DB client
results = vector_db.query(
    vector=embed("refund policy question"),
    top_k=5,
    filter={"category": "billing", "date": {"$gte": "2026-01-01"}}
)
# returns the 5 most semantically similar billing docs from 2026

Key points

Gen AI topics

Foundations of Generative AI

Prompt Engineering

Retrieval & Embeddings

Customizing Model Behavior

AI Agents & Tool Use

Multimodal & Applied AI

Ethics, Cost & Careers

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Generative AI for the Data Stack

LLMs, prompt engineering, RAG, embeddings, agents and the tools shaping modern AI products — explained practically. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Section {{ sec.num }}

{{ sec.label }}

Gen AI  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

💡

{{ current.tldr }}

Explained

{{ para }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
See It In Action
{{ current.example }}
Key Takeaways — click to check off
{{ pt.mark }} {{ pt.text }}

Share this topic