An Advanced AI Chatbot with Tiered Memory, Retrieval-Augmented Generation, and Model Context Protocol Integration

Authors

  • Mr. Padmalochan Routray Author
  • Mr. Rakesh Palai Author
  • Prof. Antaryami Muduli Author

DOI:

https://doi.org/10.64751/

Abstract

Modern conversational AI systems face three fundamental limitations: inability to recall prior interactions, no access to private
domain knowledge, and no deterministic connection to external services. This paper presents the design and implementation of an advanced AI
chatbot that overcomes all three limitations simultaneously. The system introduces: (i) a six-tier hierarchical memory model with exponential
decay scoring and dual-write persistence to PostgreSQL and a pgvector semantic index; (ii) a four-stage Retrieval-Augmented Generation
(RAG) pipeline combining query rewriting, parent-child chunking, BM25-pgvector hybrid search with Reciprocal Rank Fusion, and crossencoder
re-ranking; and (iii) a Model Context Protocol (MCP) integration layer enabling dynamic tool binding via stdio, SSE, and streamable
HTTP transports. The system is orchestrated by a LangGraph directed state-graph agent supporting task complexity classification, LLMgenerated
multi-step planning, Human-in-the-Loop (HITL) safety interruption, and automatic conversation summarisation. Deployed on a
FastAPI, PostgreSQL, and React stack with Docker Compose, the system achieves sub-400 ms median response latency for simple queries and
demonstrates coherent, context-aware, multi-step task execution in production conditions. Comparative evaluation shows the tiered memory
recall accuracy reaches 91.4% on a held-out biographical quiz benchmark, and the four-stage RAG pipeline outperforms naive single-query
vector search by 23 percentage points of mean reciprocal rank. The HITL safety layer blocks 100% of destructive tool invocations in
adversarial testing without a single false negative.

Downloads

Published

2026-06-05

How to Cite

Mr. Padmalochan Routray, Mr. Rakesh Palai, & Prof. Antaryami Muduli. (2026). An Advanced AI Chatbot with Tiered Memory, Retrieval-Augmented Generation, and Model Context Protocol Integration. International Journal of Pharmacy With Medical Sciences, 6(2(1), 33-41. https://doi.org/10.64751/