We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Chunked Semantic Search

Let's implement search using the embeddings we generated for document chunks. We'll search across all chunks to find the most relevant sections, then aggregate results back to the document level.

In this lesson, we'll focus on:

  1. Searching across chunks using cosine similarity with query embeddings
  2. Aggregating chunk scores to determine the most relevant documents
  3. Returning formatted results that map chunks back to their original movies

By searching at the chunk level, we can find relevant information even when it's buried deep within a long document, like a book or technical manual.

Assignment

Implement search functionality that queries chunk embeddings and aggregates results.

        • chunk_idx: The index of the chunk within the document
        • movie_idx: The index of the document in self.documents (you'll need to use self.chunk_metadata to map back to this)
        • score: The cosine similarity score
    1. {
          "id": doc_id,
          "title": title,
          "document": document[:100],
          "score": round(score, SCORE_PRECISION),
          "metadata": metadata or {},
      }
      
    1. print(f"\n{i}. {TITLE} (score: {SCORE:.4f})")
      print(f"   {DOCUMENT}...")
      

Run and submit the CLI tests.