Module 1: Introduction to Vectors
7. Capstone Exercise: Mapping Concepts to Vectors
Exercise overview
This is the capstone exercise for Module 1. Here you're going to apply everything you learned: representing concepts as 2D vectors (simplified so you can visualize them), computing operations (addition, subtraction, magnitude), measuring distances, and verifying that "geometric closeness = semantic similarity".
This exercise is 100% conceptual: there's no code to write. You'll work with pencil and paper (or mentally), drawing vectors, computing simple operations, and reflecting on how geometry captures meaning. The goal is for you to internalize the intuition that nearby vectors = similar concepts.
When you finish, you'll have closed the module's conceptual loop: you know what a vector is (Capsule 02), how to visualize it (Capsule 03), how it works in high dimensions (Capsule 04), how to operate on it (Capsule 05), why it's used in AI (Capsule 06), and now you apply it by hand. This intuition is the foundation of Modules 2-8 and of everything ahead of you on your path as an AI Engineer.
Exercise context
Imagine you're designing a semantic search system for a library of concepts. Each concept (word) is represented as a 2D vector (simplified; in reality it would be 1536D). Your task is to:
- Assign coordinates to 8 concepts
- Draw the vectors on a Cartesian plane
- Compute operations (addition, subtraction, distance)
- Verify that nearby vectors = similar concepts
- Simulate a semantic search
Important: This exercise uses 2D for simplicity. In reality, embeddings are 1536D, but the intuition is exactly the same.
Part 1: Assigning vectors to concepts
Concepts to map:
- dog
- cat
- tiger
- car
- bicycle
- airplane
- apple
- orange
The axes of the 2D space:
To keep it simple, we use 2 conceptual axes:
-
X axis (horizontal): "Animalness" → "Mechanicalness"
- Negative X → Animals / living beings
- Positive X → Machines / objects
-
Y axis (vertical): "Domesticity" → "Speed"
- Positive Y → Domestic / slow
- Negative Y → Wild / fast
Note: These axes are arbitrary simplifications used for illustration. In real embeddings (1536D), the axes are learned by the model and don't have clear labels.
Task 1.1: Assign coordinates
For each concept, estimate coordinates [x, y] based on:
- X: How "animal" vs "machine" it is
- Y: How "domestic" vs "fast" it is
Value guide:
- X:
-10(very animal) →0(neutral) →+10(very machine) - Y:
-10(very wild/fast) →0(neutral) →+10(very domestic/slow)
Example (worked out):
1. dog = [-8, 7] (domestic animal)
2. cat = [-7, 6] (domestic animal, slightly less so than dog)
3. tiger = [-9, -5] (wild animal, fast)
4. car = [6, -3] (machine, fast)
5. bicycle = [5, 4] (machine, slow, everyday)
6. airplane = [8, -7] (machine, very fast)
7. apple = [0, 8] (neutral animal-machine, everyday/slow object)
8. orange = [1, 8] (neutral animal-machine, everyday/slow object)
Note: These coordinates are arbitrary (chosen for illustration). In real embeddings, the model learns optimal coordinates automatically. What matters is that similar concepts have nearby coordinates.
Task 1.2: Draw the vectors
Draw a Cartesian plane on paper and mark the 8 points:
Y ↑ (Domestic/Slow)
10|
|
8 | •apple •orange
|
6 | •cat
|
4 | •bicycle •dog
|
2 |
|
0 |───────────────────────→ X (Animalness → Mechanicalness)
-2 | •car
|
-4 |
|
-6 | •tiger
|
-8 | •airplane
|
-10 |
-10 -5 0 5 10
Expected observations:
- Cluster 1 (Domestic animals): "dog" and "cat" close together (upper-left quadrant)
- Cluster 2 (Vehicles): "car", "bicycle", "airplane" on the right (positive X)
- Cluster 3 (Fruits): "apple" and "orange" very close together (top, center)
- Isolated: "tiger" far from the domestic ones (a wild animal)
Reflection questions:
- Did the similar concepts end up close together on the plane?
- Did the different concepts end up far apart?
See reflection guide
Expected answer: Yes.
- "dog" and "cat" are close together (both domestic animals)
- "apple" and "orange" are very close together (both fruits, nearly identical coordinates)
- "car", "bicycle", "airplane" are in the same region (all vehicles/machines)
- "tiger" is far from "dog" and "cat" (wild vs domestic)
- "airplane" is far from "bicycle" (very fast vs slow)
Conclusion: The geometry (closeness on the plane) reflects the semantics (similarity of concepts). This is what real embeddings do in 1536D.
Part 2: Computing distances
Task 2.1: Euclidean distance
Compute the Euclidean distance between pairs of vectors:
Formula:
distance([x₁, y₁], [x₂, y₂]) = √((x₂ - x₁)² + (y₂ - y₁)²)
Pairs to compute:
a) distance(dog, cat)
b) distance(dog, tiger)
c) distance(car, bicycle)
d) distance(apple, orange)
e) distance(dog, car)
See solutions
a) distance(dog, cat):
dog = [-8, 7]
cat = [-7, 6]
distance = √((-7 - (-8))² + (6 - 7)²)
= √(1² + (-1)²)
= √(1 + 1)
= √2 ≈ 1.41
Interpretation: Very close (small distance) → similar concepts ✅
b) distance(dog, tiger):
dog = [-8, 7]
tiger = [-9, -5]
distance = √((-9 - (-8))² + (-5 - 7)²)
= √((-1)² + (-12)²)
= √(1 + 144)
= √145 ≈ 12.04
Interpretation: Far apart (large distance) → different concepts (domestic vs wild) ✅
c) distance(car, bicycle):
car = [6, -3]
bicycle = [5, 4]
distance = √((5 - 6)² + (4 - (-3))²)
= √((-1)² + 7²)
= √(1 + 49)
= √50 ≈ 7.07
Interpretation: Moderately close (both vehicles, but one fast and one slow) → related but not identical concepts ✅
d) distance(apple, orange):
apple = [0, 8]
orange = [1, 8]
distance = √((1 - 0)² + (8 - 8)²)
= √(1² + 0²)
= √1 = 1
Interpretation: Very close (nearly identical) → very similar concepts (both fruits) ✅
e) distance(dog, car):
dog = [-8, 7]
car = [6, -3]
distance = √((6 - (-8))² + (-3 - 7)²)
= √(14² + (-10)²)
= √(196 + 100)
= √296 ≈ 17.20
Interpretation: Very far apart (large distance) → completely different concepts (animal vs machine) ✅
Task 2.2: Rank by similarity
Given the concept "dog", order the other concepts from closest to farthest (use the distances you computed and estimate the missing ones):
List to order: cat, tiger, car, bicycle, airplane, apple, orange
See solution
Ranking (closest → farthest from "dog"):
- cat (distance ≈ 1.41) — Very similar (domestic animal)
- apple (distance ≈ 8.06) — Moderately far (neither animal nor machine, but an everyday object)
- orange (distance ≈ 9.06) — Moderately far (similar to apple)
- tiger (distance ≈ 12.04) — Far (wild animal)
- bicycle (distance ≈ 13.34) — Far (machine)
- car (distance ≈ 17.20) — Very far (fast machine)
- airplane (distance ≈ 21.26) — Very far (very fast machine)
Observation: The ranking reflects conceptual similarity: "cat" (most similar) comes first; "airplane" (very different) comes last. This is semantic search: ranking by vector distance.
Part 3: Vector operations
Task 3.1: Vector addition
Compute:
a) dog + cat
b) What concept would you expect to be near that result?
See solution
a) dog + cat:
dog = [-8, 7]
cat = [-7, 6]
dog + cat = [-8 + (-7), 7 + 6] = [-15, 13]
b) Interpretation:
The vector [-15, 13] is in the "very animal, very domestic" region (the far end of the upper-left quadrant).
Expected nearby concept: A "super domestic animal" or a "generic pet". If we had the concept "pet" in our space, its vector would be near [-15, 13].
Why it works: Adding "dog" and "cat" combines their characteristics (both domestic animals) → the result emphasizes those shared characteristics.
Task 3.2: Vector subtraction
Compute:
a) car - bicycle
b) What conceptual "direction" does that subtraction capture?
See solution
a) car - bicycle:
car = [6, -3]
bicycle = [5, 4]
car - bicycle = [6 - 5, -3 - 4] = [1, -7]
b) Interpretation:
The vector [1, -7] points toward "faster" (negative Y).
The direction captured: "Speed" or "quickness". The main difference between "car" and "bicycle" is speed (a car is faster).
Application (conceptual): If you computed:
airplane + (car - bicycle) = airplane + [1, -7]
= [8, -7] + [1, -7]
= [9, -14]
You'd expect to get a vector close to a "very fast vehicle" (e.g. "rocket", "jet").
This is analogous to: king - man + woman = queen in real embeddings. The subtraction captures a "direction" (speed, gender, etc.) that you can apply to other vectors.
Task 3.3: Scaling
Compute:
a) 2 × apple
b) What does it mean geometrically? Does the concept change?
See solution
a) 2 × apple:
apple = [0, 8]
2 × apple = [2 × 0, 2 × 8] = [0, 16]
b) Geometric interpretation:
The vector [0, 16] points in the same direction as [0, 8] (due north, the positive Y axis), but with double the magnitude.
Does the concept change?
In real embeddings, no. Direction is what matters (what kind of concept it is); magnitude is usually normalized (all vectors are scaled to magnitude 1). So [0, 8] and [0, 16] would represent the same concept ("apple") once normalized.
When magnitude does matter: In some contexts (e.g. TF-IDF), magnitude can represent "frequency" or "importance". In modern embeddings (OpenAI, BERT), magnitude is normalized and only direction matters.
Part 4: Simulating semantic search
Task 4.1: Semantic search
Context: You have a "database" with 8 documents (the 8 concepts from the exercise), each represented by its vector.
The user's query: "domestic animal"
Step 1: Assign a vector to the query "domestic animal"
Guide: The query "domestic animal" should have coordinates close to the "dog" and "cat" cluster.
Proposal: query = [-7.5, 6.5] (roughly the average of dog and cat)
Step 2: Compute the distance from the query to each document:
Use the Euclidean distance formula:
distance(query, doc) = √((doc_x - query_x)² + (doc_y - query_y)²)
Documents:
- dog = [-8, 7]
- cat = [-7, 6]
- tiger = [-9, -5]
- car = [6, -3]
- bicycle = [5, 4]
- airplane = [8, -7]
- apple = [0, 8]
- orange = [1, 8]
See solution
Calculations (approximate):
query = [-7.5, 6.5]
distance(query, dog) = √((-8 - (-7.5))² + (7 - 6.5)²) = √(0.25 + 0.25) = √0.5 ≈ 0.71
distance(query, cat) = √((-7 - (-7.5))² + (6 - 6.5)²) = √(0.25 + 0.25) = √0.5 ≈ 0.71
distance(query, tiger) = √((-9 - (-7.5))² + (-5 - 6.5)²) = √(2.25 + 132.25) ≈ 11.60
distance(query, car) = √((6 - (-7.5))² + (-3 - 6.5)²) = √(182.25 + 90.25) ≈ 16.51
distance(query, bicycle) = √((5 - (-7.5))² + (4 - 6.5)²) = √(156.25 + 6.25) ≈ 12.75
distance(query, airplane) = √((8 - (-7.5))² + (-7 - 6.5)²) = √(240.25 + 182.25) ≈ 20.56
distance(query, apple) = √((0 - (-7.5))² + (8 - 6.5)²) = √(56.25 + 2.25) ≈ 7.65
distance(query, orange) = √((1 - (-7.5))² + (8 - 6.5)²) = √(72.25 + 2.25) ≈ 8.63
Ranking (smaller distance → greater similarity):
- dog (0.71) ✅
- cat (0.71) ✅
- apple (7.65)
- orange (8.63)
- tiger (11.60)
- bicycle (12.75)
- car (16.51)
- airplane (20.56)
Result: The system returns "dog" and "cat" as the most relevant documents for the query "domestic animal".
Observation: Even though the query does NOT contain the exact words "dog" or "cat", the system finds them because their vectors are close to the query's vector. This is semantic search: searching for meaning, not just exact words.
Task 4.2: Contrast with keyword search
Question: If you used keyword search (exact word matching), which documents would you return for the query "domestic animal"?
See solution
Answer: None.
Justification: The documents are:
- "dog" (contains neither "animal" nor "domestic")
- "cat" (contains neither "animal" nor "domestic")
- "tiger" (contains neither "animal" nor "domestic")
- etc.
Keyword search returns 0 results because no document contains the exact words "animal" or "domestic".
Semantic search returns "dog" and "cat" because their vectors capture the meaning of "domestic animal", even though they don't use those exact words.
Conclusion: Semantic search is superior for conceptual searches (meaning); keyword search only works for exact matches.
Part 5: Reflection and the connection to RAG
Task 5.1: How would this scale to 1536D?
Question: In this exercise you used 2D (2 axes). In reality, embeddings are 1536D. What changes and what stays the same?
See reflection guide
What stays the same:
- The concept of a vector: It's still a point in space with coordinates
- Distance: It's computed the same way (the sum of squared differences on each axis)
- Operations: Addition, subtraction, scaling work the same (axis by axis)
- Semantic search: Searching for nearby vectors is still the strategy
- The intuition: Nearby vectors = similar concepts
What changes:
- The number of axes: 2 → 1536 (768 times more axes)
- Visualization: You can't draw 1536D (only 2D projections with t-SNE/UMAP)
- Capacity: 1536 axes capture far more nuance than 2 axes (more "aspects" of meaning)
- Computation: More coordinates to process (but the tools do it automatically)
Conclusion: The intuition you gained in 2D applies directly to 1536D. The operations are the same; there are just more dimensions. Don't lose sight of the intuition: geometric closeness = semantic similarity, whether it's 2D or 1536D.
Task 5.2: The connection to RAG
Question: How is what you did in Task 4.1 (semantic search) used in RAG?
See reflection guide
The RAG flow (Retrieval-Augmented Generation):
1. Retrieval (what you did in Task 4.1):
- The user asks a question: "Which animals are pets?"
- Query → embedding (a 1536D vector)
- Search for documents with nearby embeddings (semantic search)
- Return the top-K most relevant documents (e.g. top-5)
In your exercise: You found "dog" and "cat" as the closest to "domestic animal".
2. Augmented (augmenting the context):
- Take the retrieved documents ("dog", "cat") and pass them to the LLM along with the query
Example:
Context (from semantic search):
- Doc 1: "The dog is a very loyal domestic animal"
- Doc 2: "The cat is an independent domestic animal"
Query: "Which animals are pets?"
3. Generation (generating the answer):
- The LLM (GPT-4, Claude) reads the context + the query
- It generates an answer based on the documents:
"The animals that are pets include dogs and cats.
Dogs are known for their loyalty, while cats
tend to be more independent."
Conclusion: What you did in Task 4.1 (searching for nearby vectors) is the Retrieval step in RAG. That step is critical: if you don't find relevant documents, the LLM can't generate an accurate answer. Semantic search with vectors is the heart of RAG.
Part 6: Self-assessment
Final reflection questions:
Answer each one in 1-2 sentences (for yourself; there are no single "correct" answers):
-
Why represent concepts as vectors instead of as strings?
-
What does it mean geometrically for two vectors to be "close"?
-
How does the operation
king - man + woman ≈ queenwork conceptually? -
How does semantic search differ from keyword search?
-
Why do real embeddings use 1536D instead of 2D or 3D?
See reflection guides
1. Why vectors instead of strings?
Because vectors allow mathematical operations (distance, addition, subtraction) that capture meaning. Strings can't be compared quantitatively or operated on; vectors can.
2. What does "nearby vectors" mean?
That they have similar coordinates on most axes → they're close together in the space → they capture similar concepts. Small distance = high similarity.
3. How does king - man + woman ≈ queen work?
The subtraction king - man captures the "gender direction" (removing the "man" component from "king"). Adding woman applies that direction in the feminine sense. The result is a vector close to "queen" (feminine royalty).
4. Semantic search vs keyword search:
Keyword search looks for exact word matches. Semantic search looks for meaning (nearby vectors), finding synonyms and related concepts even when they don't use the same words.
5. Why 1536D instead of 2D/3D?
Because 1536 axes can capture 1536 aspects of meaning (animalness, size, speed, emotion, etc.), distinguishing subtly different concepts. 2D/3D only capture 2-3 aspects → many concepts overlap.
Exercise summary
What you did:
- ✅ You assigned 2D coordinates to 8 concepts (simulating embeddings)
- ✅ You drew vectors and verified that similar concepts ended up close together
- ✅ You computed Euclidean distances (measuring similarity)
- ✅ You applied operations (addition, subtraction, scaling)
- ✅ You simulated semantic search (searching for vectors near a query)
- ✅ You compared semantic search vs keyword search
- ✅ You reflected on how this scales to 1536D and how it's used in RAG
The key intuition, consolidated:
Nearby vectors = similar concepts. All the magic of semantic search, RAG and embeddings comes down to that geometric intuition. Now that you've lived it by hand in 2D, you understand what happens "under the hood" when you use OpenAI embeddings or Pinecone in 1536D.
Connection to Module 2
In Module 2 (Vector Spaces), you'll extend this intuition:
- Vector space: The "container" where all the vectors live (2D, 1536D, etc.)
- Bases and dimensions: How the axes structure the space
- Subspaces: Regions of the space with special properties (e.g. all the animals)
- Projections: How to reduce 1536D to 2D (t-SNE, UMAP)
- Normalization: Why you make all vectors have magnitude 1
In Module 3, you'll see formal similarity metrics (Euclidean distance, cosine) and when to use each. What you computed by hand in this exercise (Euclidean distance) is one of those metrics.
In Module 4, you'll apply semantic search in real contexts (RAG, document search).
Everything builds on the intuition you consolidated here: vectors in a space, geometric closeness = semantic similarity.
Deliverable (optional)
If you want to consolidate the learning further, save your work:
- A diagram with the 8 vectors drawn (a photo or a digital drawing)
- The distance calculations (on paper or in a document)
- The semantic search ranking (an ordered list)
- Written reflections (your answers to the 5 self-assessment questions)
It isn't mandatory, but doing it on paper and keeping it will help you remember the intuition when you see embedding code or diagrams in the future.
Extension exercise (optional)
If you want to go deeper:
Extension 1: Add more concepts
Add 3 new concepts to your 2D space:
- "lion"
- "boat"
- "banana"
Assign coordinates, draw them, and verify that they land in the expected regions (lion near tiger, boat near the vehicles, banana near the fruits).
Extension 2: Compute cosine similarity
Instead of Euclidean distance, compute the cosine similarity between "dog" and "cat".
Formula (simplified):
cosine(A, B) = (A · B) / (||A|| × ||B||)
Where:
A · B= the dot product =a_x × b_x + a_y × b_y||A||= the magnitude of A =√(a_x² + a_y²)
Compute it:
dog = [-8, 7]
cat = [-7, 6]
Dot product: (-8) × (-7) + 7 × 6 = 56 + 42 = 98
||dog|| = √(64 + 49) = √113 ≈ 10.63
||cat|| = √(49 + 36) = √85 ≈ 9.22
cosine = 98 / (10.63 × 9.22) ≈ 98 / 98.01 ≈ 1.00
Interpretation: A cosine of 1 means "perfectly similar in direction" (a 0° angle). "dog" and "cat" point in nearly identical directions.
You'll see cosine in detail in Module 3.
Extension 3: Simulate a second query
Query: "fast vehicle"
Assign a vector to the query (e.g. [7, -5] — a fast machine), compute the distances, and verify that "car" and "airplane" appear at the top of the ranking.
Additional resources
-
Google Colab: "Visualizing Word Embeddings" — An interactive notebook where you can play with real embeddings and visualize them in 2D with t-SNE. In English.
-
Embedding Projector (TensorFlow) — A web tool for visualizing interactive 3D embeddings. You can rotate, zoom, and search for words. In English.
-
Jay Alammar: "The Illustrated Word2vec" — A blog with diagrams on embedding operations. It complements this exercise with visualizations. In English.
-
Pinecone: "Semantic Search Tutorial" — A hands-on tutorial on how to implement semantic search with embeddings. For after you complete the guide. In English.
-
OpenAI Embeddings Playground — Documentation with code examples for generating embeddings and doing semantic search. In English.
-
3Blue1Brown: "Dot products and duality" — A 14-minute video on the dot product (the basis of cosine). Excellent visualizations. In English.
Module 1 conclusion
Congratulations on completing Module 1: Introduction to Vectors. 🎉
What you achieved:
- ✅ You understand what a vector is (direction + magnitude)
- ✅ You can visualize vectors in 2D and 3D
- ✅ You understand that high-dimensional vectors (1536D) work the same way
- ✅ You know how to operate on vectors (addition, subtraction, scaling)
- ✅ You understand why AI uses vectors (the distributional hypothesis, semantic search)
- ✅ You applied all of it by hand (the capstone exercise)
The module's key intuition:
Vectors let you represent meaning geometrically. Similar words/concepts → nearby vectors. Semantic search = searching for nearby vectors.
Next step: Module 2 (Vector Spaces) — You'll see how vectors "live" in spaces with structure (bases, dimensions, subspaces), how to project high dimensions to 2D/3D, and how the geometry of the space affects operations and search.
Everything you learned here is the foundation. In Module 2 you go deeper into the geometry; in Module 3 you formalize similarity (cosine, distance); in Module 4 you apply semantic search; in Modules 5-8 you connect it to RAG and AI Engineering.
Keep going! The intuition you consolidated here is 80% of the conceptual understanding of semantic search and RAG. The rest is applying these ideas to more complex contexts.
End of Module 1! 🚀