Chapter 7 — MCP & RAG
RAG Integration
Retrieval-Augmented Generation with LightRAG gives Agents access to knowledge stored in external documents — exposed as a tool, so the Agent decides at runtime when document-based knowledge is required.
RAG acts as an additional knowledge source when the information available through the Agent's other configured tools is not sufficient. Documents are managed through a dedicated Knowledge Base interface: the Knowledge Base Backend manages document metadata and communication with LightRAG, while LightRAG processes, indexes and retrieves relevant information. The retrieved information returns to the Agent as additional context, combinable with the conversation context and results from other tools.
RAG components
Agent
Determines whether additional knowledge is required for the current request.
RAG Tool
Exposes knowledge retrieval as an Agent capability and connects the Agent with the Knowledge Base Backend.
Knowledge Base Backend
The integration layer between the platform and LightRAG. It manages knowledge-base topics, document metadata, retrieval requests and LightRAG server configuration.
Knowledge Base Topic
A separate knowledge source. Each topic has its own LightRAG server configuration and contains the documents associated with that knowledge base.
LightRAG Server
Processes and indexes documents and performs retrieval against the indexed knowledge.
Documents
The external knowledge sources uploaded to a topic and indexed by LightRAG for retrieval.
Agent → RAG tool → Knowledge Base Backend → topic → LightRAG → indexed documents
Knowledge base and document management
Documents are organised into Knowledge Base Topics. The backend is configured at system level through a dedicated address, similar to the MCP Registry — a single integration point for topic management, document handling and RAG queries. The application communicates with that address rather than connecting directly to individual LightRAG servers, and the backend routes each request to the LightRAG server associated with the corresponding topic.
When a document is uploaded, the backend stores its metadata and forwards the document to the topic's LightRAG server, which processes and indexes the content for later retrieval. Processing status is maintained by the backend and can indicate that a document is uploading, processing, indexed or failed. Knowledge available to the Agent can therefore be updated by adding or removing documents, without modifying the Agent itself.
Agent runtime retrieval
At runtime the Agent evaluates the user request together with the conversation context and what its other tools provide. When document-based knowledge is required, it invokes the RAG tool, which sends the query to the backend through the topic-specific query endpoint:
POST /api/topics/{topicId}/queries
The backend forwards the request to the topic's LightRAG server, which searches the indexed knowledge and returns the relevant information. The query operation supports retrieval configuration such as query mode and topK, and can return only the required context. The retrieved context goes back to the Agent, which combines it with the existing conversation context and other tool results to determine the final response or next action — reasoning and response generation stay with the Agent, while RAG supplies the knowledge that reasoning needs.