What Is a Vector Database? Definition and Examples
Quick answer
What a vector database is, how approximate nearest-neighbour search works, a short numpy example, and where it fits in RAG.
A vector database is a database that stores, manages and indexes high-dimensional vectors, so you can search by similarity of meaning instead of exact match. AI applications use it to find the stored items closest to a query, for example the help articles most relevant to a student's question.
Key takeaways
- A vector database stores embeddings and finds the nearest ones to a query vector.
- It relies on approximate nearest-neighbour search to avoid scanning every vector.
- It is the retrieval layer behind many RAG applications.
- For a small dataset, a plain loop or a regular database may be enough.
On this page:
- What a vector database means
- How it works, with a search example
- Where vector databases are used
- Common mistakes and confusions
- Related terms
- Frequently asked questions
| Feature | SQL database | Vector database |
|---|---|---|
| Typical data | Rows and columns | Embedding vectors with metadata |
| Typical question | Which rows match this value? | Which items are most similar to this? |
| Matching | Exact or range | Nearest by distance |
| Index | B-tree and similar | Graph-based such as HNSW |
What is a vector database?
IBM defines it in one line: a vector database stores, manages and indexes high-dimensional vector data. It adds that vector search is the retrieval layer used to discover and compare similar data points.
The vectors are usually embeddings. If that word is new, read our entry on embeddings in AI first.
How does a vector database work?
It embeds your data, stores the vectors, and answers a query by returning the nearest vectors. IBM says it uses approximate nearest-neighbour (ANN) search, which retrieves similar vectors without scanning the entire dataset.
One well-known ANN index is HNSW. In the HNSW paper on arXiv (Malkov and Yashunin), the approach is described as fully graph-based, without any need for additional search structures, and builds a multi-layer set of proximity graphs over nested subsets of the stored elements.
A brute-force version with made-up vectors, runnable with numpy:
import numpy as np
docs = {"refund policy": np.array([0.9, 0.1]),
"exam schedule": np.array([0.1, 0.9]),
"money back": np.array([0.85, 0.2])}
query = np.array([0.88, 0.12]) # "how do I get my refund"
def cosine(a, b):
return a @ b / (np.linalg.norm(a) * np.linalg.norm(b))
best = max(docs, key=lambda k: cosine(query, docs[k]))
print(best)A real vector database replaces this loop with an index such as HNSW, so a query does not have to be compared with every stored vector.
Where are vector databases used?
They are used for semantic search, recommendations and retrieval-augmented generation. The RAG paper on arXiv (Lewis et al., 2020) describes models that combine pre-trained parametric and non-parametric memory, where the non-parametric memory is a dense vector index of Wikipedia accessed with a pre-trained neural retriever.
An illustrative Indian case: a course help-desk bot with 400 articles. It embeds the student's question, searches the index, and passes the top passages to an LLM. Keyword search would miss "how do I get my refund" if the article says "money back policy". To compare tools, see best vector databases for RAG.
What are the common mistakes?
- Assuming you always need one. A small set of vectors can be searched with a simple loop.
- Treating results as exact. ANN search is approximate by design.
- Forgetting the embedding model. Query and stored vectors must come from the same model.
Which terms are related?
Embeddings, RAG and nearest-neighbour search are the closest. See what RAG is, RAG vs fine-tuning vs AI agents and Model Context Protocol.
Next step
Take ten FAQ answers, embed them with any embedding tool, and try the loop above before adding a database.
Frequently asked questions
What is a vector database used for?
It is used to find items similar in meaning to a query, such as in semantic search, recommendations and retrieval for RAG applications.
How is a vector database different from a SQL database?
A SQL database answers exact or range questions over rows. A vector database stores high-dimensional vectors and returns the nearest ones to a query by distance.
What is approximate nearest-neighbour search?
It retrieves similar vectors without scanning the entire dataset, as IBM describes it. It trades a little exactness for speed.
Do I need a vector database for RAG?
RAG needs some way to retrieve relevant passages. A vector database is a common choice, but for a small collection a simple similarity loop can work.
Which vector database should I learn?
Learn the concepts first: embeddings, similarity and indexes such as HNSW. Then try one tool from our comparison and keep the concepts portable.