Expand description
G29 Passo 4: preservation checks (Jaccard trigram) for LLM-enriched bodies. Preservation checks for LLM-enriched memory bodies (G29 Passo 4).
When a language model rewrites a memory body, the operator must be protected against silent hallucination: the LLM may invent facts, drop key terms, or drift semantically far from the source. This module provides a lightweight, deterministic similarity metric that runs locally without any model call, so the gate can be enforced before the enriched body touches persistent storage.
The default metric is a normalised trigram-Jaccard similarity computed
on the union of set_a and set_b. The score is in [0.0, 1.0],
where 1.0 means the two inputs share every trigram and 0.0 means
they share none. The threshold default of 0.7 follows the gap G29
specification, with --preserve-threshold <F> letting operators tune
it per workload.
§Examples
use sqlite_graphrag::preservation::{jaccard_similarity, PreservationVerdict};
let score = jaccard_similarity("the quick brown fox", "the quick red fox");
assert!(score > 0.5);
let verdict = PreservationVerdict::evaluate("orig body", "rewritten body", 0.7);
assert!(matches!(verdict, PreservationVerdict::Preserved { .. }));Enums§
- Preservation
Verdict - Outcome of a preservation evaluation against a configurable threshold.
Functions§
- jaccard_
similarity - Computes the trigram-Jaccard similarity between two strings.