RAG for Everyone

← Back to quiz

Chapter 12 Exercises55 min hands-on

Exercises: Compare Tiny Vectors

Use starter.py to implement cosine similarity and rank candidate chunks.

1 Implement cosine similarity

Compute dot product, vector length, and normalized similarity.

2 Rank candidate chunks

Sort chunks by similarity to the query vector.

3 Add a production warning

Flag when similarity is high but metadata says a chunk is stale.

4 Explain the result

Return a human-readable retrieval note.

← Back to QuizPractice Bank →