Package com.tnsai.memory.advanced
Class StalenessDetector
java.lang.Object
com.tnsai.memory.advanced.StalenessDetector
Detects contradictions between memory entries via Jaccard similarity
on token sets.
When two entries share a high proportion of tokens (above the configured threshold), they are flagged as potential contradictions. This is useful for identifying outdated facts that conflict with newer information.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault similarity threshold for contradiction detection. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a detector with the default threshold of 0.9.StalenessDetector(double threshold) Creates a detector with a custom threshold. -
Method Summary
Modifier and TypeMethodDescriptionList<MemoryEntry[]> detectAllContradictions(Collection<MemoryEntry> entries) Detects all contradiction pairs within a collection.List<MemoryEntry[]> detectContradictions(MemoryEntry entry, Collection<MemoryEntry> candidates) Detects entries in the collection that potentially contradict the given entry.doubleReturns the configured threshold.
-
Field Details
-
DEFAULT_THRESHOLD
public static final double DEFAULT_THRESHOLDDefault similarity threshold for contradiction detection.- See Also:
-
-
Constructor Details
-
StalenessDetector
public StalenessDetector()Creates a detector with the default threshold of 0.9. -
StalenessDetector
public StalenessDetector(double threshold) Creates a detector with a custom threshold.- Parameters:
threshold- Jaccard similarity threshold in (0, 1]
-
-
Method Details
-
detectContradictions
public List<MemoryEntry[]> detectContradictions(MemoryEntry entry, Collection<MemoryEntry> candidates) Detects entries in the collection that potentially contradict the given entry.Returns pairs where the first element is the entry being checked and the second is the contradicting entry from the collection.
- Parameters:
entry- the entry to check againstcandidates- the collection to search for contradictions- Returns:
- list of contradicting pairs [entry, contradictingCandidate]
-
detectAllContradictions
Detects all contradiction pairs within a collection.- Parameters:
entries- the entries to check pairwise- Returns:
- list of contradicting pairs
-
threshold
public double threshold()Returns the configured threshold.
-