Repository navigation
Description
Motivation
Issue #346 (pattern-based auto-edges) is closed and ships with [[ref]], @tag, ^id patterns. This works for structured content but misses implicit similarity — memories that are semantically related without explicit references.
Currently, two memories about the same topic written by different agents have zero graph connection unless someone manually adds [[ref]] patterns.
Real-world example (from Hermes, 77 memories)
Memory A [default]: "TrapFall repo BELUM dibuat. Target: codecoradev/..."
Memory B [hermes-knowledge]: "TrapFall repo BELUM dibuat. Target: codecoradev/..."
Cosine: 0.9145 — nearly identical, but no edge exists
With 77 memories, 2 pairs exceed cosine 0.90 and 11 pairs exceed 0.85. All currently invisible to graph traversal and recall scoring.
Proposal
1. Cosine-based Auto-Link on remember()
After embedding a new memory, compute cosine similarity against existing memories and auto-create SIMILAR_TO edges.
fn auto_link_cosine(&self, new_id: &str, embedding: &[f32]) -> Result<()> {
let candidates = self.vector_index.search(embedding, top_k=20)?;
for (mem_id, score) in candidates {
if score >= config.auto_link_threshold {
self.insert_graph_edge(
source = new_id,
target = mem_id,
relation = "similar_to",
weight = score as f64,
);
}
if score >= config.dedup_threshold {
self.insert_graph_edge(
source = new_id,
target = mem_id,
relation = "possible_duplicate",
weight = score as f64,
);
}
}
}2. Dedup Detection + Auto-Merge
When cosine >= dedup_threshold (0.95), flag as duplicate. If auto-merge enabled, merge:
Merge logic:
- Pick "best" memory (longest content, highest access_count)
- Migrate tags + metadata from loser → winner
- Create edge: loser
supersedes_towinner (bidirectional) - Mark loser as deprecated
Config:
[graph]
auto_link_enabled = true
auto_link_threshold = 0.90 # cosine >= 0.90 → SIMILAR_TO edge
dedup_threshold = 0.95 # cosine >= 0.95 → possible_duplicate
auto_merge = false # flag only by default (safe)3. New CLI Commands
uteke graph dedup # list possible_duplicate edges
uteke graph dedup --merge # auto-merge all flagged pairs
uteke graph dedup --dry-run # preview merge without executingValidation (Real Data)
Tested on 77 memories (2,926 pairs) from a production Hermes instance:
| Threshold | Pairs | Examples |
|---|---|---|
| >= 0.95 | 0 | No duplicates (clean data) |
| >= 0.90 | 2 | True cross-namespace duplicates |
| >= 0.85 | 11 | Related but distinct memories |
| >= 0.80 | 14 | Evolution of same topic (v0.3 → v0.5) |
| >= 0.75 | 23 | Starts noisy (join messages) |
Conclusion: Threshold 0.90 produces clean, valid edges. 0.95 is safe for dedup (no false positives in current data).
Acceptance Criteria
remember()auto-createsSIMILAR_TOedges when cosine >= thresholdremember()auto-createspossible_duplicateedges when cosine >= dedup thresholdgraph deduplists all possible_duplicate edgesgraph dedup --mergemerges flagged pairs (content, tags, metadata)- Config
[graph]section controls all thresholds and toggles - Zero regression: existing
[[ref]]pattern edges (feat: typed auto-edges — self-wiring knowledge graph on every remember() #346) still work - Unit tests: threshold boundary, empty DB, identical memories, cross-namespace
- Benchmark:
remember()latency increase < 50ms for 1K memories
Out of Scope
- Graph-augmented recall reranking (see feat: graph-augmented RAG reranking — fuse graph signals into recall scoring #378 — already closed, verify if live in v0.2.0)
- Community detection / clustering (future)
- LLM-based edge extraction
- Graph visualization UI
Dependencies
- feat: typed auto-edges — self-wiring knowledge graph on every remember() #346 (CLOSED) — graph_edges table + BFS traversal ✅
- feat: graph-augmented RAG reranking — fuse graph signals into recall scoring #378 (CLOSED) — graph RAG reranking ✅ (verify live status)
usearch— already in use for vector search
Open Questions
- Should auto-link be opt-in or default-on? (Proposal: default-on, configurable)
- Should
possible_duplicateedges be bidirectional? (Proposal: yes) - Performance: cosine against ALL memories vs top-K candidates? (Proposal: top-20 from usearch, then filter by threshold)
Activity
feat(#401): cosine-based auto-linking + dedup detection on remember() (…
ajianaz commentedon Jun 21, 2026
Implemented in #421. auto_link_cosine() creates similar_to (>=0.80) and possible_duplicate (>=0.92) edges on every remember().
release: v0.3.0 — Graph RAG (#428)
feat(#401): cosine-based auto-linking + dedup detection on remember() (…
release: v0.3.0 — Graph RAG (#428)