๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #434

Embeddings (Modern AI)

This note revisits embeddings specifically through the lens of modern AI applications โ€” how dense vector representations of text, images, and other data power the retrieval, search, and agent systems covered throughout this category.

The Core Idea, Recap

An embedding maps a piece of data โ€” a word, sentence, document, or image โ€” into a dense vector of real numbers \(\mathbf{v} \in \mathbb{R}^d\), positioned in a continuous space such that semantically similar inputs end up close together. Modern AI systems rely on this heavily: rather than comparing raw text or pixels directly, they compare embedding vectors, where "similar meaning" becomes "close in vector space" โ€” a computationally tractable operation.

Modern Embedding Models

Model FamilyTypical Use
Sentence/text embedding models (e.g. built on Transformer encoders)Semantic search, document similarity, retrieval for RAG systems
CLIP-style multimodal embeddingsPlacing images and text into a shared embedding space, enabling cross-modal search
Embeddings from LLM hidden statesRepurposing a large language model's internal representations for downstream retrieval tasks

Code โ€” Generating and Comparing Text Embeddings

from sentence_transformers import SentenceTransformer
import numpy as np

model = SentenceTransformer('all-MiniLM-L6-v2')

sentences = [
    "The cat sat on the mat.",
    "A feline rested on the rug.",
    "The stock market crashed today."
]

embeddings = model.encode(sentences)   # shape: (3, 384)

def cosine_similarity(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

print(cosine_similarity(embeddings[0], embeddings[1]))   # high -- similar meaning
print(cosine_similarity(embeddings[0], embeddings[2]))   # low -- unrelated meaning

Despite sharing almost no words in common, the first two sentences produce embeddings with high cosine similarity because they express similar meaning โ€” exactly the property that makes embeddings useful for semantic (meaning-based) search, rather than the brittle keyword matching of traditional search.

Why Embeddings Are the Foundation of Modern AI Retrieval

Every system in this category that needs to "find relevant information" โ€” RAG, semantic search, recommendation โ€” ultimately reduces to computing embeddings and comparing them efficiently, which is exactly why the next note, vector databases, exists: to store and search over millions or billions of these vectors efficiently.

Common Mistakes

  • Comparing embeddings from two different, incompatible models โ€” embedding spaces are specific to the model that produced them; vectors from different models aren't meaningfully comparable to each other.
  • Using a general-purpose embedding model for a highly specialized domain (e.g. legal or medical text) without evaluating whether a domain-specific or fine-tuned embedding model would perform meaningfully better.

Interview Relevance

Q: "Why can't you directly compare embedding vectors produced by two different embedding models?" Each embedding model learns its own internal geometry during training โ€” the specific dimensions, scale, and relative positioning of its vector space are specific to that model's training process and objective. Two different models can place semantically similar concepts at entirely different, incompatible coordinates in their respective spaces, so a vector from one model has no meaningful relationship to a vector from another โ€” comparisons (like cosine similarity) are only valid between embeddings produced by the same model.

Practice Question

Why does cosine similarity, rather than raw text matching, allow two sentences with completely different wording to be identified as semantically similar?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Embeddings (Modern AI) โ€“ FAQs

Quick answers about learning Embeddings (Modern AI) in Deep Learning.

This free note from CodingNow 2.0 explains Embeddings (Modern AI) in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Embeddings (Modern AI), is 100% free with no signup required.
With focused practice, most students grasp Embeddings (Modern AI) in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now