Dev.to AI 🤖 Ai 👁 0 📖 8 min read

Why the hardest vector database interview questions are about searches that fail without an error

Picture a customer of a document search product. They belong to tenant 42, they type a question, and they get back one result. The answer they need is in the index. The search ran without a problem. No log line says anyt

Why the hardest vector database interview questions are about searches that fail without an error

Picture a customer of a document search product. They belong to tenant 42, they type a question, and they get back one result. The answer they need is in the index. The search ran without a problem. No log line says anything went wrong.

That is what makes vector databases tricky, and it is why interviewers like them. A normal database usually tells you when something is wrong. A vector database almost always returns something. The results are just worse than they should be, and nobody notices until a user complains.

I wrote a page of 19 vector database interview questions with short answers, from freshers to senior AI engineers. While writing it, I saw that the questions that separate candidates are almost all about this quiet kind of failure. So in this post I walk through the main topics with one question in mind for each: how can this go wrong without an error?

First, what is being stored

A vector database stores embeddings. An embedding is a list of numbers, often hundreds or a few thousand long, that an embedding model makes from a piece of text, an image or a product. The model was trained so that things with similar meaning get vectors that point in similar directions. That is why a search for "car insurance" can find a passage about "vehicle cover" that shares none of the words.

Next to each vector, the database keeps an ID and some metadata, such as the source document, the tenant or a date. It also handles inserts, updates, deletes and filters, which is what makes it a database and not just an index library.

Quiet failure 1: two models in one index

Every vector in one index must come from the same embedding model, and the query must be embedded with that same model too. Vectors from two different models live in different spaces, so comparing them means nothing. Mix them, and the search still returns ten results. They are simply the wrong ten.

The same thing happens with the distance measure. Cosine similarity compares the angle between two vectors and ignores their length. Dot product multiplies the matching numbers and adds them up, so length counts too. Euclidean distance, also called L2, is the straight-line distance between two points. In pgvector these are the operators <=> for cosine distance, <#> for negative inner product and <-> for L2 distance.

The safe answer in an interview: use the measure the embedding model was trained with, which its documentation names. If the vectors are scaled to length 1, all three give the same order, and dot product is the cheapest to compute. The mistake to name is building the index with one measure and querying with another. Nothing crashes. You just get poor neighbours.

Exact search and approximate search

The simplest search compares the query with every stored vector. This is called exact or brute-force search. It always finds the true nearest items, and for a few thousand vectors it is often fast enough. At millions of vectors, every single query does millions of comparisons.

Approximate nearest neighbour search, or ANN, uses an index to look at only a small part of the data. It is much faster, and sometimes it misses a true neighbour. How often it finds the true neighbours is called recall.

Recall at 10 works like this. Exact search says which ten items are truly the closest. If the ANN index returns eight of those ten, recall at 10 is 0.8. You measure it on a sample of real queries, using exact search as the ground truth.

The two indexes you will be asked about

HNSW, short for hierarchical navigable small world, builds a graph in layers. Every vector is a point linked to some of its nearest neighbours. The bottom layer holds every point. Each layer above holds fewer, like express lanes on a highway. A search starts at the top, keeps moving to the neighbour closest to the query, drops down a layer and repeats, then looks around more widely on the bottom layer.

It has three settings. M is how many links each point keeps. ef_construction is how wide the search is while the graph is being built. ef_search is how many candidates a query keeps in play, and it is the main knob for trading recall against speed. In pgvector the defaults are m 16, ef_construction 64 and hnsw.ef_search 40.

IVF, short for inverted file, first groups the vectors into clusters, each with a centre point. Every vector goes into the list of its nearest centre. A query finds the few centres closest to it and searches only those lists. More lists searched means better recall and slower queries. pgvector's IVFFlat searches 1 list by default. Its README suggests rows divided by 1,000 lists for up to a million rows, and about the square root of the number of lists as a starting number to search.

The pgvector README states the trade-off directly. HNSW has a better speed-recall trade-off, but it builds more slowly and uses more memory. IVFFlat builds faster and uses less memory, but gives lower query speed at the same recall. IVF also learns its clusters from the data, so you build it after the table holds real data.

Quiet failure 2: the index grows and recall drops

This is the figure at the top of my page. It shows how far one HNSW setting goes at two sizes of index.

A line chart of ANN recall against HNSW ef_search on a log scale, with one curve for 1 million vectors and one for 10 million, showing the larger index needs a much higher ef_search to reach 98 percent recall

The curves are illustrative, and the chart says so. The point is the shape. With 1 million vectors, an ef_search of 64 reaches the 98 percent recall target. With 10 million vectors, the same target needs ef_search 256. If you tuned the setting at launch and never looked again, recall falls as the data grows, and nothing tells you.

So raise the knob until recall meets your target, check latency at the 95th or 99th percentile rather than the average, and keep recall in your monitoring.

Filters: the tenant 42 problem

Now back to the customer from the start. Most real queries come with a condition: only this tenant, only documents from this year, only products in stock. There are two basic ways to apply it.

Pre-filtering applies the condition while the index is being searched, so every result slot holds a matching item. Post-filtering runs the ANN search first, then throws away the results that fail the condition.

Two panels comparing where a filter runs: filtering inside the search returns ten valid results with the answer at rank 7, filtering after the search keeps one survivor in the top 10 at 0.4 percent selectivity

In the figure, the filter is tenant equals 42, and that tenant owns 0.4 percent of 10 million chunks. Filtering inside the search gives ten good candidates, with the answer at rank 7. Filtering after the search ranks all 10 million chunks first, then drops the ones from other tenants. One survivor is left in the top 10. Nine slots are empty. There is no error.

What does pgvector do here? Its README says that with approximate indexes, filtering is applied after the index is scanned. From version 0.8.0 it offers iterative index scans, which keep scanning until enough rows pass the filter. Other fixes worth naming are fetching many more candidates than you need, a partial index for a common filter value, or splitting the data by tenant.

Hybrid search, and why you cannot just add the scores

Vector search is good at finding the same meaning in different words. It is weaker on exact strings such as error codes, product names and order IDs, which embeddings tend to blur. Keyword search, usually BM25 over an inverted index, is the opposite. Hybrid search runs both and merges the results.

The trap question is how to merge them. A cosine score and a BM25 score are on different scales, so adding them is meaningless. Reciprocal rank fusion uses only positions instead. Each document earns 1 divided by (60 plus its rank) from every list it appears in, and the totals are sorted.

A worked example of reciprocal rank fusion merging a dense ranking and a sparse ranking, where documents found by both lists rise to the top

In the worked example, doc-A is first in the vector list and second in the keyword list, so it scores 0.03252 and wins. doc-E is first in the keyword list only, so it scores 0.01639 and still stays in the results. Documents that both searches found rise to the top, and a strong hit from one list is not lost. Nothing needs tuning.

Senior questions: change over time

Quiet failure 3: deletes that do not really delete

When a document changes, you re-split it, re-embed the changed pieces and replace the old vectors. That is why each piece needs a stable ID tied to its source document and version. A delete must remove every piece of that document, including from any cache. Miss one, and deleted content keeps showing up in answers.

Inside the index, a graph like HNSW cannot cheaply remove a point, so engines commonly mark it deleted, skip it in results and clean up later. A lot of churn can slowly lower recall and waste memory. In pgvector the index follows normal PostgreSQL rules, so VACUUM cleans up deleted rows. Track the share of deleted items and recall over time.

Changing the embedding model

You cannot mix old and new vectors. So you build a second index: re-embed every piece with the new model, keep serving from the old one meanwhile, and compare the two on a fixed set of real questions with known good answers. Then move traffic and keep the old index for a quick rollback. This only works if you kept the original text.

pgvector or a separate database

If your data already lives in PostgreSQL, pgvector puts vectors next to the rows they describe, with the joins, transactions, backups and access control you already run, and no second system to keep in sync. Its README lists vectors of up to 16,000 dimensions, with indexes up to 2,000 dimensions for the standard vector type and 4,000 for halfvec.

A dedicated vector database earns its place when vector search is the main workload and the scale or features go past what you want inside Postgres, such as sharding across many nodes. And a small collection may need neither: exact search in memory is simple and finds every true neighbour.

The habit that wins these questions

Name the trade-off, then say how you would measure it. The honest finish is nearly always the same: measure recall against exact search on your own queries, because settings that worked at one size or on one dataset do not carry over.

All 19 questions, each linked to the course lesson behind it, are here: vector database interview questions and answers.

Where these topics are taught in full

Vector search usually sits inside a bigger task, such as designing a RAG system. My AI Engineering course teaches embeddings, chunking, hybrid retrieval, reranking and agents in production step by step, with diagrams and quizzes. For readers outside India it is $35, paid once: the AI Engineering course.

The other half of those interviews is the system around the search: sharding, replicas, caching and the trade-offs between them. That is my System Design Masterclass, also $35 outside India: the System Design course.

If you want both, there is one payment of $59 for the two courses, which costs less than buying them one at a time: both courses in one payment.

This article was first published on systemdesign.academy.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.