Skip to content

Vector Databases and Similarity Search

How vector indexes find the nearest embeddings quickly, the main options, and when you don't need one.

Editorial team 2 min read

Once you have embeddings, you need to find the ones most similar to a query. That's nearest-neighbour search, and vector databases make it fast at scale.

  • Exact search compares the query with every vector. Perfectly accurate and fine for tens of thousands of vectors with NumPy.
  • Approximate nearest neighbour (ANN) search uses clever indexes to find very close matches much faster, trading a little accuracy for speed at millions of vectors.

Common Index Types

  • HNSW (hierarchical navigable small world graphs) — fast and accurate, widely used.
  • IVF (inverted file) — clusters vectors and searches only the nearest clusters.
  • Product quantisation — compresses vectors to save memory.

The Options

  • Libraries: FAISS, Annoy, hnswlib — you manage storage yourself.
  • Database extensions: pgvector for PostgreSQL, vector search in Elasticsearch and OpenSearch — keep vectors alongside existing data.
  • Dedicated vector databases: managed services and open-source systems built for vector workloads.

Features to Look For

Metadata filtering (by user, date, permission), hybrid keyword + vector search, updates and deletes, and backup and access control.

Do You Need One?

For a prototype or a few thousand documents, an in-memory array is simpler. If you already run PostgreSQL, an extension may be enough. Choose a dedicated system when scale, filtering or operational needs demand it.

Evaluate Retrieval Quality

Whatever you use, test with realistic queries: does the right item appear in the top results?

More in Generative AI

All Generative AI guides →
Generative AI Guide · 2 min

Prompt Engineering Fundamentals

The building blocks of a good prompt — context, task, constraints and format — with before-and-after examples.

Generative AI 2 min read 24 Jul 2026

Generative AI Guide · 2 min

Few-Shot Prompting With Examples

Showing a model a few examples of the input and output you want is often clearer than describing it. How to choose good examples.

Generative AI 2 min read 23 Jul 2026

Generative AI Guide · 2 min

Getting Structured Output From LLMs

How to get JSON and other machine-readable output reliably from a language model, and how to validate it.

Generative AI 2 min read 22 Jul 2026

Generative AI Guide · 2 min

Why Language Models Hallucinate

What hallucination is, why it happens, and practical ways to reduce and catch it.

Generative AI 2 min read 21 Jul 2026