Command Palette

Search for a command to run...

Hectal
Phase 1: Search Before Vectors
RAG and Vector Search · Exercise 4 of 5 PreviousNext
Intermediate

Find passages that contain a phrase

docs is a dict of passage id to text, and tokenize(text) is given.

Write phrase_docs(docs, phrase) returning the list of passage ids (in the order of docs) in which the words of phrase appear next to each other, in order. phrase is a string such as "ride credit"; tokenise it too. An empty phrase matches nothing.

What Check tests

  1. Adjacent words in order match
  2. Both words present but not adjacent do not match
  3. Case and punctuation are ignored
  4. A single word works
  5. An empty phrase matches nothing

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.