Lesson

Vector Databases and Embeddings

In the previous lesson, we said your app searches a "specialized database" to find the right paragraphs.

You cannot use a standard SQL database for RAG. If a user asks, "How do I fix my monitor?", a SQL database looking for the exact keyword "monitor" will fail to find a support article titled "Troubleshooting Screen Issues."

To make RAG work, we need a database that understands the meaning of words. We need a Vector Database.

What are Embeddings?

Before you can put text into a Vector Database, you must convert it into an Embedding.

An embedding is a massive list of numbers (an array) that represents the core meaning of a piece of text. You generate this list of numbers by passing the text through a specialized AI model (like Anthropic's voyage embedding models, or OpenAI's text-embedding-3).

For example, if you pass the word "dog" through an embedding model, it returns an array of 1,536 numbers: [0.012, -0.045, 0.887, ...]

If you pass the word "puppy", it returns a different array: [0.014, -0.042, 0.880, ...]

Because "dog" and "puppy" mean roughly the same thing, the math model ensures their number arrays are mathematically very similar. If you pass the word "car", the array will look completely different.

How a Vector Database Works

A Vector Database (like Pinecone, Weaviate, or pgvector) is designed to store these massive number arrays and calculate the mathematical distance between them incredibly fast.

Here is the setup process:

  1. You take your 10,000-page handbook and chop it up into 500-word paragraphs.
  2. You run every single paragraph through an embedding model to get its number array.
  3. You save the text and its corresponding number array into the Vector Database.

The Semantic Search

Now, the user asks: "How do I fix my monitor?"

  1. Your Node.js app takes the user's question and runs it through the same embedding model, generating a number array.
  2. Your app sends that array to the Vector Database.
  3. The database performs a mathematical "nearest neighbor" search. It compares the user's array against all 10,000 arrays in the database.
  4. It finds the array for the article "Troubleshooting Screen Issues" because their meanings (and therefore their numbers) are mathematically similar!
  5. The database returns the text of that article to your app.

This is called Semantic Search. It searches by concept and meaning, not by exact keyword matches. It is the engine that powers RAG.

Ready to test your understanding? Take the quiz to reinforce what you learned.

© 2026 Ant Skillsv.26.07.07-23:01