Ask anything about this article
Hi! I've read this article.
What would you like to know?
@farhan
With the rise of Generative AI and RAG architectures, a new piece of infrastructure has become indispensable: The Vector Database.
Traditional relational databases (SQL) and document stores (NoSQL) are excellent for exact keyword matches. But if you want to search for meaning or context—"semantic search"—you need a database built to handle high-dimensional vectors.
In machine learning, an embedding model takes complex unstructured data (text, images, audio) and converts it into a list of floating-point numbers called a vector. For example, OpenAI's ada-002 model converts any string of text into a vector with 1,536 dimensions.
These numbers represent the semantic meaning of the data. Concepts that are similar in meaning end up physically close to each other in this 1,536-dimensional space.
If you have 10,000 vectors, you can easily store them in a standard PostgreSQL database and do a brute-force calculation (K-Nearest Neighbors, or KNN) to find the closest vectors to a query.
However, doing complex math operations across 1,536 dimensions for millions or billions of rows takes massive compute power. A brute-force search becomes painfully slow, taking minutes instead of milliseconds.
Vector databases solve this scaling problem by avoiding brute-force calculations. Instead, they use specialized indexing algorithms called Approximate Nearest Neighbor (ANN) search.
The most popular algorithm powering modern vector databases is HNSW (Hierarchical Navigable Small World).
HNSW builds a multi-layered graph of the vectors.
This allows the database to search millions of vectors in single-digit milliseconds, sacrificing only a tiny fraction of a percent in accuracy.
The ecosystem is currently booming, with several distinct approaches:
pgvector for PostgreSQL or Redis Vector Search. These are incredibly convenient if you want to keep your relational data and your vector data tightly coupled in the same database.Vector databases are no longer a niche tool for data scientists; they are core infrastructure for the next generation of software engineering.