In Day 6, we built a working RAG pipeline and saw FAISS retrieve the most relevant document chunks for our question. But FAISS does not actually understand language, it only searches vectors. So how does text become something that can be compared mathmatically? The answer is embeddings. In Day 7, we will explore how embedding models convert sentences into vectors, how semantic similarity is measured, and why this os one of key foundations of modern RAG systems.
We can keep continue on last day:
embedder = SentenceTransformer(
"sentence-transformers/all-MiniLM-L6-v2"
)
and also:
query_embedding = embedder.encode()
What exactly is an embedding, and why can vectors tell us that two sentences have similar meanings?
"PagedAttention improves KV Cache management"
↓
Embedding Model
↓
[0.12, -0.37, 0.81, 0.24, ...]
An embedding converts text into a numerical vector where semantic relationships can be represented geometrically.
So we just do a small embedding test:
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
model = SentenceTransformer(
"sentence-transformers/all-MiniLM-L6-v2",
device="cpu"
)
query = "How does PagedAttention manage KV Cache?"
documents = [
"""
PagedAttention is a memory management technique introduced by vLLM.
It divides the KV cache into blocks and maps logical KV blocks
to physical KV blocks.
""",
"""
KV Cache stores the Key and Value tensors generated by previous
tokens during autoregressive decoding.
""",
"""
Pizza is an Italian dish made with dough, cheese and tomato sauce.
"""
]
query_embedding = model.encode(
query,
normalize_embeddings=True
)
document_embeddings = model.encode(
documents,
normalize_embeddings=True
)
scores = cos_sim(
query_embedding,
document_embeddings
)[0]
for i, score in enumerate(scores):
print(
f"Document {i + 1}: "
f"{score.item():.4f}"
)
Based on the code given above that I knew here's the result:


The experiment shows that all-MiniLM-L6-v2 can distinguish related and unrelated sentences using embeddings. The two technical sentences achieved a cosine similarity of 0.5589, while comparisons with the unrelated pizza sentence were close to zero at around -0.04. This demonstrates why embeddings are useful in RAG: they allow the system to retrieve document chunks based on semantic meaning rather than exact keyword matches.
Can the embedding model recognize similar meaning even when the sentences do not use exactly the same words?
sentences = [
"How does vLLM manage GPU memory?",
"PagedAttention helps organize the KV cache efficiently.",
"GPU memory management in vLLM uses block-based KV storage.",
"Taipei has many night markets."
]

This experiment demonstrates that embeddings can identify semantic similarity even when sentences use different wording. That is exactly what makes embeddings useful for RAG: a user query can retrieve relevant document chunks based on meaning rather than exact keyword matches.
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
model = SentenceTransformer(
"sentence-transformers/all-MiniLM-L6-v2",
device="cpu"
)
query = "How does PagedAttention manage KV Cache?"
documents = [
"""
PagedAttention is a memory management technique introduced by vLLM.
It divides the KV cache into blocks and maps logical KV blocks
to physical KV blocks.
""",
"""
KV Cache stores the Key and Value tensors generated by previous
tokens during autoregressive decoding.
""",
"""
Pizza is an Italian dish made with dough, cheese and tomato sauce.
"""
]
query_embedding = model.encode(
query,
normalize_embeddings=True
)
document_embeddings = model.encode(
documents,
normalize_embeddings=True
)
scores = cos_sim(
query_embedding,
document_embeddings
)[0]
for i, score in enumerate(scores):
print(
f"Document {i + 1}: "
f"{score.item():.4f}"
)

Document 1 → 0.7816 ← Most relevant
Document 2 → 0.5217 ← Moderately relevant
Document 3 → -0.0156 ← Unrelated
The experiment successfully ranked the documents by semantic relevance. Document 1 achieved the highest cosine similarity score (0.7816), followed by Document 2 (0.5217), while Document 3 was essentially unrelated (-0.0156). This shows how embeddings can be used to identify and retrieve the most relevant documents for a RAG pipeline.
In Day 7, we looked at how embeddings turn text into vectors and how cosine similarity can be used to measure semantic relationships between sentences and documents.
Our experiments showed that semantically related sentences received higher similarity scores, while unrelated sentences produced scores close to zero. We also used the same idea to rank documents by relevance, which is exactly how retrieval works in a RAG system.