NumPy allowed · plain Python earns 10 bonus points
Cosine-like similarity scores ranked before context assembly
Implement pre-filtered ANN search: real vector search almost always needs to combine similarity ranking with a metadata constraint (e.g. 'only in-stock items').
Implement filtered_topk(query, items, k, category). items is a list of {"id": str, "vector": list[float], "category": str} dicts. First filter to items whose category matches exactly, then rank the survivors by cosine similarity to query descending, and return the top-k ids. Ties broken by id ascending. If fewer than k items survive the filter, return all of them.
filtered_topk(query: list[float], items: list[dict], k: int, category: str) -> list[str]