Test the Search

Run the full extract-chunk-embed-search pipeline and print results

💻

Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.

Putting it together for the first time

test_search calls every function you have written so far in sequence. It is not part of the final app — it is a sanity check to confirm that search returns meaningful results before you add generation.

Running this locally against a real PDF and a real question is the first time the pipeline feels like magic.

Instructions

Complete the test_search function. The starter code provides the signature.

  1. Create a variable named text. Assign it extract_text(pdf_path).
  2. Create a variable named chunks. Assign it chunk_text(text).
  3. Create a variable named embeddings. Assign it embed_all_chunks(client, chunks).
  4. Create a variable named results. Assign it search(client, question, chunks, embeddings).
  5. Use a for loop with variable i and chunk over enumerate(results, 1). Inside the loop, print f"Result {i}:\n{chunk}\n".