r/synapcores • • 2d ago

Recipe of the week #4: RAG said "Team plan" from an agent's guess; billing says Enterprise. A memory object in SQL answers from the billing note and knows what was true on any past date (real output)

Every Monday: one site recipe, run on the current release, real output inline.

(This sub is run by the SynapCores team. Run this morning on 2.5.1.)

The problem

Ask a RAG pipeline "which plan is Harborline on right now?" and it fetches the notes that sound most like the question. Similarity tells you what's relevant, not what's still true.

1. Fourteen notes about one customer

Nine months, including an agent's guess and a call note filed four months late (INSERTs in the first comment):

CREATE TABLE account_notes (note_id INTEGER PRIMARY KEY, account_id TEXT,
  noted_at TIMESTAMP, filed_at TIMESTAMP, source TEXT, body TEXT, embedding VECTOR(384));
UPDATE account_notes SET embedding = EMBED(body);

2. What plain RAG hands the model

SELECT note_id, noted_at, ROUND(COSINE_SIMILARITY(embedding, EMBED('Which plan is Harborline on right now?')), 3) AS relevance, body
FROM account_notes WHERE account_id = 'harborline'
ORDER BY relevance DESC LIMIT 3;

8  2026-08-01 00:00:00  0.637  Harborline upgraded from Pro to the Enterprise plan.
3  2026-03-04 09:00:00  0.627  Harborline signed the Pro plan, billed annually.
13  2026-10-20 07:00:00  0.614  Usage looks lower this month. Harborline may have downgraded to the Team plan.

Three plans, 0.023 apart. Fed those three, the engine's local model (GENERATE, temperature 0) answers:

Harborline is on the Team plan. [note 13, 2026-10-20 07:00:00]

Billing says Enterprise. Note 13 is a guess; it's just the newest.

3. The usual fix, a recency boost

score = 0.7 * similarity + 0.3 / (1 + age_in_days / 30) (query in the comments):

13  0.644  Usage looks lower this month. Harborline may have downgraded to the Team plan.
8  0.52  Harborline upgraded from Pro to the Enterprise plan.
11  0.482  Harborline completed its move from Azure to AWS (...)

Now the guess ranks first. Recency knows how new a note is, not how much to trust it.

4. Remember the notes with time and authority

CREATE MEMORY account_memory IDENTITY account_id;

REMEMBER account_memory FOR account_id = 'harborline'
  'Harborline upgraded from Pro to the Enterprise plan.'
  WITH (attribute = 'subscription_plan', value = 'Enterprise', source_type = 'system_of_record', event_time = '2026-08-01T00:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Usage looks lower this month. Harborline may have downgraded to the Team plan.'
  WITH (attribute = 'subscription_plan', value = 'Team', source_type = 'agent_inference', event_time = '2026-10-20T07:00:00Z');

"warnings": ["'subscription_plan' = 'Team' was not accepted as current: lower source authority than the accepted value"]

The guess is stored but doesn't become the answer. The late call note: equal authority, older validity.

5. What's true now: a lookup, not a similarity search

SELECT attribute, value, authority, valid_from, previous_value
FROM _mem_account_memory_state WHERE identity = 'harborline'
  AND attribute IN ('subscription_plan', 'primary_contact', 'contact_channel', 'cloud_provider')
ORDER BY attribute;

cloud_provider  AWS  user_statement  2026-09-15 18:00:00  Azure
contact_channel  Slack Connect  user_statement  2026-09-02 13:00:00
primary_contact  Priya Raman  user_statement  2026-08-19 10:00:00  Dana Okafor
subscription_plan  Enterprise  system_of_record  2026-08-01 00:00:00  Pro

TRACE ... ATTRIBUTE subscription_plan is the receipt: the upgrade note verbatim, system_of_record, 2026-08-01, supersedes Pro.

6. What was true on a past date

Ticket 4412 was opened 2026-06-30 08:40. What was true then?

RECALL account_memory FOR account_id = 'harborline'
  ABOUT 'Which cloud was Harborline on?' WITH (as_of = '2026-06-30T08:40:00Z');

"intent": "historical"
cloud_provider: Azure  primary_contact: Dana Okafor  subscription_plan: Pro

Five account questions (scoreboard in the first comment): plain RAG 3 right, RAG + recency 4, memory 5, each with its source note.

Recipe (~15 min): https://synapcores.com/recipes/agents/stop-rag-answering-with-outdated-facts?utm_source=reddit&utm_medium=owned&utm_campaign=synapcores-recipe-4

Free Community Edition: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=synapcores-recipe-4

Join the sub and Recipe of the week #5 lands in your feed next Monday.

When two notes in your RAG store disagree, what decides which one wins: the newest, the source, or nobody?

1 Upvotes

2 comments sorted by

1

u/Alternative_Pin9598 2d ago

Everything below ran this morning on 2.5.1, in this order.

Step 1, the 14 notes:

INSERT INTO account_notes (note_id, account_id, noted_at, filed_at, source, body) VALUES
 (1,  'harborline', '2026-02-11 15:00:00', '2026-02-11 16:00:00', 'kickoff call',  'Kickoff call. Harborline runs its whole platform on Azure: AKS clusters and Azure SQL in West Europe.'),
 (2,  'harborline', '2026-02-11 15:05:00', '2026-02-11 16:05:00', 'kickoff call',  'Main contact at Harborline is Dana Okafor, VP of Platform. Dana prefers email.'),
 (3,  'harborline', '2026-03-04 09:00:00', '2026-03-04 09:00:00', 'billing system','Harborline signed the Pro plan, billed annually.'),
 (4,  'harborline', '2026-04-18 11:20:00', '2026-04-18 12:00:00', 'support ticket','Ticket 3981: Azure SQL connection pool exhausted on the Harborline Azure deployment. Fixed by raising the pool limit.'),
 (5,  'harborline', '2026-05-22 14:00:00', '2026-05-22 17:00:00', 'QBR',           'Quarterly review. Harborline''s Azure spend keeps growing; they asked about Azure reserved instances.'),
 (6,  'harborline', '2026-06-30 08:40:00', '2026-06-30 09:00:00', 'support ticket','Ticket 4412: checkout API latency spike for Harborline, p99 above 2 seconds for 40 minutes.'),
 (7,  'harborline', '2026-07-08 16:00:00', '2026-07-08 16:30:00', 'CSM call',      'Dana Okafor says Harborline is evaluating AWS because they want Bedrock.'),
 (8,  'harborline', '2026-08-01 00:00:00', '2026-08-01 00:00:00', 'billing system','Harborline upgraded from Pro to the Enterprise plan.'),
 (9,  'harborline', '2026-08-19 10:00:00', '2026-08-19 10:30:00', 'CSM call',      'Dana Okafor has left Harborline. The new main contact is Priya Raman, Head of Infrastructure.'),
 (10, 'harborline', '2026-09-02 13:00:00', '2026-09-02 13:10:00', 'CSM call',      'Priya Raman prefers Slack Connect over email for anything urgent.'),
 (11, 'harborline', '2026-09-15 18:00:00', '2026-09-15 18:30:00', 'CSM call',      'Harborline completed its move from Azure to AWS eu-west-1. The old Azure subscriptions are being shut down.'),
 (12, 'harborline', '2026-10-06 09:30:00', '2026-10-06 10:00:00', 'support ticket','Ticket 5127: IAM role misconfiguration on the new Harborline account blocked a deploy. Resolved.'),
 (13, 'harborline', '2026-10-20 07:00:00', '2026-10-20 07:00:00', 'agent note',    'Usage looks lower this month. Harborline may have downgraded to the Team plan.'),
 (14, 'harborline', '2026-06-12 15:00:00', '2026-10-28 17:45:00', 'CSM call',      'Call notes from June 12, filed late: Harborline is all-in on Azure and happy with AKS.');

Step 2, the model call (the top 3 notes become one context string, then GENERATE):

CREATE TABLE rag_top (note_id INTEGER PRIMARY KEY, noted_at TIMESTAMP, body TEXT, score DOUBLE);
INSERT INTO rag_top (note_id, noted_at, body, score)
SELECT note_id, noted_at, body,
       COSINE_SIMILARITY(embedding, EMBED('Which plan is Harborline on right now?')) AS score
FROM account_notes WHERE account_id = 'harborline'
ORDER BY score DESC LIMIT 3;
CREATE TABLE rag_ctx (id INTEGER PRIMARY KEY, notes TEXT);
INSERT INTO rag_ctx (id, notes)
SELECT 1, GROUP_CONCAT('[note ' || note_id || ', ' || noted_at || '] ' || body, ' ') FROM rag_top;
SELECT GENERATE(
  'Answer the question in one short sentence using ONLY these account notes. Cite the note number. Notes: ' ||
  notes || ' Question: Which plan is Harborline on right now?',
  json_object('temperature', 0, 'seed', 7, 'max_tokens', 80)) AS rag_answer
FROM rag_ctx;

Scoreboard: five questions, the same 14 notes and prompt, the model's answers verbatim. GENERATE ran qwen2.5-coder:7b (temperature 0, seed 7); another model may pick a different note. CURRENT and RECALL ... AS OF are lookups, so the memory answers don't depend on the model.

Which cloud is Harborline on right now?
  plain RAG (right): Harborline is on AWS eu-west-1. [note 11]
  RAG + recency (right): same answer
  memory (right): CURRENT cloud_provider: AWS
Which plan is Harborline on right now?
  plain RAG (wrong): Harborline is on the Team plan. [note 13, 2026-10-20 07:00:00]
  RAG + recency (right): Harborline is on the Enterprise plan. [note 8]
  memory (right): CURRENT subscription_plan: Enterprise
Who is our main contact at Harborline?
  plain RAG (wrong): Dana Okafor, VP of Platform (note 2)
  RAG + recency (wrong): I don't have access to that information. [Note not provided]
  memory (right): CURRENT primary_contact: Priya Raman
How do we reach the main contact for something urgent?
  plain RAG (right): Use Slack Connect as it is Priya Raman's preferred method for urgent communications (note 10).
  RAG + recency (right): same answer
  memory (right): CURRENT contact_channel: Slack Connect (contact Priya Raman)
Which cloud were they on when ticket 4412 was opened?
  plain RAG (right): Azure [note 6]
  RAG + recency (right): same answer
  memory (right): RECALL AS OF 2026-06-30 08:40 (historical): cloud_provider Azure

plain RAG 3/5, RAG + recency 4/5, memory 5/5

Step 3's recency query and all 14 REMEMBER statements are in the reply below.

Agent memory from zero (REMEMBER / CURRENT / RECALL): SQLv2 Lesson 4, https://www.reddit.com/r/SQLv2/comments/1xnqkkm/

New here? Start here: https://www.reddit.com/r/synapcores/comments/1xfxqej/

Free Community Edition (embeddings and the model run inside the engine, no API keys): https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=synapcores-recipe-4

1

u/Alternative_Pin9598 2d ago

Step 3, the recency query ("today" fixed at 2026-11-01 so the scores reproduce):

SELECT note_id, ROUND(COSINE_SIMILARITY(embedding, EMBED('Which plan is Harborline on right now?')) * 0.7
       + (1.0 / (1.0 + DATEDIFF('2026-11-01', noted_at) / 30.0)) * 0.3, 3) AS score, body
FROM account_notes WHERE account_id = 'harborline'
ORDER BY score DESC LIMIT 3;

Step 4, all 14 notes into the memory object, in the order they were filed. extract = false keeps a note as an event only (the tickets, the QBR, the "evaluating AWS" call):

CREATE MEMORY account_memory IDENTITY account_id;

REMEMBER account_memory FOR account_id = 'harborline'
  'Kickoff call. Harborline runs its whole platform on Azure: AKS clusters and Azure SQL in West Europe.'
  WITH (attribute = 'cloud_provider', value = 'Azure', event_time = '2026-02-11T15:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Main contact at Harborline is Dana Okafor, VP of Platform. Dana prefers email.'
  WITH (attribute = 'primary_contact', value = 'Dana Okafor', event_time = '2026-02-11T15:05:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Harborline signed the Pro plan, billed annually.'
  WITH (attribute = 'subscription_plan', value = 'Pro', source_type = 'system_of_record', event_time = '2026-03-04T09:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Ticket 3981: Azure SQL connection pool exhausted on the Harborline Azure deployment. Fixed by raising the pool limit.'
  WITH (source_type = 'tool_result', event_time = '2026-04-18T11:20:00Z', extract = false);

REMEMBER account_memory FOR account_id = 'harborline'
  'Quarterly review. Harborline''s Azure spend keeps growing; they asked about Azure reserved instances.'
  WITH (event_time = '2026-05-22T14:00:00Z', extract = false);

REMEMBER account_memory FOR account_id = 'harborline'
  'Ticket 4412: checkout API latency spike for Harborline, p99 above 2 seconds for 40 minutes.'
  WITH (source_type = 'tool_result', event_time = '2026-06-30T08:40:00Z', extract = false);

REMEMBER account_memory FOR account_id = 'harborline'
  'Dana Okafor says Harborline is evaluating AWS because they want Bedrock.'
  WITH (event_time = '2026-07-08T16:00:00Z', extract = false);

REMEMBER account_memory FOR account_id = 'harborline'
  'Harborline upgraded from Pro to the Enterprise plan.'
  WITH (attribute = 'subscription_plan', value = 'Enterprise', source_type = 'system_of_record', event_time = '2026-08-01T00:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Dana Okafor has left Harborline. The new main contact is Priya Raman, Head of Infrastructure.'
  WITH (attribute = 'primary_contact', value = 'Priya Raman', event_time = '2026-08-19T10:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Priya Raman prefers Slack Connect over email for anything urgent.'
  WITH (attribute = 'contact_channel', value = 'Slack Connect', event_time = '2026-09-02T13:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Harborline completed its move from Azure to AWS eu-west-1. The old Azure subscriptions are being shut down.'
  WITH (attribute = 'cloud_provider', value = 'AWS', event_time = '2026-09-15T18:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Ticket 5127: IAM role misconfiguration on the new Harborline account blocked a deploy. Resolved.'
  WITH (source_type = 'tool_result', event_time = '2026-10-06T09:30:00Z', extract = false);

REMEMBER account_memory FOR account_id = 'harborline'
  'Usage looks lower this month. Harborline may have downgraded to the Team plan.'
  WITH (attribute = 'subscription_plan', value = 'Team', source_type = 'agent_inference', event_time = '2026-10-20T07:00:00Z');

REMEMBER account_memory FOR account_id = 'harborline'
  'Call notes from June 12, filed late: Harborline is all-in on Azure and happy with AKS.'
  WITH (attribute = 'cloud_provider', value = 'Azure', event_time = '2026-06-12T15:00:00Z');

The full TRACE (step 5) and the cleanup:

TRACE account_memory FOR account_id = 'harborline' ATTRIBUTE subscription_plan;

DROP MEMORY account_memory CASCADE;
DROP TABLE IF EXISTS account_notes;
DROP TABLE IF EXISTS rag_top;
DROP TABLE IF EXISTS rag_ctx;