An adaptive memory architecture for conversational AI that goes beyond traditional semantic retrieval by combining semantic, episodic, procedural, and temporal memory with hybrid retrieval, adaptive reranking, conflict resolution, consolidation, lifecycle management, and controlled forgetting.
Most Retrieval-Augmented Generation (RAG) systems treat retrieved information primarily as a collection of semantically similar documents.
That approach works well for static knowledge, but conversational AI requires something more sophisticated.
A user may have:
- Current preferences
- Previous preferences
- Repeated behaviors
- Past events
- Procedural knowledge
- Time-dependent information
- Conflicting memories
- Frequently accessed information
- Information that should eventually be forgotten
For example:
"Which database do I currently prefer?"
A traditional semantic retriever may return both:
- "I previously used MongoDB."
- "I now prefer PostgreSQL."
Both statements are semantically relevant, but only one represents the user's current preference.
This project addresses that problem by introducing an Adaptive Conversational Memory Architecture that dynamically routes queries, retrieves memories from multiple memory systems, fuses candidates, reranks them using multiple signals, resolves conflicts, builds context, and finally generates a response.
The primary objective is to design a conversational memory system capable of:
- Understanding different types of memories.
- Storing memories using appropriate representations.
- Routing queries to the most relevant memory subsystem.
- Combining results from multiple retrieval mechanisms.
- Ranking memories using more than semantic similarity.
- Handling conflicting and outdated information.
- Consolidating repeated information.
- Managing memory lifecycle and controlled forgetting.
- Building relevant conversational context.
- Evaluating retrieval quality against a baseline system.
ββββββββββββββββββββββββ
β User Conversation β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Memory Extraction β
β using LLM β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Memory Classifier β
ββββββββββββ¬ββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Semantic β β Episodic β β Procedural β
β Memory β β Memory β β Memory β
ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ
β β β
βββββββββββββββββββββββΌββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Importance / β
β Confidence Scoring β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Conflict Detection β
β & Resolution β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Memory Consolidation β
ββββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Memory Storage β
β β
β Vector β Temporal β Graph/Proc β
βββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Memory Lifecycle β
β & Controlled Forget. β
ββββββββββββββββββββββββ
ββββββββββββββββββββββββ
β User Query β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Memory Router β
β β
β Semantic β
β Episodic β
β Procedural β
β Temporal β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββ
β Memory-Specific Retrieval β
β β
β Vector Retrieval β
β Temporal Retrieval β
β Graph Retrieval β
β Procedural Retrieval β
ββββββββββββββββββββββ¬ββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Candidate Fusion β
β β
β Deduplication β
β Score Normalization β
β Hybrid Fusion β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Adaptive Reranker β
β β
β Retrieval Score β
β Query Relevance β
β Importance β
β Recency β
β Source Priority β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Conflict Detection β
β & Resolution β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Context Builder β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Response Generator β
β + LLM β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Final Response β
ββββββββββββββββββββββββ
Conversational information is extracted into structured memory representations.
Examples:
"I prefer PostgreSQL now."
"I previously used MongoDB."
"I worked on an AI project yesterday."
"My usual deployment process involves..."
The extracted information is converted into structured memory objects.
The system classifies memories according to their role.
Stable facts, preferences, interests, and knowledge.
Example:
I prefer Python for machine learning projects.
Past events and experiences.
Example:
Yesterday I worked on my adaptive conversational memory project.
Knowledge about how the user performs tasks.
Example:
I first implement the experiment, then run its tests,
and finally run the complete pytest suite.
Information whose relevance depends strongly on time.
Example:
I currently use Go.
I previously used Python.
The Memory Router analyzes the query and determines which memory subsystem should be prioritized.
Examples:
"What did I work on yesterday?"
β
Episodic
"How do I deploy my application?"
β
Procedural
"What database do I currently prefer?"
β
Semantic
+ Temporal signals
Semantic memories are represented using embeddings and stored in a vector store.
The vector retrieval system provides the initial semantic candidate set.
This is useful for queries where meaning is more important than exact keyword matching.
Temporal information is handled separately so that the system can distinguish between:
Previous preference
β
Current preference
β
Future / latest information
This prevents older memories from being treated as equally relevant when the user explicitly asks about current or recent information.
Graph structures allow relationships between memories, entities, and procedural states to be represented explicitly.
This is particularly useful when the relationship between pieces of information matters rather than just their semantic similarity.
Instead of relying on a single retrieval mechanism, candidate results from different sources are combined.
The hybrid retrieval layer performs:
Multiple Retrieval Sources
β
Deduplication
β
Score Normalization
β
Score Fusion
β
Candidate Ranking
This creates a larger candidate pool for the adaptive reranker.
The reranker is one of the key components of the system.
Instead of ranking memories purely according to retrieval similarity, the system considers multiple signals:
Final Score =
Retrieval Relevance
+ Query Relevance
+ Importance
+ Recency
+ Source Priority
Current deterministic ranking configuration:
| Signal | Weight |
|---|---|
| Retrieval Score | 0.55 |
| Query Relevance | 0.15 |
| Importance | 0.12 |
| Recency | 0.10 |
| Source Priority | 0.08 |
This allows a memory with slightly lower embedding similarity to outrank a less useful memory when other signals indicate that it is more relevant.
Conversational memory naturally contains contradictions.
Example:
Old:
I use MongoDB.
New:
I now prefer PostgreSQL.
The system identifies memories belonging to the same conflict group and resolves the conflict while preserving historical information.
The goal is not to simply delete the old memory.
Instead:
Historical Memory
+
Current Memory
β
Conflict Resolution
β
Current preference is prioritized
Historical information remains available
Repeated information can be consolidated into stronger memory representations.
For example:
Python used in project A
Python used in project B
Python used in project C
can support the higher-level understanding:
Python is repeatedly used across my projects.
This reduces redundant memory representations while preserving useful information.
Memories are not treated as permanently static objects.
Conceptually:
Created
β
Active
β
Accessed / Updated
β
Consolidated
β
Potentially Forgotten
The system also contains forgetting mechanisms for controlled memory management.
After retrieval and reranking, the most relevant memories are converted into a context representation.
Retrieved Memories
β
Ranked Memories
β
Conflict Resolution
β
Context Builder
β
LLM Context
This prevents irrelevant memories from unnecessarily occupying the model's context.
The final context is passed to the response-generation layer.
User Query
+
Relevant Memory Context
β
LLM
β
Final Response
Traditional semantic RAG:
Query
β
Embedding
β
Vector Search
β
Top-K Documents
β
LLM
Adaptive Conversational Memory:
Query
β
Memory Routing
β
Multiple Memory Systems
β
Hybrid Retrieval
β
Candidate Fusion
β
Adaptive Reranking
β
Conflict Resolution
β
Context Construction
β
LLM
The adaptive architecture provides additional mechanisms for:
- Changing preferences
- Historical information
- Procedural knowledge
- Time-sensitive memories
- Conflicting memories
- Repeated information
- Memory importance
- Memory recency
- Memory lifecycle
The system includes a dedicated retrieval benchmark containing 20 evaluation cases covering:
- Semantic retrieval
- Episodic retrieval
- Procedural retrieval
- Temporal retrieval
- Conflict handling
- Consolidation
- Noise
- Mixed queries
The adaptive retriever is evaluated against a baseline retriever.
| Metric | Baseline | Adaptive | Improvement |
|---|---|---|---|
| Recall@5 | 0.800 | 1.000 | +25.00% |
| Precision@5 | 0.160 | 0.232 | +44.79% |
| Hit@5 | 0.800 | 1.000 | +25.00% |
| MRR | 0.545 | 0.674 | +23.70% |
| NDCG@5 | 0.608 | 0.754 | +24.02% |
Adaptive Recall@5 improved from 0.800 to 1.000, achieving a 25% relative improvement over the baseline.
The adaptive system achieved 1.000 Recall@5 and 1.000 Hit@5 across all 20 benchmark cases.
The project contains a comprehensive automated test suite covering the major system components.
Final validation:
507 / 507 tests passed
The complete retrieval benchmark was validated with:
20 / 20 cases
Validation flow:
Unit Tests
β
Component Tests
β
Memory Pipeline Tests
β
Retrieval Benchmark
Baseline ββββββββββ 0.800
Adaptive ββββββββββ 1.000
Baseline ββββββββββ 0.800
Adaptive ββββββββββ 1.000
Baseline ββββββββββ 0.608
Adaptive ββββββββββ 0.754
The improvement is not limited to whether the correct memory appears in the retrieved set. MRR and NDCG also improve, indicating better ranking quality.
Adaptive-Conversational-Memory/
β
βββ data/
β βββ conversations/
β βββ evaluation/
β βββ memories/
β
βββ scripts/
β βββ populate_graph_store.py
β βββ populate_temporal_store.py
β βββ populate_vector_store.py
β βββ run_benchmark.py
β
βββ src/
β βββ classification/
β βββ conflict/
β βββ consolidation/
β βββ embeddings/
β βββ evaluation/
β βββ forgetting/
β βββ lifecycle/
β βββ llm/
β βββ models/
β βββ pipeline/
β βββ retrieval/
β βββ routing/
β βββ storage/
β
βββ tests/
β βββ test_adaptive_memory.py
β βββ test_adaptive_retriever.py
β βββ test_baseline_rag.py
β βββ test_conflict.py
β βββ test_consolidation.py
β βββ test_forgetting.py
β βββ test_hybrid_retriever.py
β βββ test_memory_pipeline.py
β βββ test_reranker.py
β βββ test_router.py
β βββ ...
β
βββ requirements.txt
βββ README.md
git clone <your-repository-url>
cd Adaptive-Conversational-Memorypython -m venv .venvsource .venv/bin/activate.venv\Scripts\activatepip install -r requirements.txtpython -m pytestExpected:
507 passed
PYTHONPATH=. python scripts/run_benchmark.pyThe benchmark compares the baseline retrieval system against the adaptive retrieval system.
Measures how many relevant memories are retrieved within the top K results.
Measures the proportion of retrieved results that are relevant.
Measures whether at least one relevant memory appears in the top K.
Measures how highly the first relevant memory is ranked.
Measures ranking quality while considering the position of relevant results.
Not every memory should be represented or retrieved in the same way.
Semantic similarity alone is insufficient.
A recent preference may be more relevant than an older conflicting preference.
Historical information can remain useful.
Different queries require different memory strategies.
Memories should be created, accessed, updated, consolidated, and potentially forgotten.
The system includes an explicit evaluation framework rather than relying only on qualitative examples.
Language
Python
AI / ML
Sentence Embeddings
Hugging Face Models
LLM-based Memory Extraction
LLM-based Response Generation
Retrieval
Vector Retrieval
Hybrid Retrieval
Graph Retrieval
Temporal Retrieval
Adaptive Reranking
Storage
Vector Store
Temporal Store
Graph Store
SQLite-based Memory Storage
Evaluation
Pytest
Recall@K
Precision@K
Hit@K
MRR
NDCG
This project demonstrates practical implementation of:
- Conversational AI memory architectures
- Retrieval-Augmented Generation
- Semantic search
- Hybrid retrieval
- Embedding-based retrieval
- Query routing
- Reranking
- Temporal reasoning
- Conflict resolution
- Memory consolidation
- Controlled forgetting
- Graph-based memory
- Evaluation-driven development
- End-to-end AI pipeline design
Consider the following memories:
Memory 1:
I previously used MongoDB.
Memory 2:
I now prefer PostgreSQL.
Memory 3:
I usually use PostgreSQL for relational projects.
Query:
Which database do I currently prefer?
Instead of simply returning the most semantically similar memories, the adaptive system considers:
Semantic relevance
+
Query relevance
+
Importance
+
Recency
+
Memory source
+
Conflict resolution
The system can therefore prioritize the current preference while preserving the historical memory.
| Capability | Traditional Semantic RAG | Adaptive Conversational Memory |
|---|---|---|
| Semantic retrieval | β | β |
| Multiple memory types | β | β |
| Query routing | β | β |
| Temporal retrieval | Limited | β |
| Procedural memory | Limited | β |
| Graph memory | Limited | β |
| Hybrid retrieval | Limited | β |
| Adaptive reranking | Limited | β |
| Importance scoring | β | β |
| Recency scoring | β | β |
| Conflict resolution | β | β |
| Memory consolidation | β | β |
| Controlled forgetting | β | β |
| Retrieval benchmark | Varies | β |
ββββββββββββββββββββββββββββββββββββββββββββββ
β ADAPTIVE MEMORY PROJECT β
ββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Memory Architecture β
Complete β
β Query Routing β
Complete β
β Hybrid Retrieval β
Complete β
β Adaptive Reranking β
Complete β
β Conflict Resolution β
Complete β
β Memory Consolidation β
Complete β
β Memory Lifecycle β
Complete β
β Controlled Forgetting β
Complete β
β End-to-End Pipeline β
Validated β
β Automated Tests β
507/507 β
β Benchmark β
20/20 β
β Adaptive Recall@5 β
1.000 β
β β
ββββββββββββββββββββββββββββββββββββββββββββββ
Baseline Recall@5
0.800
β
β +25%
βΌ
Adaptive Recall@5
1.000
Additional improvements:
Precision@5 0.160 β 0.232
Hit@5 0.800 β 1.000
MRR 0.545 β 0.674
NDCG@5 0.608 β 0.754
The benchmark demonstrates measurable improvement in both retrieval coverage and ranking quality.
Potential future extensions include:
- Learned reranking models
- Neural conflict resolution
- Larger conversational datasets
- Online memory learning
- User-specific memory policies
- More advanced temporal reasoning
- Long-term memory compression
- Reinforcement-based retrieval optimization
- Multi-user memory isolation
- Distributed memory storage
- Production-scale vector and graph infrastructure
- Large-scale evaluation across real conversational datasets
This project is intended for academic and research purposes.
Add your preferred license here if the repository will be publicly distributed.
Adaptive Conversational Memory is a multi-layer memory architecture designed to make conversational AI systems more reliable when dealing with persistent, changing, temporal, procedural, and conflicting user information.
Rather than treating memory as a simple vector database, the system combines:
Memory Classification
β
Memory Routing
β
Specialized Retrieval
β
Hybrid Fusion
β
Adaptive Reranking
β
Conflict Resolution
β
Context Construction
β
LLM Response Generation
β
Memory Lifecycle Management
With a final benchmark result of:
Recall@5: 1.000 vs 0.800 baseline
and:
507/507 automated tests passing
the project provides an evaluation-driven implementation of an adaptive conversational memory architecture.