Appearance
Memory Consolidation
Extraction checks each new memory against its closest neighbors, but some duplicates still get through: two paraphrases stored weeks apart, or the same event recorded twice in one day. Consolidation finds memories that state the same fact and replaces them with one.
Why Consolidation Matters
Duplicates make the store harder to keep accurate. When you correct a fact, extraction supersedes one copy, and any other copy keeps stating the old value. Paraphrases worded differently enough to slip past recall's redundancy check also take up slots that other memories could use. Consolidation keeps the store to one memory per fact.
It doesn't combine related facts into summaries. "User prefers React over Vue" and "User switched from Vue to React last year" are two facts, and they stay two memories.
How It Works
Consolidation uses a two-phase job architecture for efficient parallel processing:
Phase 1: Cluster Building
- Gather candidate memories (see Daily Runs and Older Neighbors)
- Find pairs with high similarity (≥0.80) and group them into clusters using greedy clustering
- Dispatch one job per cluster
Phase 2: Cluster Processing
- Skip the cluster if any memory in it has reached the generation limit
- Ask the LLM whether the memories state the same fact or event
- Reject the merge if the proposed content breaks the length cap
- Lock the source memories, confirm none changed since review, then create the merged memory and soft-delete the sources
- Otherwise, the memories remain separate
When a merge goes through, any Truth built from one of the merged memories is flagged for review, and the nightly distillation run checks it against the merged memory.
The Merge Policy
The LLM merges a cluster only when one of these holds:
- The memories are paraphrases of each other
- One memory strictly contains another, so everything the shorter one says is already in the longer one
- One memory corrects or updates another about the same fact, and the newer value wins
If the model can't say in one short sentence what single fact or event all of the memories state, it keeps them separate. Different facts on the same topic, different occurrences of a similar event (Monday's meeting and Friday's meeting), and different states at different times all stay separate. So does anything the model is unsure about. A wrong merge destroys information, while an extra memory costs almost nothing.
The Length Cap
A merge restates one fact, so it shouldn't come out much longer than its longest source. Iris enforces that in code after the LLM responds. The merged content can be at most the smaller of:
max_content_chars(900 characters)max_content_growth(1.5) times the longest source, but never less thanmin_content_chars(200)
The floor lets very short memories merge. For two sources of 60 and 80 characters, the cap is 200. For a 400-character source, it's 600.
A merge over the cap is discarded and the sources stay separate. A cluster whose longest source is already over max_content_chars is kept separate too, since any merge would have to drop detail. The prompt states each cluster's cap, so most merges fit on the first try.
NOTE
Existing merged memories longer than max_content_chars aren't split. Any new merge that includes one is rejected, so they stay as they are.
Example
Input memories:
- "Has 8 years of PHP experience"
- "Has been a PHP developer for about 8 years"
- "Works primarily with the Laravel framework"
Result:
- "Has 8 years of PHP experience"
- "Works primarily with the Laravel framework"
The first two are paraphrases, so they merge. The third is a related but different fact, so it stays on its own. The LLM decides per cluster, though: if all three land in the same cluster, it keeps the whole cluster separate rather than merging part of it.
Merged Memories Keep Their Dates
A merged memory takes the created_at of its newest direct source. Recall weights recency, so a merge of two months-old memories shouldn't rank as brand new information. The merged memory's metadata also records newest_source_at and oldest_source_at.
Backfilling Older Merges
Merged memories created before this behavior carry the date of the merge instead. The iris:backfill-consolidation-timestamps command repairs them. For each merged memory, it walks the consolidated_from chain down to the original, unmerged memories (including soft-deleted ones) and uses the newest created_at it finds.
It's a dry run by default, so you can see what would change first:
bash
# Report how many merged memories carry a misleading date, with a sample
php artisan iris:backfill-consolidation-timestamps
# Write the changes
php artisan iris:backfill-consolidation-timestamps --apply
# Limit to one user
php artisan iris:backfill-consolidation-timestamps --user=1 --apply
# Load fewer memories per chunk (default: 200)
php artisan iris:backfill-consolidation-timestamps --apply --chunk=50The command leaves updated_at alone and saves the previous value in metadata.created_at_before_backfill, so you can see what it changed. Memories whose original sources can't be found are counted as unresolvable and left untouched.
Daily Runs and Older Neighbors
The daily run starts from memories created in the last days_lookback days (3 by default). On its own, that window would miss a common case: a memory extracted today that duplicates one from two months ago.
So for each recent memory, Iris also pulls up to neighbors_per_memory (5) older memories from the whole store that clear the similarity threshold. Clusters are then limited to pairs that include at least one recent memory, which keeps two old memories from being reconsidered every night.
The weekly full sweep clusters the whole store with no time filter and catches pairs of older memories that no daily run touched.
Generation Tracking
Consolidation tracks how many times a memory has been merged through generation tracking. This allows a memory to absorb a later duplicate while preventing runaway re-consolidation.
How Generations Work
Gen 0 ─┬─► Gen 1 ─┬─► Gen 2 ─┬─► Gen 3 ─┬─► Gen 4 ─┬─► Gen 5 (max)
│ │ │ │ │
Original First Re-consolidation continues...
memories merge| Generation | Description |
|---|---|
| Gen 0 | Original memories from extraction or manual creation |
| Gen 1 | First consolidation (merging original memories) |
| Gen 2-4 | Re-consolidation of already-consolidated memories |
| Gen 5 | Maximum - these memories won't be re-consolidated |
When memories are consolidated, the new memory's generation is calculated as max(source generations) + 1.
Re-Consolidation
Iris can re-consolidate already-merged memories. A Gen 1 memory "User prefers TypeScript over JavaScript" can absorb a later Gen 0 memory "User likes TypeScript better than JavaScript" to become Gen 2.
IMPORTANT
A memory above Gen 0 only merges with a memory that paraphrases it or is fully contained in it. Two consolidated memories never merge just because they're related.
Generation Limits
Generation 5 is the hard limit. Memories at that generation are excluded from clustering, and any cluster that still contains one is skipped before the LLM review. That check runs in both the queued cluster jobs and the synchronous --sync and --dry-run paths.
Running Consolidation
By default, consolidation dispatches jobs to the queue for parallel processing:
bash
# Queue batch for all users (default behavior)
php artisan iris:consolidate-memories
# Full sweep - process ALL memories, ignore days filter
php artisan iris:consolidate-memories --full
# Run synchronously (useful for debugging)
php artisan iris:consolidate-memories --sync
# Preview without changes (forces sync)
php artisan iris:consolidate-memories --dry-run
# Single user
php artisan iris:consolidate-memories --user=1
# Look back 7 days instead of days_lookback (ignored with --full)
php artisan iris:consolidate-memories --days=7
# Custom threshold for full sweep
php artisan iris:consolidate-memories --full --threshold=0.75Monitoring Health
Check the health of your memory consolidation system:
bash
# View consolidation statistics
php artisan iris:memory-health
# Filter by specific user
php artisan iris:memory-health --user=1The command shows:
- Generation distribution - Count of memories at each generation
- Original vs consolidated - Balance between new and merged memories
- Consolidation ratio - Percentage of memories that are consolidation results
- At max generation - Memories that won't be re-consolidated
- Eligible count - Memories available for future consolidation
Example output:
Memory Consolidation Health
Generation Count
Gen 0 (original) ............................................... 600
Gen 1 ............................................................ 400
Total memories ................................................. 1000
Original memories ............................................... 600
Consolidation results ........................................... 400
At max generation ................................................. 0
Consolidation ratio ........................................... 40.0%
Eligible for consolidation ..................................... 1000Processing Batches
When running in queue mode, the command returns a batch ID:
bash
php artisan iris:consolidate-memories
# Dispatched batch: 9c3b5f2a-...
# Process jobs (Horizon should already be running)
php artisan horizon
# Retry failed jobs in a batch
php artisan queue:retry-batch 9c3b5f2a-...Use Laravel Horizon for monitoring batch progress in a UI.
Scheduled Runs
Iris schedules consolidation in routes/console.php:
php
// Daily incremental at 3:00 AM
ScheduleFacade::command('iris:consolidate-memories')
->dailyAt('03:00')
->withoutOverlapping()
->runInBackground();
// Weekly full sweep on Sundays at 4:00 AM
ScheduleFacade::command('iris:consolidate-memories --full')
->weeklyOn(Schedule::SUNDAY, '04:00')
->withoutOverlapping()
->runInBackground();Job Architecture
Consolidation uses two job types for efficient processing:
ConsolidateUserMemories
Handles Phase 1 for a single user:
- Builds memory clusters (database queries only, no LLM calls)
- Dispatches
ConsolidateMemoryClusterjobs for each cluster - 300 second timeout
Clustering works on memory IDs. Postgres computes the pairwise similarities, so a full sweep never loads the store's embeddings into PHP; only the capped set of recent memories on a daily run is loaded with embeddings, to seed the older-neighbor search. Once clusters are formed, only their members are loaded, without embeddings. The pairwise query still grows with the square of the number of live memories, which is why the timeout is longer than the cluster jobs'. If a user's clustering fails on every retry, the error is logged with the user ID and whether it was a daily or full sweep.
ConsolidateMemoryCluster
Handles Phase 2 for a single cluster:
- Reconstructs the cluster from memory IDs, and drops it if any memory was already merged
- Skips clusters at the generation limit
- Calls the LLM to review and decide on merging
- Executes consolidation if approved and within the length cap
- 120 second timeout
- Rate-limited to prevent API overload
This architecture prevents timeout issues with large memory sets by processing clusters independently.
The merged memory's embedding is generated before the database transaction starts. Inside the transaction, Iris locks the source rows and checks that every one still exists and hasn't been merged elsewhere. If a source changed between review and commit, for example because extraction superseded it, nothing is written and the cluster counts as kept separate. Flagging the Truths built from the sources happens inside the same transaction as the merge.
Configuration
| Setting | Default | Description |
|---|---|---|
consolidation.similarity_threshold | 0.80 | Minimum similarity to cluster |
consolidation.days_lookback | 3 | Days of memories to consider for daily runs |
consolidation.max_memories_per_run | 100 | Cap on recent memories per daily run, and separately on older neighbors pulled in |
consolidation.neighbors_per_memory | 5 | Older memories pulled in per recent memory on daily runs |
consolidation.max_content_chars | 900 | Absolute cap on merged memory length |
consolidation.max_content_growth | 1.5 | Merged memory may be at most this multiple of the longest source |
consolidation.min_content_chars | 200 | Floor for the growth cap, so short memories can still merge |
consolidation.max_cluster_size | 5 | Max memories per cluster |
consolidation.min_cluster_size | 2 | Min memories to form a cluster |
consolidation.max_generation | 5 | Maximum consolidation generation |
consolidation.timeout | 120 | API timeout in seconds |
consolidation.provider | anthropic | Prism provider for merge decisions |
consolidation.model | claude-sonnet-5-5 | Model for merge decisions |
consolidation.jobs_per_minute | 10 | Rate limit for queued jobs |
Higher threshold (0.85+) sends fewer clusters to the LLM. Lower (0.75) sends more, and the merge policy still keeps related-but-different memories apart.
TIP
Set neighbors_per_memory to 0 to turn off the older-neighbor lookup. Daily runs then only compare memories inside the days_lookback window, and new duplicates of older memories wait for the weekly --full sweep.
Rate Limiting
Consolidation jobs are rate-limited to prevent overwhelming LLM APIs:
- Preventive: Jobs throttled to
jobs_per_minutelimit - Reactive: If rate limited by the API, jobs automatically retry after the limit resets using Prism's
resetsAttiming - Time-based retries: Jobs use
retryUntilwith a 2-hour window, allowing unlimited rate-limit releases without failing
Adjust consolidation.jobs_per_minute in config/iris-custom.php based on your API tier. The default of 10 jobs/minute leaves headroom for chat usage while consolidation runs.
NOTE
Only the ConsolidateMemoryCluster jobs are rate-limited since they make LLM calls. The parent ConsolidateUserMemories jobs run without throttling.