Skip to content

πŸ“Š Fact Clustering & Auto-SummarizationΒ #220

Closed

Description

@hurttlocker

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

  1. 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
  2. Create new summary facts with combined provenance
  3. 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 cluster

Maintenance Schedule

Designed to run monthly: cortex summarize --llm google/gemini-3-flash

Files to Create/Modify

  • internal/extract/summarize.go β€” summarization logic
  • internal/extract/summarize_test.go β€” tests (mock LLM)
  • internal/search/prompts/summarize_cluster.txt β€” prompt template
  • cmd/cortex/main.go β€” add cortex summarize subcommand
  • internal/store/fact_store.go β€” add CreateSummaryFact() and MarkSuperseded() 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 summarize subcommand works with both models
  • --dry-run shows consolidation plan without applying
  • Summary facts include combined provenance from all originals
  • Superseded facts are marked, not deleted
  • --min-cluster-size prevents summarizing small clusters
  • Integrates with v0.8.0 clustering infrastructure
  • Benchmark results documented in PR
  • All existing tests pass

Dependencies

Estimated Cost

~$0.05/cluster Γ— 100 clusters = **$5.00/sweep** (monthly batch job)

Activity

  1. added
    v0.9.0
    llm
    benchmark
    on Feb 24, 2026
  2. hurttlocker commented on Feb 24, 2026

    @hurttlocker
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    benchmarkllmv0.9.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions