Home » AI Chatbots » Conversation Memory

How Chatbot Memory and Conversation History Work

Chatbot memory works by sending the full conversation history to the AI model with each new message. The model reads all previous messages, your system prompt, and any retrieved knowledge base content, then generates a response that accounts for the full context. The conversation is stored in a database so the chatbot can maintain continuity across multiple exchanges.

Why Memory Matters

Without conversation history, every message would be like talking to someone with amnesia. The user says "I need help with my order," then follows up with "It was placed last Tuesday," and the chatbot would not know what "it" refers to. Memory is what makes the chatbot conversational rather than just a single-question FAQ tool.

On this platform, each conversation gets a unique ID and is stored in the conversationData table. Every time the user sends a new message, the system loads the full conversation history, appends the new message, sends everything to the AI model, and stores the response. The visitor experiences a continuous, contextual conversation.

How the Context Window Works

AI models have a context window, a maximum amount of text they can process at once. This window holds everything the model reads per request: the system prompt, conversation history, retrieved knowledge base chunks, and the user's current message. Modern models like GPT-4.1-mini and Claude Sonnet have large context windows (128,000+ tokens), which is enough for most conversations.

A typical conversation uses context like this:

For a 20-message conversation with knowledge base retrieval, you might use 5,000 to 8,000 tokens total. That is well within any modern model's context window. Very long conversations (50+ messages) might approach limits on older models, but current models handle even extended conversations comfortably.

Conversation Storage and Retrieval

Each conversation is stored as a record with the full message history, timestamps, and metadata. When a visitor returns to the chat widget, the platform can load their existing conversation so they pick up where they left off rather than starting over. This is especially useful for support conversations that span multiple visits.

The conversation data also feeds into your admin inbox, where you can read every exchange your chatbot has had. This gives you visibility into what customers are asking, how the chatbot responds, and where it might need better training data. See chatbot analytics for more on tracking performance.

Cost Implications of Memory

Because the full conversation history is sent with each message, longer conversations cost more per response. The first message in a conversation is cheapest because the context only contains the system prompt and any knowledge base content. By message 20, the context includes all 19 previous exchanges, which means more tokens processed per request.

In practice, the cost increase is gradual. A 6-message conversation using GPT-4.1-mini might cost 3 credits for the first response and 5 credits for the sixth. The difference is small enough that most businesses do not need to worry about it. If you do want to manage costs on very long conversations, you can set a maximum conversation length in your chatbot settings. See the full chatbot cost guide for detailed pricing.

Memory vs Knowledge Base

It is important to understand the difference between conversation memory and the knowledge base. Memory is the chatbot remembering what was said earlier in this specific conversation. The knowledge base is the permanent library of information the chatbot can search to answer questions.

When a user asks a question, the system searches the knowledge base using RAG (retrieval-augmented generation) to find relevant information, then includes both the retrieved knowledge and the conversation history when generating a response. Memory provides context ("the user already asked about pricing"), while the knowledge base provides facts ("the premium plan costs $49/month").

Conversation Handoff and History

When a conversation is handed off to a human agent, the full conversation history transfers to the live operator inbox. The agent sees everything the customer discussed with the AI, so the customer does not have to repeat themselves. This seamless handoff is one of the key benefits of maintaining proper conversation memory throughout the interaction.

Privacy note: Conversation data is stored per account and only accessible to the account owner through the admin panel. Conversations are not shared across accounts or used to train AI models. You can delete individual conversations or set automatic expiration using TTL (time-to-live) on the database records.

Build a chatbot that remembers context and delivers smarter conversations.

Get Started Free