Persistent AI Chat Memory with GPT-4o-mini and Qdrant RAG - n8n Workflow

Build powerful, context-aware AI assistants using this advanced n8n workflow. Integrate GPT-4o-mini, OpenAI embeddings, and Qdrant for persistent long-term memory retrieval (RAG).

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers building personalized chat interfaces.

  • Engineers needing production-ready RAG implementation in n8n.

  • Users looking for advanced n8n templates integrating LangChain nodes and vector databases.

  • Businesses requiring customer service bots that remember historical context.

Overview

Lack of memory is a significant limitation of standard large language models (LLMs). This professional n8n workflow solves that problem by integrating a robust Retrieval-Augmented Generation (RAG) system using Qdrant as a vector database. The automation utilizes the efficient GPT-4o-mini model for conversation, complemented by OpenAI's powerful embedding models (text-embedding-3-small) and Cohere's reranker for maximum retrieval accuracy. Every interaction processed by this n8n workflow is vectorized, chunked, and stored, allowing the AI Agent to query its own history before responding, ensuring personalization and continuity. This is one of the most sophisticated n8n templates available for building AI assistants with durable, persistent memory.

How it Works

The entire process is initiated by the custom When chat message received n8n trigger, which receives user input from a chat interface or webhook.


  1. Trigger and Agent Initiation: The incoming message activates the n8n trigger, sending the data to the AI Agent n8n node. The Agent uses a detailed system prompt instructing it to utilize the RAGMEMORY tool for historical context before generating a response.

  2. Context Retrieval (RAG): If required, the Agent calls the RAGMEMORY n8n node (Qdrant Vector Store in retrieval mode). This node vectorizes the user query using the Embeddings for Retrieval n8n node (OpenAI embeddings, 1024 dimensions). It retrieves the top 20 most relevant conversation snippets from the Qdrant 'ltm' collection.

  3. Relevance Optimization: The retrieved context is passed to the Reranker Cohere n8n node, which significantly improves relevance by re-ranking the snippets, ensuring the most accurate context is fed to the LLM.

  4. Response Generation: The AI Agent node, powered by the GPT-4o-mini (Main) LLM and equipped with the retrieved context, generates a comprehensive response.

  5. Structured Output: The output is validated and standardized by the Structured Output Parser n8n node, enforcing a strict JSON schema including session IDs and timestamps.

  6. Memory Storage: The complete interaction (user input + AI output) is then ingested by the Store Conversation n8n node (Qdrant Vector Store in insert mode). This memory ingestion path includes a Default Data Loader, the Recursive Character Text Splitter (chunk size 200, overlap 40), and the Embeddings OpenAI n8n node for vectorization, ensuring future retrieval accuracy. The final Format Response n8n node extracts the clean AI message for the user.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON and import it directly into your n8n instance.

  2. OpenAI Credentials: Set up or select your OpenAI credentials. This n8n workflow requires API keys for both the LLM and the embedding services (Embeddings OpenAI and Embeddings for Retrieval).

  3. Qdrant Setup: Configure the Qdrant credentials used by the RAG_MEMORY and Store Conversation n8n nodes. Ensure the 'ltm' (long-term memory) collection is created with 1024 vector dimensions.

  4. Cohere (Optional): If you wish to use the advanced re-ranking feature, configure the Reranker Cohere n8n node with a valid Cohere API key.

  5. Activation: Activate the n8n workflow. The When chat message received n8n trigger will generate a unique webhook URL that can be integrated into your chat frontend.

  6. Testing: Send a message to the generated webhook URL to test the functionality and verify that the conversation data is successfully stored in Qdrant, confirming the n8n templates setup is complete.

Node Details


  • When chat message received (n8n trigger): The starting point of this n8n workflow. It listens for incoming user messages via a webhook URL.

  • AI Agent: The orchestrator. It uses a custom system message emphasizing the use of the RAGMEMORY tool for conversational context.

  • GPT-4o-mini (Main): The large language model (LLM) used by the Agent for real-time conversation generation.

  • RAGMEMORY (Qdrant): An n8n node configured as a tool (retrieve-as-tool). It searches the 'ltm' collection for relevant memories.

  • Embeddings for Retrieval (OpenAI): Converts the user's query into a 1024-dimensional vector for semantic search against the Qdrant index. This n8n node is crucial for accurate context lookup.

  • Reranker Cohere: Re-scores the 20 retrieved memory chunks to ensure only the highest relevance data is used by the AI Agent.

  • Structured Output Parser: Enforces a JSON schema on the AI's final response, guaranteeing structured output for reliable storage.

  • Store Conversation (Qdrant): An n8n node configured for insertion. This is where the vectorized conversation history is saved.

  • Recursive Character Text Splitter: Takes the full conversation data and chunks it (200 chars, 40 overlap) before vectorization, optimized for conversation snippets. A necessary component in this high-performance n8n workflow.

  • Embeddings OpenAI: Used specifically in the memory ingestion path to create the 1024-dimensional vectors stored in Qdrant.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all

Featured*