Building with AI

Vector databases

4 min readintermediateUpdated 28 Sept 2026
1 · In one line

A vector database stores vectors and returns the saved records closest to a query vector, often with a score and any extra fields you ask for.

1 · What it is

A vector database keeps vectors and finds the ones closest to a query vector. A vector is a fixed-length list of numbers that stands for the meaning of a text, an image or other data. Items that mean similar things sit close together, so the closest vectors are the most alike. Those numbers come from an embedding model. You can run the model yourself and load finished vectors, or, in Pinecone, hand over plain text and let the service run a hosted model on it.

Picture each stored item as a row. Two parts are required: a label that names it and its list of numbers. Pinecone also lets you pin optional tags to the row, such as a language or a team, and a search can then skip rows whose tags do not match. Faiss is a similarity-search library developed mainly at Meta’s research lab. Faiss measures closeness by Euclidean distance or by dot product. Cosine similarity is a dot product taken after each vector is normalized.

Checking every vector gives exact answers, and pgvector does that by default. An approximate index is faster, but it can change which rows come back. HNSW, one such index, was described by Malkov and Yashunin in a paper first posted in March 2016. It builds layers of graphs that link nearby vectors. A search enters at the top layer. The authors report that the search cost grows logarithmically. pgvector offers HNSW as an index type and describes it as a multilayer graph. In pgvector, an index covers only rows whose vectors have the same number of dimensions.

2 · Why it exists

Checking every stored vector is exact, and an index trades a little accuracy for speed.

Exact costs timepgvector searches exactly by default, so it never misses a true nearest neighbour. Adding an approximate index speeds it up but gives up some of that recall.
A hit is only an idIn Faiss, each stored vector is known by an integer. A Qdrant search returns ids ranked by score, and leaves out the stored fields unless you ask.
Filters cut the hitsIn pgvector, an HNSW search with a filter can return fewer rows than you asked for. Qdrant offers a slower search mode, ACORN, that finds more matches when a filter is strict.
3 · How it works

Follow one password-reset question from the stored vector to the note that comes back.

In this example the query vector is already computed. Search starts at the upper layer of the graph.
  1. 1 · enterThe query arrives as a vector from the same embedding model that made the stored vectors.
  2. 2 · probeAn HNSW index starts the search at the top layer of a stack of proximity graphs.
  3. 3 · scoreCandidates are ranked by closeness, meaning the lowest Euclidean distance or the highest dot product.
  4. 4 · returnQdrant sends back point ids ordered by score, and adds the stored fields only when the query asks for them.

Meaning comes from an embedding model. You can run it yourself before storing anything, or some services, such as Pinecone, can run a hosted model for you.

4 · Where it's used
WhoWhat they askWhat it works with
Support lead“Which public articles explain a password reset?”Support vectors filtered to public articles
Research team“Which papers sit nearest this abstract?”Stored paper vectors, ranked by distance
Shop app“Which products look like this photo?”Image vectors, then a payload with price
Team wiki“Which notes match this question inside one team?”Note vectors filtered by team id
5 · What it solves, and what it doesn't
solves
  • An index layer such as HNSW makes nearest-neighbour search more efficient than a plain scan.
  • With pgvector, the vectors live in the same Postgres tables as the rest of your data.
  • In Pinecone, one query can combine closeness with a filter on metadata fields.
  • In Qdrant, a score threshold drops matches that are too weak.
doesn't solve
  • It does not create meaning by itself. An embedding model does that, whether you run it or the service runs it for you.
  • Approximate indexes can miss true neighbours. In pgvector, adding one can change what the same query returns.
  • Two identical HNSW searches in Qdrant may not list hits in the same order. Paging with an offset can then repeat or skip a point.
  • An index serves one distance. pgvector needs a separate index for each distance function you query with.
6 · Go deeper

Sources used

This explainer is written in original language. The links below support its factual claims.

  1. paperEfficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs, Malkov and Yashunin · read 27 Sept 2026
  2. repoFaiss, Meta · read 27 Sept 2026
  3. repopgvector, pgvector · read 27 Sept 2026
  4. docsSearch - Qdrant, Qdrant · read 27 Sept 2026
  5. docsIndex data overview - Pinecone Docs, Pinecone · read 27 Sept 2026