DEV Community

Aqsa Zafar
Aqsa Zafar

Posted on

What is a Vector Database? Super Easy Explanation for Beginners

vector database

In my last post, I explained What is RAG. But there's one part I skipped over, how does the AI actually find the right document so fast, out of hundreds or thousands of files? That part has a name, it's called a Vector Database. So in this article, I am gonna break that down too.

So give your few minutes and learn about Vector Databases and why every AI tool you use is secretly built on top of one.

So, without further ado, let’s get started-

What is a Vector Database?

Before moving to the working of a Vector Database, I would like to tell you about the actual problem it solves.

Suppose you have a search bar, and you type the word “dog.” A normal search bar will look for the exact word “dog” in all your documents. But what if your document has the word “puppy” instead? A normal search bar will completely miss it. Because for a computer, “dog” and “puppy” are two different words, even though for us, they basically mean the same thing.

This is the actual problem. Computers are good at matching exact text, but they are not good at understanding meaning. That’s where a Vector Database comes in.

vector database

So, this is the basic problem. Now let's understand what a vector actually is.

What is a Vector, Actually?

A vector is nothing but a list of numbers. That’s it. That list of numbers represents something, it could be a word, a sentence, a paragraph, or even an image.

Do you think? How can numbers represent a word?

Let me explain with an example you already know, GPS location.

When you share your location with a friend, you don’t say “I’m near the big tree, past the blue gate, next to the shop.” You just send two numbers, latitude and longitude. Those two numbers tell exactly where you are on the map.

A vector works the same way. Except instead of 2 numbers showing your location on Earth, it might have hundreds of numbers showing the “location” of a word or sentence in a giant space of meaning.

So when an AI model converts the word “dog” into a vector, it is basically giving “dog” a coordinate. And the word “puppy” gets a coordinate very close to it. Because their meaning is close too.

A vector database is not magic. It’s just a smart way of storing meaning as numbers, and then searching by closeness instead of by exact words.

The Map of Meaning

Now imagine a huge map. But instead of cities, this map has words placed on it. Words with similar meaning are placed close together. Words with different meaning are placed far apart.

Map of Mapping

As you can see in this image, “dog,” “puppy,” and “canine” are placed close together, because they mean almost the same thing. “Apple,” “banana,” and “mango” form their own group. And “sadness” is sitting all alone, far from everything, because it has nothing to do with the other words.

So a Vector Database is basically the system that stores all these coordinates. And when you ask a question, it just finds whatever is closest to your question on this map. That’s the whole idea.

How Does a Vector Database Actually Work?

Now Let’s understand the working in steps. There are mainly 4 steps involved-

  1. Convert text into a vector (this step is called embedding)

  2. Store the vector in the database along with the original text

  3. Convert your search query into a vector too

  4. Find the closest vectors and return their original text

Let’s understand each step one by one.

1. Embedding- Converting Text into Numbers

Every sentence or document you want to store first passes through an embedding model. This model converts your text into a vector, that long list of numbers we talked about earlier.

text = "I love machine learning"
vector = embedding_model.encode(text)

Output (simplified)
vector = [0.21, -0.08, 0.44, 0.12, ......]

So now this sentence is no longer just text, it’s a point in a giant space of meaning.

2. Storing the Vector

This vector, along with the original text, gets stored inside the vector database. Most popular vector databases right now are Pinecone, Chroma, Weaviate, and Qdrant. You don’t need to memorize all these names, just know that these tools exist for exactly this purpose.

3. Converting Your Question into a Vector

When you type a question, like “What is machine learning?”, that question also gets converted into a vector using the same embedding model.

4. Finding the Closest Match

Now the database compares your question’s vector with every vector it has stored. And it finds whichever ones are sitting closest. This closeness is usually measured using something called cosine similarity, but you don’t need to worry about the math behind it right now. Just remember, closer vectors mean closer meaning.

vector database

And that's the whole working procedure. Not that complicated once you break it down, right?

If you want to see this whole process explained visually with a real walkthrough, I made a full video on it. Watch it here-

Where is Vector Database Used in Real Life?

Now you might be thinking, “Okay Aqsa, but where do I actually see this in action?” So let me give you a few real examples-

  1. RAG Systems- Remember my previous post on RAG? The retriever part, the one that searches your documents, runs on a vector database in the background. This is literally the missing piece that connects both topics.

  2. Product Recommendations- When a shopping site shows “similar products,” it’s often comparing vectors of products, not just matching categories.

  3. Music and Video Recommendations- Apps that suggest songs based on “vibe” rather than just genre are comparing vectors of how the content sounds or feels.

  4. Chatbots and Customer Support- Any chatbot that searches through your company’s documents to answer a question is most likely using a vector database under the hood.

Vector Database vs Normal Database

I know at this point, you might be confused, what’s the difference between this and a normal database you already know? Let me clear it up-

  • Normal database stores exact values, and searches using exact match or filters. Good for something like “find the customer with ID = 5.”
  • Vector database stores meaning as numbers, and searches by closeness. Good for something like “find documents similar to this question.”

One thing you need to remember is, a vector database doesn’t replace a normal database. Most real systems use both together. Normal database for structured facts like price, ID, date. Vector database for anything that needs understanding of meaning, like text, images, or questions.

Conclusion

I tried to explain Vector Databases in a simple and easy to understand way. Hope you understood.

To summarize everything-

  • Normal search matches exact words, and misses things phrased differently
  • A vector is just a list of numbers that represents meaning
  • A vector database stores these numbers and finds the closest match when you search

That’s it.

I would suggest you go try a tool like Chroma yourself, it’s free and beginner friendly. And if you have any doubts, feel free to ask me in the comments. I would like to help you.

Happy Learning!

Top comments (0)