Once past trajectories are stored (see Store Successful and Failed Agent Trajectories), the next real question is finding the ones actually relevant to a new task. Unlike semantic retrieval over free text (see Cosine-Similarity Top-K Retrieval From Scratch), trajectories here are described by a small set of tags — "booking," "flight," "customer-support" — and similarity is just how many of those tags a stored trajectory shares with the new task, a simple integer overlap count rather than a continuous vector similarity.
You're given query_tags (describing the new task) and every stored trajectory's (trajectory_id, tags). Implement find_similar_trajectories(query_tags, trajectories). Rank stored trajectories by how many tags they share with query_tags. Return all trajectory ids, sorted by overlap count descending, ties broken by ascending id.
Set intersection (query_tags & tags) directly gives you the shared tags; len(...) of that turns it into the overlap count this whole ranking is based on.
Sort by the tuple key (-overlap_count, trajectory_id) — the same "negate for descending, then break ties on id" pattern used for score-based rankings elsewhere in this curriculum.
No results yet
Run your code to check it against the examples, or submit to run every test.