Book a free call

How Does a Vector Database Work?

A vector database stores AI-made number lists called vectors and finds items that are similar in meaning. Learn how queries, indexes and similarity search work.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How Does a Vector Database Work?
On this page

Short answer

A vector database stores numerical lists called vectors, where each vector captures the meaning of a piece of text, an image or another item. To answer a query it turns the query into a vector, compares it with the stored vectors using a distance measure, and returns the items with the smallest distances.

What is a vector database?

A vector database is a database built to store and search numerical lists called vectors, where each vector represents the meaning of a piece of text, an image, a sound clip or another item, so that the database can find items that are similar in meaning rather than items that match a keyword exactly.

A vector is a long list of numbers, often hundreds of them, produced by an AI model called an embedding model. Two items with similar meanings get vectors that sit close together, and two items with different meanings get vectors that sit far apart. The database stores these vectors alongside the original item and a link back to it.

Three ideas sit at the centre of it:

  • Embeddings. An AI model turns each item into a list of numbers that captures its meaning.
  • Similarity search. The database compares a query vector with stored vectors and returns the closest ones.
  • Metadata filters. Each vector carries labels such as date, author or category, so a search can be narrowed before it runs.

A vector database does not replace a normal database. It handles one job, finding similar items fast, and it usually works next to a regular database that holds the full records. Teams that build search or AI features often pair the two, with data engineering work to keep the vectors and the records in step.

How does a query find similar items?

A query finds similar items in a vector database by turning the query into a vector, comparing it with the stored vectors using a distance measure, and returning the items with the smallest distances.

The usual sequence is:

  1. Embed the query. The same embedding model that indexed the data turns the search text into a vector.
  2. Search the index. The database walks an index structure that groups similar vectors together, instead of checking every vector one by one.
  3. Measure distance. It scores candidates with a measure such as cosine similarity or Euclidean distance.
  4. Apply filters. It drops results that fail the metadata filters, such as the wrong date or category.
  5. Return the top results. It sends back the closest items, usually the top 5 or 10, with their scores and links to the source records.

The index is what makes this fast. Checking every vector in a large collection would be slow, so the database builds a structure that narrows the search to a small region of likely matches. That shortcut trades a little accuracy for a large gain in speed, and most applications accept that trade.

What are vector indexes?

Vector indexes are data structures that group similar vectors together so a search can find near neighbours without scanning the whole collection, and the choice of index decides the balance between speed, accuracy and memory use.

Index typeHow it worksBest for
HNSWLinks each vector to near neighbours in layersFast, accurate search at scale
IVFSplits vectors into clusters, searches a fewLarge collections with filters
Product quantizationCompresses vectors into short codesVery large collections, low memory
Brute forceCompares the query with every vectorSmall collections, exact results
Disk-basedKeeps most of the index on diskCollections too large for memory

HNSW is the most common choice for general use. It builds a graph where each vector links to its nearest neighbours, and a search hops from node to node toward the query. It is fast and accurate, but it uses more memory than compressed indexes.

Product quantization takes the opposite approach. It compresses each vector into a short code, so a huge collection fits in memory, but the scores are approximate and some close matches can be missed. The right choice depends on how many vectors you have, how fast answers must be, and how much accuracy you can give up. A team building generative AI development features usually tests two or three indexes on its own data before choosing.

Where do vector databases fit?

Vector databases fit wherever a product needs to find things by meaning: search that understands intent, chatbots that answer from company documents, product recommendations and finding near-duplicate content.

The most common use is retrieval for AI chat. A chatbot turns the user's question into a vector, pulls the most similar passages from company documents, and hands them to a language model to write the answer. The vector database is the memory the chatbot searches, and the quality of its answers depends on what was put into it.

Other uses are simpler. A shop can find products similar to one a customer is viewing. A support team can find past tickets that describe the same fault. A media team can find images that look like a reference photo. In each case the pattern is the same: turn items into vectors once, then search by similarity many times.

A vector database is not the right tool for every job. Exact lookups, transactions and reports still belong in a normal database. The vector store earns its place only when similarity is the question being asked.

Example (hypothetical): a support team searches 200,000 help articles

Example (hypothetical): a software company has 200,000 help articles and wants support agents to find the right one from a customer's description of a fault.

Each article is turned into a vector of 768 numbers. With 200,000 articles, that is 200,000 times 768, which is 153,600,000 numbers. Stored as 4-byte numbers, the vectors take 614,400,000 bytes, or about 614 megabytes, plus the index and the article text.

An agent pastes a customer message into the search box. The system turns it into a vector, searches the index and returns the 5 closest articles in about 40 milliseconds. The agent opens the top article, finds the fix and replies to the customer in two minutes instead of twenty.

The team also tracks misses. Each week it checks 100 searches where the agent picked a lower-ranked article, and it finds that 12 of the 100 need a missing article. It writes those 12 articles and adds them to the index, so the next search finds them. The system improves because the misses are measured, not because the model changed.

What are the limits of a vector database?

The main limits of a vector database are that similarity is not the same as correctness, embeddings go stale as content changes, and large collections need careful tuning of the index and the hardware.

Similarity is the first limit. A vector search returns items that are close in meaning, but a close item can still be wrong, out of date or written for a different product. The database cannot judge truth; it can only judge closeness. That is why retrieval systems add filters, dates and a human check.

The second limit is staleness. When a document changes, its vector must be rebuilt, or the search will keep returning the old version. Teams that update content often need a pipeline that re-embeds changed items quickly, and that pipeline is easy to forget until stale answers appear.

The third limit is scale. A small collection is simple, but a collection of tens of millions of vectors needs index tuning, enough memory and a plan for growth. The wrong index can make searches slow or inaccurate, and the fix is usually a test on real data rather than a guess. A AI proof of concept is a good place to measure this before committing to a design.

What are the common mistakes?

The most common mistakes with vector databases are embedding the wrong content, skipping filters, and treating similarity scores as proof that an answer is right.

  • Embedding whole documents. Long documents mix many topics into one vector. Split content into short, focused passages first.
  • Skipping metadata filters. A search that ignores date, product or language will return close but useless results.
  • Trusting the score. A high similarity score means the text is close, not that it is correct or current.
  • Forgetting re-indexing. Changed documents need new vectors, or the search returns stale content.
  • Choosing the index by guesswork. Test indexes on your own data and your own queries before deciding.

Start small on purpose. Embed a few hundred passages, test real questions from real users, and measure how often the top result is the right one. That test will tell you more about whether a vector database fits than any feature list. A team that knows document AI can help with the splitting and labelling work that makes the search useful.

Key takeaways

  • Each item is turned into a vector by an embedding model, and similar meanings sit close together
  • A query is embedded the same way, then compared with stored vectors by distance
  • Indexes such as HNSW and IVF group similar vectors so searches stay fast at scale
  • The main use is retrieval for AI chat, search and recommendations
  • Similarity is not correctness, and stale vectors are the most common failure

Frequently asked questions

What is an embedding?

An embedding is a list of numbers, usually hundreds long, produced by an AI model from a piece of text, an image or another item. Items with similar meanings get similar lists of numbers, which is what lets a database compare meaning instead of matching keywords.

How is a vector database different from a normal database?

A normal database finds rows by exact values, such as a name or a date. A vector database finds items by similarity of meaning, which a normal database cannot do well. The two usually work together, with the normal database holding the full records.

What is cosine similarity?

Cosine similarity is a measure of the angle between two vectors, and it is the most common way to score how close two items are in meaning. A score near one means the items are very similar, while a score near zero means they are unrelated.

How many vectors can a vector database hold?

It depends on the product, the index and the hardware. Small collections of thousands of vectors run anywhere, while large collections of tens of millions need a tuned index and enough memory. Compressed indexes help when memory is the limit.

Do I need a vector database for a chatbot?

Only if the chatbot must answer from your own documents. A chatbot that answers from its training alone does not need one. If it must quote company policies, manuals or tickets, a vector database is the usual way to find the right passages.

What happens when a document changes?

Its vector must be rebuilt, or the search will keep returning the old version. Teams that update content often run a pipeline that re-embeds changed items automatically, so the index stays in step with the source documents.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building search or AI features that need to find things by meaning?

A senior engineer replies within one business day. Or see our Data Engineering service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call