6 Working with memory and knowledge RAG for agents
This chapter covers
- Understanding retrieval in AI applications
- Vector databases and similarity search
- Building practical knowledge RAG agents
- Adding memory to agents with MCP
Now that we’ve explored how reasoning and planning can create smarter agents, we will look at how retrieval and context augmentation can be used to support knowledge and memory in agents. We start with a look at the basis for retrieval and how we can search by semantic meaning using dense vector embeddings. Then we will look at the practical side of using retrieval to build knowledge agents, agents that have access to external resources to help answer questions. Finally, we will employ retrieval to find relevant previous experiences in the form of memory that will be used to help augment agent context.
6.1 Understanding retrieval in AI applications
Retrieval in agent and chat applications is a mechanism for obtaining knowledge/memories stored in an external, long-lived storage system. Unstructured knowledge includes conversation or task histories, facts, preferences, or other items necessary for contextualizing a prompt. Structured knowledge, normally stored in databases or files, is accessed through native functions or plugins. Memories may consist of the previous conversation thread, previous agent experiences, previous facts or preferences about the user, or other experiential information.