Conversation
…gmentation, recall recency Add two computable diagnostic signals for context management quality: - temporalCnorm(): normalized variance of relative-existence weights over message timestamps. Measures attention imbalance [0,1] — 0 is uniform distribution, 1 is dominated by distant past. Logged per-distillation under LORE_DEBUG=1. - compressionRatio(): k/√N ratio where k=distilled tokens, N=source tokens. Values < 1.0 signal aggressive/likely-lossy compression. Logged per-distillation under LORE_DEBUG=1. Enhance detectSegments() to prefer splitting at the largest inter-message time gap (≥3x median) when oversized, respecting natural conversation boundaries instead of arbitrary count-based chunking. Falls back to count-based splitting when timestamps are uniform. Add recency-biased RRF list for temporal recall results. Same candidates re-ranked by created_at (newest first), fused alongside BM25 via existing RRF — messages that are both semantically relevant AND recent get a natural score boost. Inspired by D7x7z49/llm-context-idea research notes on temporal clustering and compression boundaries. 582 tests pass, 0 fail. Build clean across all 3 packages.
5 tasks
BYK
added a commit
that referenced
this pull request
May 2, 2026
…12) (#116) ## Summary Persist `r_compression` and `c_norm` context health metrics directly in the `distillations` table, replacing the `LORE_DEBUG=1`-gated log lines that were invisible by default. ## Why The diagnostic logging added in #113 used `log.info()` which is suppressed unless `LORE_DEBUG=1` — making the diagnostics effectively invisible in normal operation. Storing metrics in the DB makes them queryable retroactively without env vars or log parsing. ## Changes - **Schema v12**: Two nullable `REAL` columns (`r_compression`, `c_norm`) on `distillations` - **storeDistillation()**: Accepts optional `rCompression` and `cNorm` params, writes to new columns - **distillSegment()**: Computes metrics *before* `storeDistillation()` (was after), passes them in - **loadForSession() + loadGen0()**: SQL and row types updated to include new columns - **Distillation type**: `r_compression: number | null` and `c_norm: number | null` - **Tests**: 3 new tests verifying NULL for legacy rows, correct values for new rows, mixed results - **opencode test helper**: `restoreDistillationTables()` updated for schema parity ## Verification - 586 tests pass, 0 fail - Build clean across all 3 packages - Existing rows get NULL (no backfill needed) - Migration is two `ALTER TABLE ADD COLUMN` statements (idempotent for new DBs, safe for existing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add two computable diagnostic signals and two behavioral improvements for Lore's context management, inspired by D7x7z49/llm-context-idea research notes on temporal clustering and compression boundaries.
Diagnostic signals (Phase 1)
temporalCnorm(timestamps, now)intemporal.ts: Normalized variance of relative-existence weights over message timestamps. Returns [0, 1] — 0 means uniform attention distribution, 1 means dominated by distant past. Lightweight (pure arithmetic overcreated_atvalues we already store).compressionRatio(distilledTokens, sourceTokens)indistillation.ts:k/√Nratio where k = distilled tokens, N = source tokens. Values < 1.0 signal aggressive/likely-lossy compression. Based on the "square root boundary" heuristic — unvalidated, used as observation-only diagnostic.Both are logged per-distillation segment under
LORE_DEBUG=1:Time-gap-aware segmentation (Phase 2)
detectSegments()now prefers splitting at the largest inter-message time gap (≥ 3× median gap) instead of purely at count boundaries. Falls back to count-based splitting when timestamps are uniform (existing behavior preserved).Recall recency biasing (Phase 3)
Changes
packages/core/src/temporal.tstemporalCnorm()exportpackages/core/src/distillation.tscompressionRatio()export, diagnostic logging indistillSegment(), time-gap-awaredetectSegments()(now exported)packages/core/src/recall.tspackages/core/test/context-health.test.tstemporalCnorm,compressionRatio, and recency RRF behaviorpackages/core/test/distillation.test.tsdetectSegmentstime-gap splittingVerification