Vector Database
- In Turkish
- Vektör Veritabanı
In short
A vector database is a database designed to store embeddings and quickly find the vectors most similar to a query, which powers semantic search and RAG.
What is a vector database?
A vector database stores data as vectors, the lists of numbers produced by embedding models, together with the original content and metadata such as titles or dates. Its main job is similarity search: given a query vector, it returns the stored vectors closest to it, which represent the items with the most similar meaning. This is also called nearest-neighbor search.
Comparing a query with every stored vector one by one becomes too slow with millions of items. Vector databases therefore build special indexes, most commonly approximate nearest neighbor (ANN) indexes such as HNSW, which organizes vectors into a layered graph that can be searched in a few hops. These indexes trade a tiny amount of accuracy for huge gains in speed, and most systems also let you filter results by metadata, such as only documents from a certain team.
A library is a useful analogy: a traditional database is like a catalog you search by exact title or author, while a vector database is like a librarian who can hand you books on a similar topic even if you don't know their titles. Vector databases are used for semantic search, recommendations, duplicate detection, image search, and the retrieval step of RAG applications.
A vector database is not always a separate product. Many relational and NoSQL databases now support vector columns and vector indexes, so small and medium projects can often keep embeddings next to their existing data. A dedicated vector database mainly pays off when you need to search very large collections with low latency.
Key takeaways
- A vector database stores embeddings and finds the ones most similar to a query.
- It measures similarity with metrics such as cosine similarity or Euclidean distance.
- Approximate nearest neighbor indexes make search fast across millions of vectors.
- It is the usual retrieval layer for semantic search and RAG.
- Many regular databases now offer vector search as a built-in feature.
Example
// vectorDb and embed are placeholders for a real client and embedding model
await vectorDb.upsert("docs", [
{ id: "1", vector: await embed("How to reset your password"), metadata: { team: "support" } },
{ id: "2", vector: await embed("Quarterly revenue report"), metadata: { team: "finance" } },
]);
// Search by meaning: returns the closest vectors, not exact keyword matches
const results = await vectorDb.query("docs", {
vector: await embed("I forgot my login"),
topK: 1,
filter: { team: "support" },
});
console.log(results[0].id); // "1"Readers ask
Why use a vector database instead of a regular database?
Regular database indexes are built for exact matches and ranges, such as finding a user by email. A vector database is built to find items with similar meaning, which keyword or exact-match queries cannot do.
What is approximate nearest neighbor search?
Approximate nearest neighbor (ANN) search finds vectors that are very close to the query without checking every stored vector. It may occasionally miss the exact best match, but it is dramatically faster on large datasets.
Can a relational database store vectors?
Yes. Many relational databases support vector columns and similarity search through built-in features or extensions. For many applications this is enough, and it avoids running and syncing a separate system.
See also
- EmbeddingAI & Machine Learning, p. 16An embedding is a list of numbers, called a vector, that represents the meaning of text, images, or other data so that similar items end up close together.
- RAGAI & Machine Learning, p. 38RAG is a technique that makes an LLM answer using relevant documents retrieved at question time, so its responses are grounded in current, specific data.
- DatabaseDatabases, p. 6A database is an organized collection of data stored on a computer, managed by software that lets applications save, search, and update it efficiently.
- Database IndexDatabases, p. 7A database index is a data structure that helps a database find rows quickly without scanning a whole table, much like the index at the back of a book.
- NoSQLDatabases, p. 29NoSQL is a family of databases that store data in models other than relational tables, such as documents, key-value pairs, wide columns, or graphs.
- LLMAI & Machine Learning, p. 25An LLM is a machine learning model trained on huge amounts of text that generates language by repeatedly predicting the next most likely piece of text.
- Cosine SimilarityAI & Machine Learning, p. 13Cosine similarity measures how alike two vectors are by the angle between them, from -1 to 1; it is the usual way to compare embeddings in semantic search.
- ChunkingAI & Machine Learning, p. 9Chunking splits long documents into smaller passages before they are embedded and stored, so a RAG system can find and pass on just the relevant parts.
Spotted a mistake or something missing on this page?Suggest an edit