Class StalenessDetector

java.lang.Object
com.tnsai.memory.advanced.StalenessDetector

public final class StalenessDetector extends Object
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 Details

    • DEFAULT_THRESHOLD

      public static final double DEFAULT_THRESHOLD
      Default 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 against
      candidates - the collection to search for contradictions
      Returns:
      list of contradicting pairs [entry, contradictingCandidate]
    • detectAllContradictions

      public List<MemoryEntry[]> detectAllContradictions(Collection<MemoryEntry> entries)
      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.