Retrieve scoped and fresh memories
Implement retrieve_memory(records, query_tags, scope, now, max_age, k). Records contain unique string IDs, scope, nonnegative integer time, and a list of tags. Return up to k eligible IDs ranked by 2*overlap + 1/(1+age), breaking ties by ID. Overlap counts distinct shared tags. Exclude wrong scope, future timestamps, expired records, and zero-overlap records before ranking. Validate nonnegative exact integer time controls and k, and reject duplicate IDs. Inputs are trusted well-shaped records except for those explicitly validated conditions.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
InputRecords A(time=10,tags=[p]), B(time=18,tags=[p]), now=20, scope=u, max_age=20, k=2
Output["B","A"]
InputThe same records with max_age=1
Output[]
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor