Objective
An agent's memory fills up from many writers: the chat, a CRM sync, a scraper, another agent. Sooner or later two of them disagree. The office is in Denver and in Chicago. The plan has a 14-day return window, and also "does not allow returns". Most memory layers store both facts, and recall returns whichever one is most similar to the question. The agent now holds two contradicting beliefs and doesn't know it.
This recipe checks a batch of incoming facts before they're written. A single SQL statement does three things that usually need three systems:
EMBED+COSINE_SIMILARITYpairs each incoming fact with the existing memories on the same topic, and only those.NLI_VERIFY(a local NLI model running inside the engine) checks the incoming fact against those memories.- SQL sorts the batch into
CONFLICT(with the memory it conflicts with),ALREADY_KNOWNandNEW. Only safe facts are stored. Conflicts go to a review queue.
No LLM judge or external API is involved, and the check runs where the memory
lives. Self-Consistent Agent Memory
covers the single-fact version on MEMORY_STORE. This recipe does a whole batch
and adds the similarity gate, which a batch needs (Step 4 shows why).
Before you start: NLI is off by default
The NLI functions need a model installed and enabled. Until you enable it, every NLI call fails with:
Inference error: NLI is disabled; install a model and enable NLI
Install and enable the curated model (DeBERTa-v3-small, Apache-2.0, English, ~577 MB download), then restart:
synapcores --config /etc/synapcores/gateway.toml pull nli-default
synapcores --config /etc/synapcores/gateway.toml models enable-nli nli-default
For Docker or environment-driven installs, set AIDB_NLI_ENABLED=1 and
AIDB_NLI_MODEL=nli-default at startup. Check that GET /v1/ai/nli/models
reports the model as ready. See
Semantic Claim Verification
for air-gapped installs.
Step 1: What the agent already believes
Memories are rows with an embedding, so you can join on them.
CREATE TABLE IF NOT EXISTS recipe_memcheck_memories (
id INT PRIMARY KEY,
fact TEXT,
embedding VECTOR(384)
);
INSERT INTO recipe_memcheck_memories (id, fact, embedding) VALUES
(1, 'The customer prefers to be contacted by email, never by phone.',
EMBED('The customer prefers to be contacted by email, never by phone.')),
(2, 'The customer is on the Aurora plan, which includes a 14-day return window.',
EMBED('The customer is on the Aurora plan, which includes a 14-day return window.')),
(3, 'The customer manages procurement for a mid-size logistics company.',
EMBED('The customer manages procurement for a mid-size logistics company.')),
(4, 'The customer''s office is in Denver.',
EMBED('The customer''s office is in Denver.'));
Step 2: A batch of incoming facts from different writers
CREATE TABLE IF NOT EXISTS recipe_memcheck_incoming (
id INT PRIMARY KEY,
source TEXT,
fact TEXT,
embedding VECTOR(384)
);
INSERT INTO recipe_memcheck_incoming (id, source, fact, embedding) VALUES
(101, 'chat', 'The customer asked us to call them by phone from now on.',
EMBED('The customer asked us to call them by phone from now on.')),
(102, 'crm-sync', 'The customer works in logistics procurement.',
EMBED('The customer works in logistics procurement.')),
(103, 'webinar-tool', 'The customer attended the October product webinar.',
EMBED('The customer attended the October product webinar.')),
(104, 'scraper', 'The customer''s office is in Chicago.',
EMBED('The customer''s office is in Chicago.')),
(105, 'agent-b', 'The customer''s plan does not allow returns.',
EMBED('The customer''s plan does not allow returns.')),
(106, 'chat', 'The customer is learning to play the cello.',
EMBED('The customer is learning to play the cello.'));
Facts 101, 104 and 105 conflict with an existing memory. Fact 102 restates one. Facts 103 and 106 are new.
Step 3: Look at the numbers before choosing thresholds
List every incoming/memory pair that the NLI model scores as a contradiction (above 0.6), with its topic similarity:
SELECT i.id AS incoming, m.id AS memory,
ROUND(COSINE_SIMILARITY(i.embedding, m.embedding), 3) AS similarity,
ROUND(CAST(JSON_EXTRACT(NLI_CLASSIFY('nli-default', m.fact, i.fact),
'$.scores.contradiction') AS DOUBLE), 3) AS contradiction
FROM recipe_memcheck_incoming i
CROSS JOIN recipe_memcheck_memories m
WHERE CAST(JSON_EXTRACT(NLI_CLASSIFY('nli-default', m.fact, i.fact),
'$.scores.contradiction') AS DOUBLE) > 0.6
ORDER BY similarity DESC;
Observed on 2.3.1 with nli-default:
| incoming | memory | similarity | contradiction | reality |
|---|---|---|---|---|
| 104 | 4 | 0.740 | 0.999 | real conflict (office city) |
| 105 | 2 | 0.524 | 1.000 | real conflict (returns) |
| 101 | 1 | 0.502 | 0.999 | real conflict (contact channel) |
| 104 | 2 | 0.408 | 0.760 | false: office city vs plan |
| 103 | 3 | 0.366 | 0.888 | false: webinar vs procurement job |
| 106 | 4 | 0.235 | 0.997 | false: cello vs office |
| 106 | 3 | 0.228 | 1.000 | false: cello vs procurement job |
| 106 | 1 | 0.169 | 0.999 | false: cello vs contact channel |
| 106 | 2 | 0.132 | 0.996 | false: cello vs plan |
Nine pairs score as contradictions, and only three of them are real. The NLI model scores pairs of sentences. Give it two sentences about different things and it often still returns a confident "contradiction": the cello fact "contradicts" all four memories at 0.996 or higher. Contradiction scores can't separate real from false here, but similarity can. Real conflicts sit at 0.50–0.74, and false ones at 0.41 or less. This recipe sets the floor at 0.45, inside that gap. It's a value read from this data, not a universal constant, so measure your own memories the same way.
Step 4: The trap: verify against every memory
NLI_ANCHORS collects a group's memories into an evidence array, and
NLI_VERIFY checks the incoming fact against them. Without a similarity gate,
each incoming fact is checked against all memories:
SELECT i.id, i.source,
JSON_UNQUOTE(JSON_EXTRACT(NLI_VERIFY('nli-default', i.fact, NLI_ANCHORS(m.fact)),
'$.verdict')) AS verdict,
JSON_UNQUOTE(JSON_EXTRACT(NLI_VERIFY('nli-default', i.fact, NLI_ANCHORS(m.fact)),
'$.violated_anchor')) AS conflicts_with
FROM recipe_memcheck_incoming i
CROSS JOIN recipe_memcheck_memories m
GROUP BY i.id, i.source, i.fact
ORDER BY i.id;
Observed:
| id | source | verdict | conflicts_with |
|---|---|---|---|
| 101 | chat | LIE | The customer prefers to be contacted by email, never by phone. |
| 102 | crm-sync | TRUTH | |
| 103 | webinar-tool | LIE | The customer manages procurement for a mid-size logistics company. |
| 104 | scraper | LIE | The customer's office is in Denver. |
| 105 | agent-b | LIE | The customer is on the Aurora plan, which includes a 14-day return window. |
| 106 | chat | LIE | The customer manages procurement for a mid-size logistics company. |
Five of six facts are rejected, including the webinar and the cello, which
conflict with nothing. NLI_VERIFY gives contradiction precedence, so one
unrelated memory scored as a "contradiction" vetoes the fact. A memory
that rejects everything new can't learn.