Command Palette

Search for a command to run...

Hectal
Phase 11: RAG in Production
RAG and Vector Search · Exercise 4 of 5 PreviousNext
Intermediate

Merge results from shards

Write scatter_gather(shards, score, k). shards is a list of lists of document ids, and score(doc_id) returns a number. From each shard take its best k documents, then merge them and return the best k document ids overall.

Order by score from highest to lowest, with ties broken by document id (ascending).

What Check tests

  1. Returns the global best three
  2. Fewer documents than k
  3. Ties are broken by id
  4. Takes k from every shard
  5. Empty shards are fine

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.