Contradiction Detection
Reeflect includes sophisticated contradiction detection capabilities to identify when new information conflicts with existing memories. This helps maintain consistency and accuracy in the memory system.
How Contradiction Detection Works
When new information is added to the memory system, it can automatically check for potential contradictions with existing memories:
- New memory content is compared against semantically similar existing memories
- The system analyzes whether the new content contradicts or conflicts with existing memories
- Detected contradictions are scored by confidence level
- The system can either flag contradictions for review or automatically resolve them
Detecting Contradictions
# Check if new information contradicts existing memories
contradictions = memory.detect_contradictions(
new_memory="The user prefers light mode for all applications.",
namespace="user_preferences"
)
if contradictions:
print("Contradictions detected:")
for contradiction in contradictions:
print(f"- Conflicts with memory {contradiction['memory_id']}: {contradiction['reason']}")
print(f" Confidence: {contradiction['confidence']}")
# You can also check an existing Memory object
existing_memory = memory.retrieve("memory-id-123")
new_memory = Memory(
content="The user is allergic to dairy.",
namespace="user_health",
importance=0.9
)
contradictions = memory.detect_contradictions(
new_memory=new_memory,
namespace="user_health"
)
Automatic Contradiction Resolution
For applications that need automatic handling of contradictions, you can use the contradiction resolver:
from reeflect.intelligence.contradictions import ContradictionResolver
# Create a contradiction resolver
resolver = ContradictionResolver(memory_system)
# Resolve contradictions with a new memory
resolution = resolver.resolve(
new_memory="The user now prefers dark mode for all applications.",
namespace="user_preferences",
resolution_strategy="newest_wins", # Options: newest_wins, oldest_wins, highest_confidence, manual
add_relationship=True # Add CONTRADICTS relationship between memories
)
print(f"Resolution action: {resolution['action']}")
print(f"Affected memories: {resolution['affected_memories']}")
print(f"Resolution explanation: {resolution['explanation']}")
Resolution Strategies
Strategy | Description | Use Cases |
---|---|---|
newest_wins | Prioritize the most recent information | User preference changes, updated facts |
oldest_wins | Preserve original information over new data | Core preferences, fundamental facts |
highest_confidence | Choose the memory with highest confidence score | Factual information, verified data |
manual | Flag for manual review without automatic resolution | Critical information, sensitive data |
Best Practice
For user preference data, newest_wins
is usually the best strategy as preferences change over time. For health information or critical facts, consider using manual
resolution to ensure accuracy.
Next Steps
Explore Memory Analytics to learn how to gain insights into your memory system's performance and usage patterns.