---
title: "What is a vector database? Similarity search explained"
description: "A vector database stores embeddings and finds the nearest ones to a query vector fast. How HNSW and IVFFlat indexes trade recall for speed, and when you need one."
url: https://broadrouter.com/glossary/vector-database/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Vector database

Updated 2026-11-16

A vector database is a data store that holds embedding vectors, often with their source text and metadata, and answers nearest-neighbour queries: given a query vector, it returns the stored vectors most similar to it, usually by cosine distance, Euclidean distance or inner product.

Also called: vector store, vector DB, vector index, vector search engine, similarity search database

A vector database answers one question very fast: which stored items mean something close to this query?

## How it works

Each record is an [embedding](https://broadrouter.com/glossary/embeddings/), a fixed-length list of numbers, plus metadata such as the source text, a document ID and a date. At query time you embed the question with the same model and ask for the top k nearest vectors.

“Nearest” needs a distance measure. pgvector, the Postgres extension, offers three operators: `<->` for Euclidean (L2) distance, `<#>` for negative inner product and `<=>` for cosine distance. Use the one your embedding model was trained for; OpenAI recommends cosine similarity for its vectors.

Comparing a query against every stored vector is exact but slow at scale. Approximate nearest-neighbour (ANN) indexes avoid that:

| Index | How it works | Trade-off (per pgvector docs) |
| --- | --- | --- |
| HNSW | Layered proximity graph | Better speed-recall, slower build, more memory |
| IVFFlat | Vectors grouped into lists | Faster build, less memory, lower query speed at the same recall |

The HNSW paper by Malkov and Yashunin describes a stack of graphs where search starts at sparse upper layers, which “allows a logarithmic complexity scaling.” pgvector’s README sums up the deal: an approximate index “trades some recall for speed.”

## Why it matters

-   **It is the retriever in most [RAG](https://broadrouter.com/glossary/rag/) systems.** If the store misses the right chunk, the LLM never sees it.
-   **Recall is a setting, not a given.** ANN parameters change which results come back. Measure recall on real queries.
-   **Filtering.** Real queries add conditions such as language, customer or date. Check that filters apply before ranking, not after a top-k cut that drops valid hits.

## On BroadNet Inference

BroadNet does not host vector storage and its docs do not list an embeddings endpoint. A typical setup is your own vector store, an embedding model from another source, and a BroadNet chat model that writes the answer from retrieved chunks. For small corpora, a large [context window](https://broadrouter.com/glossary/context-window/) can replace the store; see [long context vs RAG](https://broadrouter.com/blog/long-context-vs-rag/). For Arabic text, [Arabic RAG search](https://broadrouter.com/blog/arabic-rag-search/) explains why a keyword index next to the vector index helps.

## Common mistakes

-   Querying with a different embedding model than the one used to index.
-   Tuning the LLM prompt when the real problem is low retrieval recall.

## Questions

### Do I need a dedicated vector database?

Not necessarily. Extensions such as pgvector add vector columns and similarity search to Postgres, so vectors can live next to your other data. Dedicated stores help at very large scale or with heavy filtering needs.

### Is vector search exact?

It can be. pgvector runs exact nearest-neighbour search by default, which gives perfect recall. Adding an HNSW or IVFFlat index makes it approximate and faster.

### Does a vector database store my text?

Usually you store the original chunk or a document ID next to each vector, because the prompt needs the text and a vector is not a reliable way to get it back. Still, Morris et al. (2023) rebuilt 92% of 32-token test inputs exactly from their embeddings, so protect vectors like the text itself.

## See also

-   [Embeddings](https://broadrouter.com/glossary/embeddings/) (term)
-   [RAG (retrieval-augmented generation)](https://broadrouter.com/glossary/rag/) (term)
-   [Context window](https://broadrouter.com/glossary/context-window/) (term)
-   [Grounding](https://broadrouter.com/glossary/grounding/) (term)
-   [Hybrid search](https://broadrouter.com/glossary/hybrid-search/) (term)
-   [BM25](https://broadrouter.com/glossary/bm25/) (term)
-   [Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/) (guide)
-   [Long context vs RAG: when 1M tokens replaces a vector DB](https://broadrouter.com/blog/long-context-vs-rag/) (article)
-   [Arabic RAG: normalisation, chunking and retrieval that works](https://broadrouter.com/blog/arabic-rag-search/) (article)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-vector-database&utm_content=page-cta) ·

**Sources**

-   [pgvector, open-source vector similarity search for Postgres (README) (checked 2026-11-16)](https://github.com/pgvector/pgvector)
-   [Malkov and Yashunin, Hierarchical Navigable Small World graphs (HNSW) (arXiv) (checked 2026-11-16)](https://arxiv.org/abs/1603.09320)
-   [OpenAI, vector embeddings guide (cosine similarity) (checked 2026-11-16)](https://developers.openai.com/api/docs/guides/embeddings)
-   [Morris et al., Text Embeddings Reveal (Almost) As Much As Text, arXiv 2310.06816, EMNLP 2023 (checked 2026-11-16)](https://arxiv.org/abs/2310.06816)
