AI / 6 min read
Day 12 of Becoming an AI Developer: Embeddings Explained for Developers
Learn how AI understands meaning, powers semantic search, and finds similar content using vector embeddings and cosine similarity.
Day 12 of Becoming an AI Developer: Embeddings Explained for Developers
Learn how AI understands meaning, powers semantic search, and finds similar content using vector embeddings and cosine similarity.

Why Does Google Understand What You Mean Even When You Don’t Type the Exact Words?
Imagine searching:
“How do I fix a slow React application?”
But the most relevant article is titled:
“Optimizing Frontend Performance in React”
None of your search terms exactly match.
Yet modern AI-powered search systems can still find it.
How?
The answer is Embeddings.
And if you’re building AI applications, chatbots, RAG systems, recommendation engines, or semantic search tools, embeddings are one of the most important concepts you’ll encounter.
So today let’s deep dive into it
Quick Recap: What We’ve Covered So Far
In the last 11 days, we explored:
- Day 2: How LLMs actually work
- Day 3: How ChatGPT generates responses
- Day 4: Prompt engineering
- Day 9 & 10: RAG, embeddings, vector databases, and Chat with PDF architecture
- Day 11: Context windows in AI
If you’d like to follow the complete journey and learn AI with me in 30 days, check out the full series below. Save the series to receive notifications whenever a new article is published.
Zero to AI Expert in 30 Days
What Are Embeddings?
An embedding is a numerical representation of data.
AI converts text into a list of numbers called a vector.
Instead of storing:
"React is a frontend library"the AI stores something like:
[0.23, -0.81, 0.45, 0.12, ...]This vector captures the semantic meaning of the sentence.
Similar meanings produce vectors that are close together in vector space.
Different meanings produce vectors that are far apart.
Human View vs AI View

Even though “Cat” and “Kitten” are different words, their vectors are very close because their meanings are related.

Why Do Embeddings Matter?
Traditional search relies on keyword matching.
For example:
Search Query:
JavaScript async programmingDocument:
Understanding Promises and AwaitA keyword search might miss this result because the exact words don’t match.
Embeddings solve this problem.
Instead of comparing words, they compare meaning.
This is called Semantic Search.
What Is Semantic Search?
Semantic search retrieves information based on meaning rather than exact keywords.
Traditional Search
Query:
"car"
Matches:
carMay not match:
automobile
vehicle
sedanSemantic Search
Query:
"car"Can match:
automobile
vehicle
SUV
sedanBecause the meanings are related.
This is why modern AI systems feel much smarter than traditional search engines.
How Semantic Search Works
At a high level:
- Convert documents into embeddings
- Store embeddings in a vector database
- Convert user query into an embedding
- Compare query vector against document vectors
- Return the most similar results
Workflow

Generating Embeddings with OpenAI
A typical workflow looks like this:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
const embedding = await client.embeddings.create({
model: "text-embedding-3-small",
input: "React performance optimization"
});
console.log(embedding.data[0].embedding);What This Does
- Sends text to the embedding model
- Receives a vector representation
- The vector can now be compared against other vectors
Common Beginner Mistake
Many developers regenerate embeddings every time a user searches.
Instead:
- Generate document embeddings once
- Store them
- Only generate embeddings for incoming queries
This dramatically reduces cost and latency.
Enter Cosine Similarity
Now we have vectors.
But how do we compare them?
This is where cosine similarity comes in.
Cosine similarity measures how closely two vectors point in the same direction.
Think of it as:
“How similar are these meanings?”
Example
Sentence A:
How to learn ReactSentence B:
React tutorial for beginnersSentence C:
Best pizza recipesAI generates embeddings:
A → [ ... ]
B → [ ... ]
C → [ ... ]Cosine similarity scores might look like:

Higher score = more similar meaning.

Simple Cosine Similarity Implementation
function cosineSimilarity(a, b) {
let dotProduct = 0;
let normA = 0;
let normB = 0;
for (let i = 0; i < a.length; i++) {
dotProduct += a[i] * b[i];
normA += a[i] * a[i];
normB += b[i] * b[i];
}
return dotProduct / (
Math.sqrt(normA) * Math.sqrt(normB)
);
}Why It Matters
This simple formula powers:
- Semantic search
- RAG systems
- Recommendation engines
- Similarity matching
- AI-powered document retrieval
Many AI products rely on this concept every second.
Real-World Architecture
A production semantic search system often looks like:

Common Vector Databases
Some popular options include:

These databases are optimised for finding similar vectors extremely fast.
The Most Important Insight Most Developers Miss
Many developers think embeddings are only useful for search.
They’re not.
Embeddings are actually the foundation of:
- Retrieval-Augmented Generation (RAG)
- AI assistants
- Recommendation systems
- Duplicate detection
- Content clustering
- Knowledge bases
- Document search
If your AI application needs to understand relationships between pieces of information, embeddings are usually involved somewhere.
The Surprising Payoff
Here’s the counterintuitive part:
AI doesn’t “understand” language the way humans do.
What feels like understanding is often the result of mathematical relationships between vectors.
A chatbot finding the right answer from thousands of documents isn’t searching for keywords.
It’s finding nearby points in a high-dimensional space.
The intelligence users experience often begins with a surprisingly simple idea:
Similar meanings end up close together.
Key Takeaways
- Embeddings convert text into numerical vectors.
- Similar meanings produce similar vectors.
- Semantic search compares meaning rather than keywords.
- Cosine similarity measures how closely two embeddings relate.
- Vector databases store and retrieve embeddings efficiently.
- Embeddings power RAG systems, AI assistants, recommendations, and modern search experiences.
As you continue your AI developer journey, you’ll discover that many advanced AI systems are built on a simple foundation:
Turn information into vectors, then find what is most similar.
And once you understand embeddings, concepts like RAG, vector databases, and AI retrieval systems become much easier to grasp.
Missed the previous articles?
- Read here: Build a Resume Analyser Using AI
- Read here: Architecture of Chat PDF App with AI
Upcoming
- Vector Databases Explained
🚀 Transitioning into AI as a developer?
I’m building a practical 30-day roadmap to help developers move into AI — step by step, without random tutorials or confusion.
👉 Save this series so you don’t miss the next day
Zero to AI Expert in 30 Days.
👉 To support my writings, you can buy me a coffee ☕️ 🤗
👉 What’s the biggest thing confusing you about AI right now? Drop it in the comments — I may cover it next.