RAG & Vector Databases · Lesson 1
Embeddings and Similarity Metrics
What an embedding is, cosine vs dot product vs Euclidean, comparing text-embedding-3-large, ada-002, Cohere Embed v3 and all-MiniLM, choosing dimensions.
What an embedding is
An embedding is a fixed-length dense vector (e.g., 1536 or 3072 numbers) that encodes the meaning of text. Semantically similar fragments sit close together in this space even if they share no words. That is the basis of semantic search: instead of keyword matching we look for nearby vectors.
import os
from openai import OpenAI
client = OpenAI()
resp = client.embeddings.create(
model="text-embedding-3-large",
input=["How do I reset my password?", "Recovering account access"],
dimensions=1536, # 3-large is natively 3072, can be truncated
)
v1 = resp.data[0].embedding
v2 = resp.data[1].embedding
print(len(v1)) # 1536
The rest of this lesson opens after a free sign-up
Sign up with email or Google: the first two lessons of every course stay open for good, and the whole catalog is open for 7 days. No card needed.
