LedgerBox

What is a vector database

Updated August 2026 · 5 minute read

A vector database stores embedding vectors together with metadata and a reference back to the source record, and answers one question fast: which stored vectors are nearest to this query vector . It exists because computing exact distances against millions of vectors is too slow, so it builds approximate nearest neighbor indexes that trade a small amount of recall for speed.

What a vector database stores

Each entry holds three things: the embedding vector itself, a metadata payload of ordinary fields such as dates, amounts, and account ids, and a pointer back to the source record. The vector is a search key, not the data; a query returns ids, scores, and metadata, and your application fetches the underlying document from wherever it lives.

The vectors arrive from outside. An embedding model, the subject of the companion article, maps each text chunk or record to a point in a space where nearby means similar; the database only stores and searches what your model produced. It follows that every vector in a collection must come from the same model, or the distances between them mean nothing.

The database also cannot repair what it is given. A financial document embedded as raw PDF text searches poorly; embedded as clean per-transaction rows it searches well. Producing those rows is where LedgerBox fits: a REST API and an open source TypeScript SDK that extract structured rows from bank statements before anything gets embedded.

A row lookup vs a similarity query

The clearest way to see what is new is to compare the two query shapes.

How a conventional database query differs from a vector similarity query
Conventional database Vector database
The question Which rows match this condition exactly? Which stored items are most similar to this one?
The input A key or a predicate over column values A query vector from the same embedding model
The result Every matching row, exactly The k nearest vectors, ranked by distance, usually approximate
The index B-tree or hash over column values An ANN structure such as HNSW or IVF over positions in space
A miss Zero rows when nothing matches Always k neighbors; relevance is a score, not a yes or no

How do vector databases work

Answering a similarity query exactly means measuring the distance from the query to every stored vector and keeping the smallest. That is trivial at ten thousand vectors and hopeless at a hundred million, because the work grows linearly with the collection. Approximate nearest neighbor search, ANN, is the escape hatch, accepting a small chance of missing a true neighbor in exchange for skipping most of the comparisons.

Two index families dominate. HNSW builds a layered graph in which each vector links to its neighbors, and a search hops greedily through the graph toward the query, descending layer by layer. IVF instead partitions the space into clusters and searches only the handful of clusters closest to the query. Both expose tuning parameters that move recall and latency against each other, and both are why results carry the word approximate: a slightly imperfect answer returned quickly usually beats a perfect one you had to wait for.

The practically hard part is not the similarity math but combining it with filters: nearest neighbors to this vector, but only where the account type is business and the date falls after January. Filter before the search and the index built over the whole collection no longer matches the survivors; filter after it and all k results may get thrown away. Engines differ more here than anywhere else, which makes filtered-query behavior the sharpest question to ask when evaluating one.

Dedicated engines vs pgvector

Dedicated engines include Pinecone, Weaviate, Milvus, Qdrant, and Chroma: systems built around ANN search, each with its own API, scaling story, and approach to the filtering problem above.

The other route extends a database you already run. pgvector adds a vector column type, distance operators, and HNSW and IVF indexing to Postgres, so embeddings sit in the same tables as everything else, inside the same transactions and joins, and the metadata filter is an ordinary WHERE clause. For many products that wins by subtraction: one fewer system to deploy, monitor, back up, and secure.

The honest tiebreaker is operational rather than algorithmic. A team already running Postgres with a collection in the hundreds of thousands of vectors rarely regrets starting with pgvector; a dedicated engine earns its keep when vector search is the core workload, the collection is very large, or its specific filtering and scaling machinery is the point.

When you do not need a vector database

Most projects start below the scale where any of this applies. A few thousand embeddings fit in memory as a plain array, and a flat scan that computes every distance is exact, a dozen lines of code, and quick enough that an index would add operational surface without adding anything a user could feel.

Treat the upgrade as a staircase, not a default. When the collection outgrows an in-memory scan, or needs persistence, concurrent writers, and filters, pgvector inside a Postgres you already operate comfortably covers a few hundred thousand vectors. A dedicated engine is the third step, and taking it on day one means running a new distributed system to serve queries a WHERE clause and an ORDER BY would have handled.

Questions people ask

How is a vector database different from a normal database?

A conventional database retrieves the rows that match a condition exactly; a vector database ranks everything by similarity to a query vector and returns the top of the ranking. The line is blurring, though: Postgres with pgvector is a normal database that also answers vector queries.

Do I need a vector database for RAG?

Not until the corpus demands one. Retrieval only requires finding the embeddings nearest the question, and for thousands of chunks an in-memory flat scan does that exactly. A vector database becomes the answer when the collection is too big to scan, must persist across processes, or has to be filtered by metadata.

Is pgvector good enough for production?

At the scales most products actually reach, yes. It brings HNSW and IVF indexing into Postgres, keeps filtering as plain SQL, and removes an entire system from the architecture; teams tend to outgrow it only when collections get very large or vector search becomes the central workload.

Can a vector database store the documents themselves?

It stores the vector, a metadata payload, and typically your id for the source record; some engines can hold raw text as payload too. Treating one as the system of record is usually a mistake: keep documents in your primary store and let the vector side hold search keys.

Where to go next

Structured rows for your pipeline?

Point the API or the TypeScript SDK at a statement and get clean rows back. Free to start, no card required.

Get started free