AskDocs v2: embed the handbook, retrieve by meaning
The embedder is a toy with a word table written for these questions. The structure (an Embedder interface, vectors built once, retrieve with the same shape) is what carries over to a real model.
AskDocs version 2: an Embedder interface that the rest of the product depends on, a toy embedder behind it, vectors for the whole handbook, retrieval by cosine, and a cache keyed by content and model so nothing is embedded twice.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write retrieve(question, k, min_score) over a dict VECTORS of id to unit vector, with a function embed(text) given. Return (id, score) pairs best first. Use the tiny two-direction table in the answer and print the result for the question 'password help'.
Write content_key(model_name, text) that returns model_name + ":" + sha256 hex of text and print the first 12 characters of the hash for 'Helmets' and for 'helmets'. What does it tell you about cache keys?
Explain it without notes
Why does AskDocs hide the embedding step behind an Embedder interface?
What does the cache key consist of, and why each part?
What changed in retrieve between version 0 and version 2, and what stayed the same?
In the trace, why does the pass-price question retrieve three sources? Is that a problem?
Expected output
embedded 12 passages, 8 numbers each, 12 calls
Q: What does the monthly pass cost?
sources: D8 (0.97), D12 (0.71), D6 (0.71)
answer: The monthly pass costs 25 dollars and includes unlimited rides of up to 45 minutes. [D8]
Q: I forgot my login, how do I get back in?
sources: D3 (0.87), D5 (0.52)
answer: To reset your password, open the app, tap Forgot password and follow the link we email you. The link works for 30 minutes. [D3]
Q: Can I get my money back if I cancel?
sources: D1 (0.97)
answer: A ride cancelled at least 2 hours before its start time is refunded in full. Later cancellations get ride credit instead. [D1]
Q: How long are lost things kept?
sources: D9 (1.00)
answer: Items left on a bike are kept at the nearest shop for 14 days. [D9]
Q: Do you rent scooters?
sources: none
answer: I can't find that in the handbook.
embedder calls in total: 17