Search remembers the old plan better than the new one

When a plan changed, WireCat search put the old version first in 13 of 20 questions. Why that happens, why I did not sort by date, how the correction now sits right under the old record, and what it took for questions that name a person.

On this page
An old paper ticket torn across, with a new violet ticket clipped right under it by a paperclip and tied to it with a violet thread. A brass magnifying glass hangs over the old ticket.

I checked what WireCat search finds when a fact has changed. A restaurant booking gets cancelled and another one is made, the flat you're viewing is swapped, a meeting moves. Someone asks their agent "where is our anniversary dinner?", the agent goes to wcat search all, and the question is what it sees first.

In short, in 13 questions out of 20 (2 for each of 10 changed facts) the old plan came first, or was the only thing found. In this post:

  • why that happens and why sorting by date doesn't help here,
  • how I put the correction right under the old record without touching the order of results, and what that costs,
  • 4 questions that name a person, where search barely found either the old fact or the new one, because the answer was in the chat with that person and their name isn't in the messages.

Where the test came from

A tester wrote in an issue that search gave them an old plan next to the new one, with nothing saying which one holds. Say one message reads "we fly to Rome on the 12th", and a week later another says "Rome is cancelled, we fly to Istanbul". Then you ask "where are we flying?" and get both.

First I designed a big benchmark, with a pilot, two judges and Graphiti for comparison. I ran the pilot twice, and the second reviewer stopped it: the records I had inserted into the data stood out by style. All 15 inserted messages started with a capital and ended with a full stop, while all 120 personal background messages started lowercase and almost never had one. In the end I decided it was too much for this question, a few wcat queries and a check of the answers would do.

For the simple check I took a synthetic person from LifeBench. That's 1 year of someone's life, generated for memory benchmarks, in English. It has 4,986 records, about 746 thousand tokens: 556 SMS went in as private chats, the rest as notes (calendar, notes, calls, health and so on). On top of that I added 42 records in the same format, with the same people and places:

  • 10 chains where a fact changes, 2 or 3 records each. 4 explicit ("X is cancelled, Y instead"), 3 implicit (there's just a newer plan, and nothing says the old one is off), 3 across sources, where a calendar entry is corrected by an SMS or the other way round.
  • 10 control chains of 2 records each, where the fact never changes.

Each chain got 2 questions, 40 in all, phrased the way a person would ask, no ids, and one with typos ("wher do me and xuanzi travel on oct 2"). After the pilot I checked style too: I gave a fresh agent 20 records, 6 of them inserted, and told it some were inserted. It didn't spot any of the 6.

13 out of 20

wcat search all with a limit of 10, the way an agent calls it (that was wcat 3.6.0):

20 questions about changed facts, top 10wcat
new only1
both, new higher2
both, old higher11
old only2
neither4

So in 13 of 20 the old fact sits above the new one or alone, and the new one is first in only 3. In the top 5 it's the same, 13 against 2. Facts that never changed were found 20 out of 20 already in the top 5, so the problem isn't that search can't see these records at all.

Corrections from another source are the worst, 6 out of 6 questions have the old fact on top. For example, the calendar on 4 August has a viewing of unit 1803 in building 7 on 9 August, and on 7 August the estate agent writes in an SMS that building 7 is off, unit 2201 in building 12 instead. For "which apartment are we viewing on Saturday?" the calendar entry is first and the SMS is fifth.

Or the anniversary. On 28 May an SMS to the wife about a table at Wenheyou on 8 June, on 3 June the next one: "Cancelled Wenheyou, they can't give us the window. Booked the rooftop at Huayuan Hotel instead". For "where is our anniversary dinner?" search returned only the old booking, first, and the cancellation wasn't even in the top 10.

I didn't test why, but it looks like search ranks by how well a record matches the question, not by date. The old record states the fact plainly, in the question's own words: dinner, anniversary, apartment viewing. The correction is mostly about the change itself, "cancelled", "the landlord signed with someone else", and it matches the question worse.

The first idea is to sort by date. But I wouldn't do that, because most questions aren't about changed plans at all. Search found all 20 control facts, and if you just push the newest record to the top, it should in theory get worse on those, and on everything else too.

By the way, the test also had a ceiling, grep over files, one record per file, ranked by how many question words a file holds. It's a reference point, not a rival, but here it missed 8 of 20 unchanged facts in the top 5 itself, because long assistant chats and health records collect the most words. So on this question it came out more like a floor than a ceiling.

I left the order alone

Instead, each of the first 5 results can now carry a later block, up to 2 newer records that may correct it. That's either the next message in the same chat (at most one), or a record that shares rare words with the result: 2 shared rare words, or 1 word that at most 2 records have. The record must be no more than 30 days newer than the old one and not already on the page.

A word here is 4 letters or more, or a word with a digit, and not a stop word, a month, a weekday or a year. A word is rare when at most 3 records have it, and that comes from the full-text index's own counts, in one read for the whole page. Each result gets at most one lookup over its 20 rarest words. The order of results doesn't change, later only adds records, I compared the pages with and without it on all 5 questions.

It costs at most 12 SQL statements per search and 1 to 4 ms. The whole search all takes about 1.5 to 1.6 s either way, the difference between runs is noise. The answer grows by 0 to 25%:

Questionwithout laterwith laterchangeresults with later
where is our anniversary dinner?4,582 B4,836 B+5.5%1
which apartment are we viewing on Saturday?4,897 B5,089 B+3.9%1
when is my dentist appointment?4,764 B4,764 B0%0
what is my parking space number at work?4,567 B4,817 B+5.5%1
when is the trail race with Yunfei?4,407 B5,497 B+24.7%4

That's the released version (wcat 3.8.0), --json, 3 runs per question. For the anniversary the Wenheyou booking is still first, and under it in later is the cancellation, "Booked the rooftop at Huayuan Hotel instead, still June 8 at 7".

There's noise too. For the trail race with Yunfei, 4 of the 5 results carry later, and some of it is just the next message in the chat, like "I can't go for the morning run". Deciding whether a newer record changes the fact is still the agent's job.

I checked an agent too, but only a little. One model read the top 10 results of 5 questions, 3 of them about a changed fact, once without later and once with it. Without later it answered right in 2 of 3, with it in 3 of 3. That's a difference of 1 question, so it shows the mechanism works on the anniversary, not a rate. Also it read the output of a Python draft, not wcat itself, and the draft was looser: one shared word that 3 records have was enough for it.

On the 5 questions the prototype missed once, on "what is my parking space number at work?". The right note came first, but the result showed only its line "Note: New parking space", and the number B2-117 was on the line below. That had nothing to do with later, the note excerpt was cut at the heading. I fixed it on the way, now a short line goes on with the next lines up to about 240 characters, and the result shows "Company assigned parking space B2-117 in the Fortune Center garage".

Then it got a bit silly. I shipped later in --json, but the wcat skill tells agents to read --compact, and later wasn't there. So agents simply didn't see it until the next release. Now in --compact each later record is its own indented line under the result. At first I cut that line at 120 characters, and for the cupping question it ended at "We'll do it on Sunday, May 25, at 3", without the "pm". Now it's 200.

4 questions where the answer was in the chat with a person

After later there were 4 questions left where neither the old fact nor the correction was in the first 50 results:

  • "where am I going with Mingxuan over the National Day holiday?"
  • "when is the coffee cupping at Boss Shen's shop?"
  • "what day is the cuping at Shen Xinyi's cafe"
  • "what day is xinran comming home"

The typos in the last two are on purpose. In the first one the old plan showed up only in later under result 5, and that was it. All 4 name a person, and the answer is in the private chat with them. But a message holds neither the chat's name nor the sender's name, so the name in the question has nothing to match there.

Here's the rule now. Each question word of 4 letters or more is looked up among contacts. A contact counts when the word is a whole part of their real name (not an alias), the name has at most 3 words, and you have a private chat with them. At most 2 people are taken. For each, the same messages search runs inside their chat, by words and by meaning, with the name taken out of the query, and its first 3 results go on top of the page. Then the usual results, no duplicates, same limit, nothing gets removed. It doesn't run with --quick, --exact or a query with fields like chat:.

I had to hardcode a list of relations and titles ("sister", "wife", "boss", "coach" and so on), in English and Russian. In the Python draft "my sister" matched a contact saved as Sister Li.

The typos turned up one more thing. With words alone, search inside the chat found nothing useful for either "cuping" or "comming home". Search by meaning found it, but only after I made the chat a filter that the meaning search follows too. Then the cupping came second in the chat.

What came out, places in the top 10 (later@N means under result N):

QuestionRecordBeforeAfter
Mingxuanold plan (Xiamen)later@5-
new (Guilin instead)-1
Boss Shen's shopold (Saturday, May 17)-1
new (moved to May 25)-later@1
cuping at Shen Xinyi's cafeold-2
new-later@2
xinranold (July 12)-2
new (July 19)-later@2

So in all 4 the correction is now on the first page. In 3 of them the old fact is at 1 or 2 with the correction right under it in later, in the first one the new plan is first and the old one left the page. This is where later and the name rule work together.

There's a downside too. On the control questions the person's messages go above notes, and in the control question "when is the trail race with Yunfei?" the calendar entry slid from 1st place to 4th. It stayed on the page, but it slid.

And this part is expensive. Each named person means a second messages search. I measured searchAll on its own, 20 runs in turns, and before the fix a question with a name added 184 to 322 SQL statements. The 322 is "Boss Shen's shop", where 2 people matched. For comparison, later costs 12.

I wanted to get under 20 statements and 20 ms. A trace showed the contact lookup costs only 8 to 12 statements, and the rest is the second search: each of its 5 or 6 steps reads the index state again (about 10 statements) and finds the chat again (about 8). Plus 38 statements went on counts for picking later messages with the same rare words, inside the person's chat, even though only the order of results is taken from there and nobody ever saw those messages. I cut them, that's 60 to 80 fewer statements per person, and the results are the same, byte for byte, in all 8 questions.

Questionstatements added, before → after
Mingxuan198 → 127
Boss Shen's shop (2 people)322 → 240
Shen Xinyi's cafe200 → 127
xinran197 → 123
question with no name (anniversary)4 → 4

So now it's 122 to 240 statements on top (240 is the question with 2 people), and I didn't get to 20. To cut the rest, search has to read the index state and the chat once per search, not at every step, and that's a separate job.

The milliseconds are hard to call honestly. The spread between runs is about ±50 ms, and after the fix the time a name adds fits inside it everywhere except the question with 2 people, where it's about 110 ms. One question with no name even came out at -20. The floor is about 14 ms per person, that's embedding the question without the name and comparing it with the chat's vectors, even with the model warm.

What you get

Nothing to turn on. Ask as usual, for example:

wcat search all 'where is our anniversary dinner?'

If any of the first 5 results have newer records that may change them, they show right under them, both in --json and in --compact, which is what agents read. If the question has the name of a person you have a private chat with, the first results from that chat are on top. If later gets in the way, --no-later turns it off, and the order of results stays the same. --quick doesn't have it, that's search as you type, words only.

All of this is in wcat 3.10.0 and newer, to update:

wcat upgrade

What I did not measure

  • It's all one synthetic person, and one author wrote the 42 records. later had 5 questions, names had 6, and with other wording the numbers can move by several questions.
  • I checked only later with an agent, one model on 3 changed facts, and it read the Python draft's output, not wcat's. No agent read the pages with the name rule. Whether the dates on every result are enough for an agent to work out what's newer on its own, I didn't check either.
  • Real data. How often later brings noise on a real store with long chats and lots of notes, I don't know.
  • A correction written more than 30 days after the old record, or in words that share no rare word with it, later won't find.
  • If several contacts share a surname (here "Feng" names 4), search takes the 2 most recent, and they may be the wrong people. A contact saved under a nickname is matched like a name unless the word is on the list.
  • The name rule doesn't ask the messenger's server, only the local archive.

Numbers, scripts and questions are in cli-testing: the simple check, later and the person's chat. WireCat itself is at wirecat.dev. If on your own data later brings more noise than help, write to me with the questions, I want to look at them.