8 Understanding agent memory and knowledge
This chapter explores how retrieval underpins agent memory and knowledge, showing how both are used to augment prompts with relevant context. It distinguishes knowledge (document-derived context) from memory (agent- or user-derived facts and history) while unifying them under the Retrieval Augmented Generation pattern. The core flow—load, split, embed, store, and retrieve—enables agents to ground answers in external, long‑lived stores, making semantic search and prompt engineering central to reliable, contextualized reasoning.
Building from first principles, the text moves from classic TF‑IDF and cosine similarity to modern embedding-based semantic search, storage in vector databases, and practical querying. It demonstrates how document indexing choices affect retrieval quality, emphasizing chunking strategies (size and overlap), token-based splitting, and the trade‑offs between sending whole documents to an LLM versus targeted augmentation. Using LangChain, the chapter assembles end‑to‑end RAG pipelines across loaders, splitters, embeddings, and vector stores (e.g., Chroma) to deliver scalable document Q&A and agent grounding.
The chapter then applies these patterns to agent platforms with knowledge and memory stores, showing how agents can attach a knowledge base to chats and how memories are captured, summarized, embedded, and retrieved. It maps cognitive notions to AI (sensory, short‑term/working, long‑term) and extends memory into semantic, episodic, and procedural forms using LLM functions for extraction and categorization. Finally, it introduces compression—clustering and summarizing memories/knowledge to reduce redundancy and improve retrieval—and offers guidance on when to compress, how often, and how multi‑level compression or multiple stores can further optimize agent behavior.
Memory and retrieval and the augmentation of the prompt using the prompt engineering strategies Use External Tools and Provide Reference Text.
The two phases of RAG: First, documents must be loaded, transformed, embedded, and stored, and then they can be queried using augmented generation.
Memory retrieval for augmented generation uses the same embedding patterns to index items to a vector database.
How cosine similarity is measured
The cosine similarity between selected document and document set
Embeddings in 3D, showing how similar semantic documents are grouped
Load, transform, embed, and store steps in storing documents for later retrieval
How the document would ideally be split into chunks for better semantic and contextual meaning
Adding a new knowledge store and populating it with a document
The embeddings and document query views
Enabling the knowledge store for agent use
Managing the knowledge store splitting and chunking options
How memory is broken down into various forms
Basic memory retrieval and augmentation workflow
Adding memories to a newly created memory store
Conversing with a different agent on the same memory store
How semantic memory augmentation works
Configuration for changing the memory store type to semantic
Comparing memories for the same information given two different memory types
The process of memory and knowledge compression
The interface for compressing memories
Summary
- Memory in AI Applications differentiates between unstructured and structured memory, highlighting their use in contextualizing prompts for more relevant interactions.
- Retrieval-augmented generation (RAG) is a mechanism for enhancing prompts with context from external documents, utilizing vector embeddings and similarity search to retrieve relevant content.
- Semantic Search and Document Indexing converts documents into semantic vectors using TF-IDF and cosine similarity, enhancing the capability to perform semantic searches across indexed documents.
- Vector Databases and Similarity Search stores document vectors in a vector database, facilitating efficient similarity searches and improving retrieval accuracy.
- Document Embeddings capture semantic meanings, leveraging models like OpenAI's to generate embeddings that preserve a document's context and facilitate semantic similarity searches.
- LangChain provides several tools for performing RAG, and it abstracts the retrieval process, allowing for easy implementation of RAG and memory systems across various data sources and vector stores.
- Short-term and Long-term Memory in LangChain implements conversational memory within LangChain, distinguishing between short-term buffering patterns and long-term storage solutions.
- Storing document vectors in databases for efficient similarity searches is crucial for implementing scalable retrieval systems in AI applications.
- Agent knowledge directly relates to the general RAG pattern of performing question and answer on documents or other textual information.
- Agent memory is a pattern related to RAG that captures the agentic interactions with users, itself, and other systems.
- Nexus is a platform that implements agentic knowledge and memory systems, including setting up knowledge stores for document retrieval and memory stores for various forms of memory.
- Semantic memory augmentation (Semantic Memory) differentiates between various types of memories (semantic, episodic, procedural). It implements them through semantic augmentation, enhancing agents' ability to recall and use information relevantly specific to the nature of the memories.
- Memory and Knowledge Compression are techniques for condensing information stored in memory and knowledge systems, improving retrieval efficiency and relevancy through clustering and summarization.