An agent's memory gets written by many hands. The chat, a CRM sync, a scraper, another agent. Sooner or later two of them disagree. One says the customer's office is in Denver, another says Chicago. One says the plan has a 14-day return window, another says the plan "does not allow returns".
Most memory layers store both. At recall time, whichever sentence is closest to the question comes back, and the agent now holds two beliefs that can't both be true. It doesn't know that, and neither do you.
This post shows how to catch those contradictions at write time, before the second fact is stored. The check runs inside the database: EMBED finds the existing memories on the same topic, a local NLI (natural language inference) model checks the new fact against them, and SQL sorts the batch into conflict, already-known and new. There's no LLM judge and no external API call.
We build SynapCores, and the examples are SynapCores SQL. Every query and every printed table below comes from recipe 036, first run on SynapCores 2.3.1 and re-run on 2.5.1, where all statements passed and every table came out identical.
We'll also cover the part most posts skip: the NLI model gives confident wrong answers when you use it naively, and the thresholds that are fine for flagging are too loose for deleting.
Why recall can't fix this later
Similarity search ranks by closeness, not by consistency. "The customer's office is in Denver" and "The customer's office is in Chicago" are almost the same sentence to an embedding model. Once both are stored, a question about the office can return either one, or both. Nothing at read time knows which is current.
So the cheapest place to catch a contradiction is when the fact is written. That needs two things: a way to find the memories the new fact is about, and a way to tell whether it agrees with them. Similarity does the first. An NLI model does the second. It reads two sentences and scores whether the second follows from the first (entailment), conflicts with it (contradiction), or neither.
Before you start: turn NLI on
NLI is off by default. Until you install and enable a model, every NLI call fails. On a fresh 2.5.1 install where NLI was never set up, the error is:
Inference error: NLI is disabled; install a model and enable NLI
If NLI is enabled but the model was never pulled, you get this instead:
Inference error: NLI model is not installed; pull or import it and retry
Install and enable the curated model (DeBERTa-v3-small, Apache-2.0, English, about a 577 MB download), then restart the engine:
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. GET /v1/ai/nli/models should report the model as ready.
If you don't have SynapCores yet, the Community Edition is free and self-hosted:
curl -fsSL https://get.synapcores.com | SYNAPCORES_REF=blog-nli-memory sh
Step 1: What the agent already believes
Memories here are plain rows with an embedding, so you can join on them. (SynapCores also has a built-in memory layer: REMEMBER, CURRENT, TRACE and RECALL in SQL, and /v1/memory/* over REST. Step 7 uses the lower-level MEMORY_RECALL function. A table makes the batch check easiest to see.)
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 new 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.'));
We know the right answer up front. Facts 101, 104 and 105 conflict with a stored memory. Fact 102 restates one. Facts 103 and 106 are new.
Step 3: Look at the scores before you pick a threshold
Before writing the check, list every incoming/memory pair the NLI model scores as a contradiction (above 0.6), next to 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;
The result (the "reality" column is ours):
| 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. Three are real.
This is the most important table in the post. An NLI model scores pairs of sentences. Hand it two sentences about different things and it often still says "contradiction", with high confidence. The cello fact "contradicts" all four memories at 0.996 or higher. The contradiction score can't separate real conflicts from false ones here.
Similarity can. The real conflicts sit between 0.50 and 0.74. The false ones are at 0.41 or below. We set the floor at 0.45, inside that gap. That number was read off this data. It isn't a universal constant, and the gap is narrow, so run this query on a sample of your own memories before you pick yours.
Step 4: The trap: check against every memory
NLI_ANCHORS collects a group's memories into an evidence array, and NLI_VERIFY checks the new fact against all of them. Here's the naive version, with no similarity gate:
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;
| 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 that scores as a "contradiction" vetoes the whole fact. A memory that rejects everything new can't learn anything.
Step 5: The fix: one gated query for the whole batch
Add the similarity floor, and use a LEFT JOIN so a fact with no related memory comes back as NEW instead of dropping out:
SELECT i.id, i.source,
CASE g.verdict
WHEN 'LIE' THEN 'CONFLICT'
WHEN 'TRUTH' THEN 'ALREADY_KNOWN'
ELSE 'NEW'
END AS status,
g.conflicts_with
FROM recipe_memcheck_incoming i
LEFT JOIN (
SELECT c.id AS cand_id,
JSON_UNQUOTE(JSON_EXTRACT(NLI_VERIFY('nli-default', c.fact, NLI_ANCHORS(m.fact)),
'$.verdict')) AS verdict,
JSON_UNQUOTE(JSON_EXTRACT(NLI_VERIFY('nli-default', c.fact, NLI_ANCHORS(m.fact)),
'$.violated_anchor')) AS conflicts_with
FROM recipe_memcheck_incoming c
CROSS JOIN recipe_memcheck_memories m
WHERE COSINE_SIMILARITY(c.embedding, m.embedding) > 0.45
GROUP BY c.id, c.fact
) g ON g.cand_id = i.id
ORDER BY i.id;
| id | source | status | conflicts_with |
|---|---|---|---|
| 101 | chat | CONFLICT | The customer prefers to be contacted by email, never by phone. |
| 102 | crm-sync | ALREADY_KNOWN | |
| 103 | webinar-tool | NEW | |
| 104 | scraper | CONFLICT | The customer's office is in Denver. |
| 105 | agent-b | CONFLICT | The customer is on the Aurora plan, which includes a 14-day return window. |
| 106 | chat | NEW |
All six land where they should, and each conflict names the memory it collides with. Two details:
- Fact 103 (the webinar) cleared the floor against one memory, "office is in Denver", at similarity 0.487. Its contradiction score there was 0.488, below the 0.6 threshold, so
NLI_VERIFYreturnedUNVERIFIED_PLAUSIBLE, which maps toNEW. - Fact 106 (the cello) cleared no memory at all. The
LEFT JOINreturns a NULL verdict, which also maps toNEW.
One syntax note from the recipe: put the similarity condition in WHERE over a CROSS JOIN, as shown. On 2.3.1, the same condition in JOIN … ON COSINE_SIMILARITY(...) > 0.45 returned zero rows. On 2.5.1 both forms return the same pairs, so the WHERE form is the one that works on both versions.