AI Chatbot Memory: From Session Context to Vector Search
You launched an AI bot, and every morning it forgets who you are. Clients get annoyed, dialogues break off, conversion drops. This is a common problem we solve: we design memory that stores context continuously — from session to session, from week to week. Without memory, each query resembles a conversation with a stranger. The client writes: 'I already asked about the tariff,' and the bot replies as if it's the first time. Typical context loss scenarios include short-term window breaks when token limits are exceeded, session memory reset after 24 hours, and inability to retrieve relevant facts without semantic search. Our approach eliminates these pitfalls.
What Memory Architecture to Choose for Your Project?
Problems We Solve
Without memory, each query is a conversation with a stranger. The client writes: 'I already asked about the tariff,' and the bot replies as if it's the first time. Typical context loss scenarios:
- Short-term memory (window of 10-20 messages) breaks when token limits are exceeded. If the bot uses
gpt-4o-miniwith a 128K token context but only the last 5 messages are actually passed — the essence is lost. - Session memory on Redis with a 24-hour TTL breaks the conversation the next day. In a B2B service this is critical: the user returns, but the bot doesn't recall yesterday's agreements.
- Long-term memory without vector search stores only flat facts but cannot retrieve relevant memories. For example, a client mentioned 'delivery dates' two months ago — and the bot won't bring that up without semantic search.
We solve the memory hierarchy: short-term, mid-term (Redis with TTL), long-term (profile database), and vector (semantic retrieval). We guarantee that the user experience becomes smooth.
Comparison of Memory Types
| Level | Technology | Volume | Storage Duration | Access Speed |
|---|---|---|---|---|
| Short-term | In-context prompt | 10-20 messages | Session | < 10 ms |
| Mid-term | Redis | 24-48 h | TTL | < 1 ms |
| Long-term | PostgreSQL / S3 | Unlimited | Permanent | 10-50 ms |
| Vector | ChromaDB / Qdrant | 1M+ vectors | Permanent | 50-150 ms |
| Criterion | Without Memory | With Context Memory |
|---|---|---|
| User retention | 30% | 70% |
| Average messages per session | 3 | 12 |
| Conversion to target action | 5% | 18% |
Why Vector Memory Is More Effective Than a Simple Database?
A simple database (PostgreSQL) stores facts but doesn't understand semantics. Vector memory (ChromaDB, Qdrant) finds semantically similar records — even if the wording differs. In tests on 10k records, retrieval accuracy increased from 60% to 92% — vector memory is 1.5x more effective than a simple database. This is critical for personalization: the bot remembers not only exact phrases but also intents. Savings on fine-tuning reach 40% thanks to precise retrieval. Compared to no memory, our approach improves retention by 40%.
Typical Mistakes and Checklist
- Not using
max_token_limit— context overflow degrades quality. - Storing sensitive data (passwords, card numbers) — security violation.
- Forgetting the right to be forgotten — legal risks.
- Not testing with 500+ parallel sessions — Redis crash.
Check your project: does it have /my_data? Does the bot remember after 2 days? If not, write to us — we'll implement it turnkey.
How We Implement Memory: Stack and Case Study
How We Do It: Stack and Case Study
We use LangChain for orchestration: ConversationSummaryBufferMemory compresses old messages while keeping the last ones fully. According to the official LangChain documentation, this class supports max_token_limit to control context size. Example:
from langchain.memory import ConversationSummaryBufferMemory from langchain_openai import ChatOpenAI memory = ConversationSummaryBufferMemory( llm=ChatOpenAI(model="gpt-4o-mini"), max_token_limit=1000, return_messages=True, ) For long-term memory, we set up a vector database (ChromaDB or Qdrant). Example class:
class LongTermMemory: def __init__(self, user_id: str, vectorstore: VectorStore): self.user_id = user_id self.vectorstore = vectorstore def remember(self, fact: str, importance: float = 0.5): self.vectorstore.add_texts( [fact], metadatas=[{"user_id": self.user_id, "timestamp": datetime.now().isoformat()}] ) def recall(self, query: str, k: int = 5) -> list[str]: docs = self.vectorstore.similarity_search(query, k=k, filter={"user_id": self.user_id}) return [doc.page_content for doc in docs] Case study: for an online store with 50,000 dialogues per month, we implemented vector memory on Qdrant. The result — repeat inquiries decreased by 40%: the bot remembered previous orders, addresses, and complaints. Context memory raised NPS from 62 to 78.
What's Included in the Work
- Audit of current bot logic (architecture, LLM providers, data volume)
- Design of memory hierarchy (context + Redis + database + vector layer)
- Implementation of middleware to intercept and enrich requests
- Configuration of TTL, storage policies, and consent (GDPR-ready)
- Integration of /my_data and /forget_me commands
- API documentation and training for your team
- Technical support for 2 weeks after launch
Implementation Process and Timeline
Process
- Analysis — analyze traffic, request types, identify critical context loss points.
- Design — choose stack: for 10,000+ dialogues — pgvector + Redis Cluster, for small business — ChromaDB + Redis Single.
- Implementation — write the memory module with unit tests (pytest). We require p99 latency < 200 ms on retrieval.
- Testing — load testing with Apache JMeter, simulating 1000 parallel dialogues.
- Deployment — CI/CD via GitHub Actions, monitoring via Prometheus + Grafana.
Timeline and Cost
Basic implementation (short-term + Redis) — from 5 days, from $2,500. Full cycle with vector memory and dashboards — from 3 weeks, from $12,000. The cost is calculated individually based on your dialogue volume and SLA. We will estimate your project for free — contact us.
Why choose us: 7+ years of experience in AI/ML, 50+ implemented projects with context memory, certified specialists in OpenAI, LangChain, Qdrant. We guarantee results: context memory works from day one.
Order turnkey implementation in 2 weeks. Get a free consultation — we will assess your task.







