A long-lived agent accumulates thousands of memories, far too many to show the model. The influential Generative Agents work retrieves them with a score built from three signals. Recency: recently used memories are more likely to matter, modelled by exponential decay with time since last access. Importance: the agent rates how significant an event was (breakfast is a 1, a breakup is a 9), so that rare but vital memories survive. Relevance: the cosine similarity between the memory's embedding and the current query. A weighted sum of the three ranks the memories, and the top few go into the prompt.
Implement memory_scores and top_memories.
embedding (list of floats), importance (a number from 1 to 10) and last_access (a time in hours). query is an embedding list, now the current time in hours.recency = decay ** (now - last_access), importance_score = importance / 10, relevance = cosine(query, embedding) (0.0 if either vector has zero length). memory_scores(memories, query, now, decay, weights) returns the list of w_r * recency + w_i * importance_score + w_s * relevance, where weights = (w_r, w_i, w_s).top_memories(memories, query, now, k, decay, weights) returns the indices of the k highest-scoring memories, best first, ties broken by lower index.Write a small cosine helper using math.sqrt.
Decay below 1 makes older memories score lower: with decay = 0.99 per hour a day-old memory keeps about 79%.
No results yet
Run your code to check it against the examples, or submit to run every test.