# What Is a Vector Database?

> What a vector database stores, how it finds the closest matches, and when to use one, explained simply for your AI interview.

**In short:** A vector database stores embeddings, which are lists of numbers that stand for the meaning of text, images or audio. It quickly finds the stored items closest in meaning to a question, so it can be the search step behind a retrieval-augmented generation (RAG) app, where the model answers from text it is given.

AI and LLM interview question Q117, Retrieval-augmented generation (RAG). Beginner, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-a-vector-database

## Say it in 30 seconds

A vector database stores embeddings. An embedding is a list of numbers that stands for the meaning of a piece of text. When someone asks a question, the database finds the stored chunks closest in meaning, even when the words differ. It uses an index so it doesn't check every chunk, which means a small loss of accuracy for a big gain in speed. In a retrieval-augmented generation (RAG) app, it supplies the passages the model reads before it answers.

## Say it in 2 minutes

Start with what gets stored. An embedding model reads a passage and turns it into a long list of numbers, so passages with similar meaning end up with similar lists. A vector database keeps those lists with the original text and labels, such as the policy number and the date. Its main job is to answer one question quickly: which stored lists sit closest to this new one?

A normal keyword search finds the same words, so it can't see that a burst pipe and a water leak mean nearly the same thing. A vector database measures closeness with a distance measure such as cosine similarity (a score for how alike the direction of two lists is). It also keeps an index, so it doesn't measure every stored item for every question. The index trades a small amount of accuracy for speed, and that trade is what you tune.

Here is a real case. A mid-size insurer wants its claims assistant to answer from 400,000 policy wordings and claim notes. The database holds the chunks, the model reads the closest few, and filters keep policy B's wording away from policy A's customers. Storing the vectors is quick to set up. Choosing filters and chunk size, then testing on real questions, takes most of the project.

On its own, a vector database doesn't make an answer correct. Chunks, filters and a test set of real questions decide most of the quality.

## What is a vector database, in plain words?

A vector database is a database built to store embeddings and find the closest ones quickly. An embedding is a list of numbers that stands for what a piece of text, an image or a sound means. The database keeps those lists next to the original text and labels, such as a policy number or a date.

Picture a senior claims handler who files every policy clause by what it means. When a new claim about a burst pipe arrives, she pulls the three clauses closest to it, even if none of them uses the word burst. A vector database does this filing for an AI assistant, across far more documents than one person could read.

For an AI app, that lets the model find the right paragraphs before it writes an answer. Writing the answer is the model's job. Finding the paragraphs is the database's job.

Google Cloud's definition is broad: any database that can store, index and query these embeddings. So a vector database can be a product of its own, or vector support added to a database you already run.

- **Embedding:** A list of numbers that stands for the meaning of text, an image or a sound.
- **Vector:** The same thing as an embedding here: a list of numbers, seen as a point in space.
- **Chunk:** A short piece of a document, such as one clause or a few paragraphs, with its own embedding.
- **Index:** A structure that lets the database find close vectors without checking every one.
- **Metadata filter:** A rule on labels, such as policy-B or a 2026 date, that limits which chunks can be returned.

## How does a vector database find the right text?

The search runs in four steps. The question is turned into numbers by the same embedding model that filed the text. The database applies any filters and measures how close each vector is to the question. Some products filter first and some search first, as explained further down. Only the top few chunks go to the model.

Say an adjuster types "Is a burst pipe covered?" into the claims assistant. The words don't match the clause exactly, but their numbers sit close to the clause about water damage from a burst pipe.

*Diagram, How a question finds its text: A question goes through the embedding model, then the vector database filters and ranks chunks. Some products filter before the search and some after. Only the best few reach the model, which writes the answer from them.*
1. The question is turned into a list of numbers.
2. Those numbers go into the database.
3. Filters drop chunks from the wrong policy or date.
4. The closest few chunks are passed on.
5. The model writes its answer from those chunks.

How close means is set by a distance measure. Google lists dot product, cosine similarity and Euclidean distance. Cosine similarity compares the direction of two lists and ignores their length.

> "A vector database is any database that allows you to store, index, and query vector embeddings, or numerical representations of unstructured data, such as text, images, or audio." (Google Cloud)
>
> "When you add a file to a vector store it will be automatically chunked, embedded, and indexed." (OpenAI)

Where the filter runs depends on the product. Microsoft notes that the search engine can process the filter before or after executing the vector query, so check which order your product uses.

Here is the idea in plain Python, with small made-up vectors, three numbers each, so you can follow them by hand. Two policies are stored, and the search can be limited to one of them.

```python
# A tiny vector store for a claims team. The numbers are made up, like an embedding model's output.
import math

CHUNKS = [
    ("Burst pipe damage is covered up to $10,000.", "policy-A", [0.9, 0.1, 0.0]),
    ("Flood damage needs a separate rider.", "policy-A", [0.1, 0.9, 0.0]),
    ("Claims must be filed within 60 days.", "policy-B", [0.0, 0.2, 0.9]),
    ("Water leaks from storms are covered.", "policy-B", [0.7, 0.3, 0.1]),
]

def cosine(a, b):
    dot = sum(x * y for x, y in zip(a, b))
    norm = math.sqrt(sum(x * x for x in a)) * math.sqrt(sum(y * y for y in b))
    return dot / norm

def search(query, k, policy=None):
    # Filter by label first, then rank what is left by closeness in meaning.
    rows = [c for c in CHUNKS if policy in (None, c[1])]
    scored = sorted(((cosine(query, c[2]), c[0]) for c in rows), reverse=True)
    return [(round(score, 3), text) for score, text in scored[:k]]

question = [0.85, 0.15, 0.05]  # "Is a burst pipe covered?" as numbers
for row in search(question, k=2):
    print(row)
print(search(question, k=2, policy="policy-B"))
```

Output:

```text
(0.996, 'Burst pipe damage is covered up to $10,000.')
(0.971, 'Water leaks from storms are covered.')
[(0.971, 'Water leaks from storms are covered.'), (0.094, 'Claims must be filed within 60 days.')]
```

## Why is it fast at scale, and what does it give up?

The simple method is exact. Measure the distance from the question to every stored vector, then sort. Google says that calculating the exact distance between a query vector and every other vector can be computationally expensive. A small store can cope with it. A store of millions of chunks makes that slow to repeat for every question.

*Diagram, Exact search versus approximate search: Exact search measures every chunk. Approximate search opens only the nearby groups in its index, so it is quicker, and it can miss a few true matches. Both are shown side by side so you can compare them.*
1. Each stored chunk is measured against the question, one by one.
2. In a cluster index, only the nearby groups are opened.

Vector databases use approximate nearest-neighbour methods, which find close matches without checking every stored vector. Google describes this as trading a small amount of accuracy for speed, and calls that an acceptable compromise for most semantic search.

Many vector indexes group nearby vectors into clusters, so a query can open only the clusters near it. Google also lists graph and tree indexes, which work differently.

Worked example. A legal team holds 40,000 contracts and asks whether a clause limits liability. Exact search gives the true top ten. An approximate index may return nine of them and miss the clause that matters most. So the team tests recall (the share of true matches the search actually returns) on 200 questions with known answers, and sets the index to a recall target its lawyers can defend.

## Do you always need a separate vector database?

No. Vector search can live in a dedicated product or in a database you already run. The choice depends on your data size, your team and how much of the work is search.

- **Dedicated: A vector product.** Built around vector search, with its own indexes and filters. A good fit when search is the main job.
- **Inside your database: Vector support you already have.** AlloyDB for PostgreSQL has built-in vector support through pgvector. It keeps PostgreSQL compatibility, but check speed and filters on your own data.

Google expects the second option to spread. Its page says most databases will add vector support. Whether you need a separate one is a design choice to test on your data.

### How would you set up search over 400,000 claim documents?

Work through the pipeline, and name the choice at each step.

1. **Split the documents:** Cut each wording into chunks of a few paragraphs, and keep the policy number and date as labels.
2. **Embed and store:** Run every chunk through one embedding model and store the vectors with their labels. Questions must use the same model, or the distances mean nothing.
3. **Filter and search:** For a policy-B question, filter on policy B. Check whether your product applies the filter before or after the search.
4. **Test recall:** Keep 200 real questions with known right passages. Count how often the right chunk lands in the top five.
5. **Tune and watch the cost:** If recall is too low, change the index settings and measure how much slower search gets.

> **Tip:** Say the numbers you measured, such as recall on 200 real questions. "It works" is the weak answer.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a database that stores embeddings and finds the closest ones quickly.
- [ ] What an embedding is, and that questions and chunks must use the same model.
- [ ] Exact versus approximate search, and the accuracy-speed trade-off.
- [ ] Metadata filters, and that products apply them before or after the search.
- [ ] When vector support in an existing database is enough, and when a dedicated product fits.
- [ ] Testing: real questions with known right answers, and a recall number.

**Common traps**

- Trap: "It is a database that stores the documents, so the AI can read them." Better: It stores the vectors that point at the text. The model reads only the chunks you send it, so the chunking and filters matter.
- Trap: "Its search is exact, so it always finds the best answer." Better: Approximate search trades a little accuracy for speed. Name that trade-off, and say how you measured recall.
- Trap: "Buy the biggest vector database and the answers are right." Better: Chunks, filters and a test set of real questions usually decide quality first.

## Can you spot the bug, and pick the trade-off?

**Spot the bug:** Claims staff report that policy A wording is quoted to policy B customers. Which line causes it?

A. results = index.search(q_vec, k=5, filter={"policy": "policy-B"})
B. chunks = split_by_paragraph(wording, max_words=300)
C. results = index.search(q_vec, k=5)
D. print(len(results))

**Answer:** C. That search ranks chunks from every policy, so a policy A clause can win for a policy B customer. Add the metadata filter, then test with real questions.

**Quick check:** A claims team needs to find similar clauses across 400,000 wordings quickly. What do they accept with an approximate index?

A. Hours of search per question, since each clause is read by hand
B. A small loss of recall in return for much faster search
C. Exact answers for every question, so the index is never needed
D. No loss at all, because the index keeps every vector exact

**Answer:** B. Approximate search trades a small amount of accuracy, called recall, for speed. The team measures how much recall it loses on real questions before it trusts the setup.

## Can you answer these from memory?

**Flash cards**

- **What is a vector database?** A database that stores embeddings and finds the closest ones quickly.
- **What is an embedding?** A list of numbers that stands for the meaning of text, an image or a sound.
- **Why not an ordinary database?** Exact lookups don't measure closeness in meaning, so they miss near matches.
- **Exact or approximate search?** Exact checks every vector. Approximate checks nearby groups: faster, with a small loss of recall.
- **What is a metadata filter?** A rule on labels, such as policy or date, that limits which chunks the search can return.
- **Where does it fit in RAG?** It finds the chunks the model needs, which are sent along with the question.

## Likely follow-up questions

- Q113 What is chunking, and why does size matter? https://designervenkat.online/interview/ai/what-is-chunking-in-rag
- Q116 How do you choose an embedding model? https://designervenkat.online/interview/ai/how-do-you-choose-an-embedding-model
- Q118 Cosine vs dot product vs Euclidean distance? https://designervenkat.online/interview/ai/cosine-vs-dot-product-vs-euclidean-distance
- Q119 What is approximate nearest-neighbour search? https://designervenkat.online/interview/ai/what-is-approximate-nearest-neighbour-search
- Q120 How does HNSW work? https://designervenkat.online/interview/ai/how-does-hnsw-work
- Q123 What is hybrid search (BM25 + vectors)? https://designervenkat.online/interview/ai/what-is-hybrid-search

## Learn it in depth

- [Vector DBs](https://designervenkat.online/learn/ai-engineering/vector-dbs)
- [Embeddings for builders](https://designervenkat.online/learn/ai-engineering/embeddings)
- [Choosing a vector store](https://designervenkat.online/learn/ai-engineering/vector-stores)
