I am developing a personal assistant and need it to remember user preferences over several months. I'm considering using as the "long-term memory" vault. How do I handle the logic of summarizing old conversations and updating existing vectors without creating thousands of redundant entries every time the user speaks?
3 answers
Building a "memory" with involves a strategy called "Selective Persistence." Instead of saving every single line of dialogue, you should use a secondary LLM call to summarize the key facts from a session and then store only that summary as an embedding. When the user returns, you can query the collection for the top 5 most relevant historical summaries and inject them into the system prompt. To prevent redundancy, use the 'upsert' method provided by the SDK. This allows you to update an existing record (identified by a unique UserID) instead of adding a new one, keeping your vector space clean and relevant.
How do you handle the "forgetting" aspect if a user's preferences change over time?
The 'context_variables' approach is definitely the cleanest way to manage this in a live loop.
Agree. It keeps the prompt size down while ensuring the retrieval stays focused on what actually matters for the current interaction.
That's where metadata timestamps come in handy. You can use the library's filtering capabilities to prioritize recent vectors or even run a cleanup script that deletes entries older than six months. By combining the vector similarity score with a "recency score" in your application logic, you ensure the agent remembers the most important current facts while letting old, irrelevant information fade into the background.