Long-Term Knowledge Storage and Retrieval › Practical Considerations

Michael BrenndoerferJuly 3, 20252 min read
AI Agent HandbookAll chapters
Part 6 of 15Memory and Retrieval - How Agents Remember
Chapter 16Long-Term Knowledge Storage and Retrieval › Practical Considerations
Reading section 8 of 13 · Practical Considerations · 2 minSection 8 of 13 · 2 min

Book contents

Section 8 of 13 · 2 min read

Long-Term Knowledge Storage and Retrieval › Practical ConsiderationsOne section · Sections in this chapter8 / 13 ↓
Reading tools Definitions & inline links

Toggle tooltip visibility. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

As you build long-term memory into your assistant, keep these points in mind:

Storage limits: Vector databases can grow large. Consider setting limits on how many facts to store, or implementing a way to archive or remove old information.

Privacy: Long-term memory means persistent data. Be thoughtful about what you store and how you protect it. Never store sensitive information like passwords or financial details without proper encryption.

Retrieval quality: The quality of your retrieval depends on your embedding model. Better embeddings lead to better semantic search. The example above uses a small, fast model, but you might want a more powerful one for production use.

Context window limits: Even with long-term memory, you can only include so many retrieved facts in each request to the language model. Prioritize the most relevant information.

Updating facts: What happens when information changes? You might need a way to update or delete facts. For example, if the user moves to a new city, you want to update that fact rather than having two conflicting locations stored.

Here's a simple update mechanism:

In[2]:
Code
def update_fact(self, old_fact, new_fact):
    """Replace an old fact with updated information"""
    # Remove old fact
    if old_fact in self.memory.facts:
        idx = self.memory.facts.index(old_fact)
        self.memory.facts.pop(idx)
        self.memory.vectors.pop(idx)

    # Add new fact
    self.memory.add_fact(new_fact)
    return f"Updated: {new_fact}"