Repository navigation
Closed
Description
Summary
When cortex conflicts detects contradictory facts, an LLM evaluates recency, source authority, and context to auto-resolve them — superseding losers and reinforcing winners.
Priority: HIGH IMPACT — cleans up existing fact corpus, improves search quality downstream.
Spec
New File: internal/extract/resolve.go
type ConflictResolution struct {
WinnerID int64
LoserID int64
Reason string
Confidence float64
Action string // "supersede", "merge", "flag-human"
}
func ResolveConflicts(ctx context.Context, llm llm.Provider, conflicts []ConflictPair) ([]ConflictResolution, error)Resolution logic:
- Gather both facts + their metadata (source, timestamp, reinforcement count)
- Send to LLM with evaluation prompt:
- Which is newer? (newer usually wins)
- Which source is more authoritative? (MEMORY.md > daily note > import)
- Is this a genuine update or error?
- Can they be merged into one better fact?
- LLM returns structured JSON:
{winner, loser, reason, confidence, action} - If confidence < 0.7 → flag for human review instead of auto-resolving
CLI Integration
cortex conflicts --resolve # detect + auto-resolve
cortex conflicts --resolve --llm openai/gpt-5.1-codex-mini
cortex conflicts --resolve --dry-run # show what would be resolved, dont act
cortex conflicts # unchanged (just lists conflicts)Actions
- supersede: Mark loser fact as superseded, boost winner confidence
- merge: Create a new fact combining both, supersede both originals
- flag-human: Print to stdout for manual review (low confidence)
Files to Create/Modify
internal/extract/resolve.go— resolution logicinternal/extract/resolve_test.go— tests (mock LLM)internal/search/prompts/resolve_conflict.txt— prompt templatecmd/cortex/main.go— add--resolveand--dry-runflags to conflicts commandinternal/store/fact_store.go— addSupersedeFact()method
Benchmark Test Spec
Test Corpus
Generate 20 synthetic conflict pairs covering:
- Temporal updates (old value → new value)
- Source authority (MEMORY.md vs daily note)
- Genuine contradictions (needs judgment)
- Near-duplicates (merge candidates)
- Ambiguous cases (should flag for human)
Metrics (per conflict pair, per model)
| Metric | Target |
|---|---|
| Latency (per pair) | <2s |
| Tokens in | <300 |
| Tokens out | <100 |
| Cost per resolution | <$0.005 |
| Accuracy (vs human judgment) | ≥85% |
| Appropriate flag rate | Flags ≥80% of ambiguous cases |
Accuracy Rubric
- Correct: Same decision a human would make
- Acceptable: Reasonable but not optimal (e.g., superseded when merge was better)
- Wrong: Kept the wrong fact or auto-resolved what should be flagged
- Dangerous: Deleted correct information
Benchmark Script
Create scripts/benchmark_resolve.go:
- Runs all 20 pairs against both models
- Records latency, tokens, cost, decision
- Compares to pre-labeled human judgments
- Outputs accuracy matrix + cost comparison
Acceptance Criteria
-
--resolveflag oncortex conflictsworks -
--dry-runshows resolutions without applying - Confidence threshold (0.7) gates auto-resolution
-
SupersedeFact()properly marks losers - Merge creates new fact with provenance from both originals
- Benchmark results documented in PR
- All existing tests pass
Dependencies
- 🧠 Query Expansion (Pre-Search) #216 (Query Expansion) — uses the
internal/llm/adapter created there
Estimated Cost
~$0.005/conflict × 50 conflicts/week = **$0.10/month** (weekly batch job)
Activity
feat(observe): LLM-powered conflict resolution (#217)
release: v0.9.0 — LLM-Augmented Intelligence