Vector Database - Similarity Search Across Millions of Objects

A vector database stores embeddings and finds the most similar entries to a query in seconds. Methods like HNSW make nearest-neighbor search fast even across millions of objects. It is the backbone of semantic search, recommendations, and RAG.

Category:AI & Machine Learning

A vector database is a data store designed for a special data type: high-dimensional vectors, or embeddings. Instead of filtering by exact values, as a classic database does, it answers a different question: "Which stored entries are closest to this query?" This turns similarity itself into a search operation.

This is the foundation of modern AI search. A text or an image is turned into a vector, the database compares it against all stored vectors and returns the most similar ones - conceptually related, not merely letter-identical.

Nearest-Neighbor Search and HNSW

The core is the search for nearest neighbors in vector space. With few entries, each vector could be compared individually; with millions of objects, that would be too slow. Vector databases therefore use approximate methods:

  • HNSW (Hierarchical Navigable Small World): A graph-based index that navigates the search across multiple layers and finds very good matches in fractions of a second without checking everything.
  • Top-k search: The k most similar entries are returned - for example the twelve best candidates, from which a downstream step makes the final assignment.

pgvector: Vector Search in PostgreSQL

You do not necessarily need a specialized system. With the pgvector extension, the proven relational database PostgreSQL becomes a vector database. The advantage: vectors and classic business data live in one system, with the familiar operational, backup, and security properties - ideal for on-premises operation in an EU stack.

Recall@k as a Metric

Because the search is approximate, its quality is measured with Recall@k: how often is the correct match among the first k results? For the fine distinction of nearly identical objects, this metric is central. In a real project, an adapted model raised the top-12 match rate significantly over a generic solution - both in the regular test and on object classes never seen during training. Important: such values must be averaged over several runs, otherwise you measure noise as progress.

Operation and Data Protection

  • On-premises: A vector database can run entirely in your own data center; the data never leaves your infrastructure.
  • Frugal: Search and operation get by with moderate resources and require no dedicated graphics card.
  • EU stack: For privacy-critical applications, everything stays under your own control.

Typical Applications

  • Semantic search: Finding by meaning rather than exact keywords.
  • Catalog matching: Assigning a photographed object to the right entry.
  • RAG: Retrieving relevant documents for a language model (see RAG).

Vector Databases at Elasticbrains

At Elasticbrains we build similarity search on pgvector and HNSW - lean, fast, and on-premises. See how we combine vector search with adapted models on our service page Customizing AI Models.

More Glossary Terms