Repository navigation
Closed
Description
Summary
Periodically cluster related facts and generate consolidated summaries β deduplicating without losing nuance. Reduces search noise and compresses the fact corpus.
Priority: MEDIUM IMPACT β nice-to-have for long-term maintenance, improves search signal-to-noise.
Spec
New File: internal/extract/summarize.go
type ClusterSummary struct {
ClusterID int64
FactIDs []int64
Summary string // consolidated fact text
FactCount int // number of facts merged
Provenance []string // sources from all merged facts
SupersededIDs []int64 // facts replaced by this summary
}
func SummarizeClusters(ctx context.Context, llm llm.Provider, clusters []FactCluster) ([]ClusterSummary, error)Leverages existing clustering from v0.8.0 (internal/extract/cluster.go):
- v0.8.0 clusters facts by topic (BM25 similarity)
- v0.9.0 adds: within each cluster, identify redundant/overlapping facts β LLM generates one authoritative summary
Summarization Logic
- For each cluster with >5 facts:
- Send all facts to LLM
- Ask: "Consolidate these into the minimum set of non-redundant facts"
- LLM returns: consolidated facts + which originals each replaces
- Create new summary facts with combined provenance
- Mark superseded originals (dont delete β keep for audit trail)
CLI Integration
cortex summarize --dry-run # show what would be consolidated
cortex summarize --llm google/gemini-3-flash # run summarization
cortex summarize --min-cluster-size 10 # only summarize large clusters
cortex summarize --cluster <id> # summarize specific clusterMaintenance Schedule
Designed to run monthly: cortex summarize --llm google/gemini-3-flash
Files to Create/Modify
internal/extract/summarize.goβ summarization logicinternal/extract/summarize_test.goβ tests (mock LLM)internal/search/prompts/summarize_cluster.txtβ prompt templatecmd/cortex/main.goβ addcortex summarizesubcommandinternal/store/fact_store.goβ addCreateSummaryFact()andMarkSuperseded()methods
Benchmark Test Spec
Test Corpus
Take 5 real clusters from the live Cortex DB (after v0.8.0 clustering):
- 1 large cluster (>50 facts, e.g., "ORB strategy")
- 2 medium clusters (10-30 facts)
- 2 small clusters (5-10 facts)
Metrics (per cluster, per model)
| Metric | Target |
|---|---|
| Latency (per cluster) | <10s |
| Tokens in | <3000 |
| Tokens out | <1000 |
| Cost per cluster | <$0.05 |
| Compression ratio | β₯2x (50 facts β β€25 summary facts) |
| Information loss (0-5 rubric) | β€1.0 avg |
| Summary quality (0-5 rubric) | β₯3.5 avg |
Information Loss Rubric
- 0: Zero information lost β perfect consolidation
- 1: Trivial details lost (timestamps, formatting)
- 2: Minor context lost but core facts preserved
- 3: Some meaningful detail lost
- 4: Important information dropped
- 5: Critical facts missing from summary
Benchmark Script
Create scripts/benchmark_summarize.go:
- Runs 5 clusters through both models
- Human rates information loss + quality
- Measures compression ratio
- Outputs: cost, latency, compression, quality per model
Acceptance Criteria
-
cortex summarizesubcommand works with both models -
--dry-runshows consolidation plan without applying - Summary facts include combined provenance from all originals
- Superseded facts are marked, not deleted
-
--min-cluster-sizeprevents summarizing small clusters - Integrates with v0.8.0 clustering infrastructure
- Benchmark results documented in PR
- All existing tests pass
Dependencies
- π§ Query Expansion (Pre-Search)Β #216 (Query Expansion) β uses
internal/llm/adapter - v0.8.0 clustering (feat(graph): Topic clustering with cohesion scores at import timeΒ #212) β provides cluster infrastructure
Estimated Cost
~$0.05/cluster Γ 100 clusters = **$5.00/sweep** (monthly batch job)
Activity
feat(extract): add LLM-powered fact cluster summarization (#220)
feat(extract): add LLM-powered fact cluster summarization (#220)
hurttlocker commentedon Feb 24, 2026
Already implemented in PR #224 (commit abf718d). Full summarize pipeline: internal/extract/summarize.go (321 lines), 9 tests passing, CLI command
cortex summarize --llm <model> [--dry-run] [--min-cluster-size N]. Integrates with v0.8.0 clustering infrastructure.release: v0.9.0 β LLM-Augmented Intelligence