LESSON 28 · EMBEDDINGS

Vector Representation

Understand what a vector representation really means, how information is positioned inside a vector space, how vectors can be compared, and why this idea is fundamental to semantic search, recommendations, clustering, and RAG.

30 min read•Beginner•Generative AI

By the end of this lesson, you will be able to:

  • Explain what a vector representation is in an AI system.
  • Understand dimensions, coordinates, magnitude, and direction.
  • Explain why similar concepts can be close in a vector space.
  • Compare vectors using common distance and similarity measures.
  • Connect vector representations to search, recommendations, and RAG.
1

What Is a Vector Representation?

A vector is an ordered collection of numbers. In machine learning, a vector can represent an object, such as text, an image, a product, or another piece of data. An embedding model creates a vector that captures useful patterns learned from data.

EXAMPLE REPRESENTATION
[ 0.21, -0.48, 0.73, 0.15, -0.09, … ]
A vector is a numerical coordinate inside a high-dimensional space.
Key idea: The individual numbers usually do not have simple human-readable meanings. Their usefulness comes from the relationships between complete vectors.
2

From Meaning to Coordinates

Imagine placing information on a map. A physical map uses latitude and longitude. A vector representation uses many numerical dimensions instead. Together, those coordinates locate an item in a mathematical space.

cat
dog
car
banana
Illustration: related concepts can occupy nearby regions.

This drawing has only two dimensions so humans can visualize it. Real embedding vectors commonly have hundreds or thousands of dimensions.

3

Dimensions Are Coordinates

If a vector contains 768 numbers, it has 768 dimensions. Each position contributes one coordinate to the complete representation.

Dimension 10.21
Dimension 2-0.48
Dimension 30.73
Dimension 40.15
Dimension 5-0.09
……
Important: Do not assume Dimension 17 means “topic” or Dimension 200 means “sentiment.” In learned representations, useful information is generally distributed across many dimensions.
4

Direction and Magnitude

Two useful geometric ideas are direction and magnitude. Direction describes the orientation of a vector, while magnitude describes its length.

Vector A
Vector B
0

Cosine similarity focuses on the angle between vectors, while other metrics can also take magnitude into account. The right choice depends on the application.

5

Why Similar Things Can Be Close

An embedding model is trained so that useful relationships in its training objective can be represented geometrically. As a result, texts with related meanings may have vectors that are close according to an appropriate similarity measure.

“How can I reset my password?”
“I forgot my password.”
“Where can I change my login password?”
“How do I recover my account?”
“What is the weather today?”

The first three examples are likely to be more relevant to a password-recovery query than the unrelated weather question. Actual rankings depend on the selected model and data.

6

Vector Similarity vs Exact Matching

Keyword matching looks for overlapping words. Vector similarity can retrieve text that expresses a related idea even when the wording is different.

KEYWORD MATCH

Exact words

Query: “cancel subscription”

Strong match: “How to cancel your subscription”

VS
VECTOR SIMILARITY

Related meaning

Query: “I don't want my plan anymore”

Potential match: “How to end your membership”

Practical value: Vector representations help applications search by meaning rather than relying only on exact word overlap.
7

Cosine Similarity

Cosine similarity measures the cosine of the angle between two vectors. It is commonly used when comparing embedding vectors.

CONCEPT cos(θ) = (A · B) / (||A|| × ||B||) Dot product divided by the product of the vectors' magnitudes.
Related text
High similarity
Somewhat related
Medium similarity
Unrelated text
Low similarity

The exact score range and interpretation depend on the metric, implementation, and vectors being compared. Do not use an arbitrary score threshold without evaluation.

8

Python: Represent a Vector

Python lists or NumPy arrays are convenient ways to work with vectors in small experiments.

PythonSimple vector
import numpy as np

vector = np.array([
    0.21,
    -0.48,
    0.73,
    0.15,
    -0.09,
])

print("Dimensions:", vector.shape[0])
print("Vector:", vector)
9

Python: Calculate Vector Magnitude

The Euclidean norm gives the length, or magnitude, of a vector.

PythonVector magnitude
import numpy as np

vector = np.array([0.21, -0.48, 0.73])

magnitude = np.linalg.norm(vector)

print("Magnitude:", magnitude)
Remember: Magnitude is a property of the whole vector. It is not the value of one individual dimension.
10

Python: Compare Two Vectors

Here is a compact example of cosine similarity using NumPy.

PythonCosine similarity
import numpy as np

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

a = np.array([0.8, 0.2, 0.1])
b = np.array([0.7, 0.3, 0.1])

score = cosine_similarity(a, b)

print("Similarity:", score)

In a real embedding application, a and b would usually come from an embedding model rather than being manually written numbers.

11

Other Ways to Compare Vectors

Cosine similarity is not the only option. Different applications can use different distance or similarity measures.

Cosine similarityFocuses on vector direction.
Euclidean distanceMeasures straight-line distance.
Dot productCombines alignment and magnitude.
Manhattan distanceSums absolute coordinate differences.
Engineering rule: Use the metric expected by your embedding/search system and validate it with real retrieval or ranking tests.
12

Vector Representation in RAG

Retrieval-Augmented Generation uses vector representations to help find relevant information before the language model generates an answer.

01DocumentsSplit into chunks
→
02EmbeddingsConvert chunks to vectors
→
03Vector SearchFind similar chunks
→
04LLMGenerate answer

The vector representation is therefore one part of a larger retrieval pipeline. Good retrieval still depends on chunking, metadata, indexing, query formulation, ranking, and evaluation.

13

Vector Representation Beyond Search

01Semantic Search

Find content based on meaning.

02Recommendations

Find products or content with similar representations.

03Clustering

Group data points with similar representations.

04Classification

Use vector features as inputs to downstream models.

05Duplicate Detection

Identify content with highly similar representations.

06RAG

Retrieve relevant knowledge for an LLM.

14

Common Misconceptions

“Each dimension has one clear meaning.”

Usually, learned representations distribute information across many dimensions.

“Closer always means better.”

Distance only becomes useful relative to the model, metric, data, and task.

“A vector stores the original text.”

An embedding is a numerical representation; it is not a reversible copy of the original text.

“Higher similarity guarantees correctness.”

A retrieval score is not the same thing as factual correctness.

HANDS-ON PRACTICE

Visualize a Tiny Vector Space

Use three-dimensional toy vectors to understand how distance and direction change.

  1. Create three vectors representing three fictional documents.
  2. Calculate the magnitude of each vector.
  3. Calculate cosine similarity between every pair.
  4. Identify which pair is most similar.
  5. Change one coordinate and observe how the scores change.
Challenge: Create five short FAQ questions, convert them into embeddings, and compare the query against all five. Record the top three results.
QUICK QUIZ

Test Your Understanding

1. What is a vector?

An ordered collection of numerical values that can represent an object or learned features.

2. What does the number of dimensions tell you?

How many numerical coordinates are present in the vector.

3. Why can related text have nearby vectors?

The embedding model can encode useful relationships so related items occupy nearby regions under an appropriate similarity measure.

4. Does vector similarity prove that two texts have the same meaning?

No. Similarity is a useful signal, but it must be evaluated for the actual application.

30-SECOND RECAP

Vector Representation in One Flow

InformationText, image, product...
→
VectorNumerical coordinates
→
ComparisonSimilarity or distance
→
ApplicationSearch, RAG, recommendations

Key Takeaways

  • A vector is an ordered collection of numbers representing an item in a mathematical space.
  • Dimensions are coordinates of the complete representation, not necessarily human-readable concepts.
  • Similarity measures let applications compare vector representations.
  • Cosine similarity focuses on direction, while other metrics measure different geometric relationships.
  • Vector representations power semantic search, recommendations, clustering, duplicate detection, and RAG.
  • Always evaluate vector retrieval using real examples from your application.