Course contents · Lesson 10 of 15

What Is a Vector Database? Search by Meaning

Retrieval-Augmented Generation · Lesson 10 of 15 · 8 min Foundations

Imagine you run support for an online shop with 50,000 help articles. A customer types "my package didn't come", and the best article is titled "Report a missing parcel". In the previous lesson you saw that embeddings can place both phrases close together on a map of meaning. The practical problem is storage and speed: where do you keep 50,000 vectors, and how do you find the nearest few in a fraction of a second? This lesson answers what is a vector database: a store built to keep those vectors and search them by meaning.

Shelved by meaning, not by alphabet

An ordinary database is great at exact questions such as "find order 1047" or "list customers in Pune". A keyword search engine is great at finding pages that contain the words you typed. Neither can answer "find pages that mean something like this", because neither knows anything about meaning. The figure below shows the difference with a handful of help pages.

Left: a keyword index maps the words delivery, parcel, password and refund to page numbers, and the search 'package didn't come' finds nothing. Right: a vector index places pages 12, 40 and 77 together as delivery problems and the same search returns them
The keyword index finds nothing because no page uses the words "package" or "come", while the vector index still lands among the delivery pages.

A vector database keeps one record for each piece of content, and each record has three parts:

  • The vector: the embedding of the text, made by an embedding model.
  • The original text, or a pointer to it such as a file name or web address, because a list of numbers means nothing to a person.
  • Metadata: extra details such as the source, the date, the language or who is allowed to see it.

How a search by meaning works

Every search follows the same three steps. First, the question is turned into a vector with the same embedding model that was used for the stored documents. Second, the database finds the stored vectors nearest to the question's vector. Third, it returns those records, usually with a similarity score for each one.

Flowchart: ahead of time, documents go through an embedding model into a vector database; at question time, the question goes through the same model, a nearest-neighbour search compares it with the stored vectors, and the top 3 results come back with text and sources
Embedding the documents is done once, ahead of time; each question then needs only one quick embedding and one search.

The number of results you ask for is called k, so this is known as a top-k search. With k = 3 you get the three closest records, as the next figure shows.

A map of help pages with a star for the question 'my parcel never came'; the three nearest pages, Late delivery, Report a missing parcel and Track your order, are circled, and farther pages are greyed out
With k = 3, only the three nearest pages come back; "Deliver to a new address" is fourth closest, so it misses out.

There is one catch. A top-k search always returns k results, even when nothing stored is relevant. Ask a shop's help centre about cricket scores and you still get three "closest" articles, which are simply the least far away. Well-built apps also set a minimum similarity score and say "nothing found" below it.

Why it stays fast with millions of vectors

The simplest way to search is to compare the question with every stored vector and keep the best k. This is called exact, or brute-force, search. It is fine for a few thousand vectors. With hundreds of millions, each a list of hundreds of numbers, it becomes too slow for an app that should answer in a blink.

So vector databases build an index ahead of time: a structure that lets each search look at only a small part of the collection. These are called approximate nearest neighbour (ANN) indexes. "Approximate" is an honest word here. They find the true nearest neighbours almost every time, but not always, and in exchange they are many times faster.

A popular one is HNSW, short for Hierarchical Navigable Small World. It links every vector to a few of its near neighbours, then adds sparser layers on top with fewer points and longer links. A search starts in the sparse top layer, hops towards the question, and drops down layer by layer, like taking the motorway, then main roads, then your own street. Other indexes split the map into regions and only search the regions closest to the question.

Filters and hybrid search

Meaning alone is rarely enough. A metadata filter narrows the search to records that match a rule: only documents from 2025, only pages in Hindi, or only files this user is allowed to open. Because the metadata is stored next to each vector, the database can apply the rule in the same query.

Hybrid search runs a keyword search and a vector search on the same question and merges both result lists into one ranking. The keyword side catches exact terms that embeddings blur, such as product codes, error numbers and names. The vector side catches different phrasings of the same idea. Many real search systems use both.

Do you actually need one?

Not always. A few thousand vectors fit easily in a computer's memory, and a short program can compare a question against all of them in milliseconds. A plain file is enough to store them between runs.

A vector database earns its place when the collection is large, changes often or is shared: millions of records, documents added and removed every day, many people searching at once, plus filters, permissions and backups. The options range from dedicated products such as Qdrant, Milvus, Weaviate and Pinecone to vector search added to databases you may already run, such as PostgreSQL with the pgvector extension.

Check yourself

Why must the question be embedded with the same model as the stored documents?

Each model builds its own map of meaning, so positions from two different maps cannot be compared.

Your search returns five results for a topic your documents never mention. Why, and what helps?

Top-k always returns the k nearest records however far away they are; a minimum similarity score lets the app say nothing relevant was found.

What does an approximate nearest neighbour index give up, and what does it gain?

It accepts a small chance of missing a true nearest neighbour in exchange for searching millions of vectors far faster than checking every one.