The reranker in WireCat's search over a messenger archive sometimes scored a different message from the one it found. When someone in a chat replied to a long message, that message filled the whole model window, and the message it found never got read. I cut the replied-to message to 300 characters, and now search messages --discover in the tg and max CLIs always sees at least the start of the message it found, with about 40% less CPU time. This is the second part about search on a laptop. I noticed it while making the reranker faster in the first one.
--discover first finds candidates by meaning and by words, then a small model (the reranker) reads the top 50 and puts them in order. It reads the question and one piece of text at a time and gives that pair a score.
A chat message alone is often too short. "Yes, send it Friday" means nothing without the message it answers. So the piece for the reranker was built like this: the chat, the author and the date, then the message being replied to, and at the end the message it found. The model reads at most 512 tokens, and anything longer was cut from the end.
The window ended before the message it found
The replied-to message came first and the found one last. When the replied-to message was long, the cut took the end, and the end was exactly the message it found.
On one of my real chats this happened in 18 of the 119 pairs with a reply, about one in seven. In those pairs the replied-to message alone was longer than the window, so the reranker scored it and not the message it found.
Nothing looked broken, because the answers to my test questions were still near the top, and a message and the reply to it are usually about the same thing. I noticed it only when I counted the tokens in each pair.
Why the test set didn't catch it
My synthetic evaluation set has replies too, but its longest pair is under 256 tokens and its median is 38. Real pairs have a median of 153 tokens, and one in ten is longer than 762. With messages that short the replied-to one can't fill the window.
9 ways to cut the input
I ran my 6 test questions on that chat with 9 versions of the input, twice each. The table shows 6 of them, the other 3 combine them with a 256-token cut. I counted the questions that keep a direct answer in the top 5, and the CPU time per --discover call across all threads. The machine was busy with other work at the time, so I compared CPU time, not wall-clock time, and the seconds here are larger than in the first part.
| Input | Direct answer in top 5 | CPU per call |
|---|---|---|
| Replied-to message, then found message, cut at 512 tokens (before) | 6 of 6 | 27.1 s |
| Cut at 256 tokens | 6 of 6 | 16.3 s |
| Cut at 128 tokens | 6 of 6 | 12.9 s |
| Found message, then replied-to message | 6 of 6 | 22.6 s |
| Replied-to message cut to 300 characters, then found message | 6 of 6 | 16.0 s |
| No replied-to message | 5 of 6 | 14.9 s |
Without the replied-to message one answer was lost, so the context is needed. Cutting at 256 or 128 tokens kept the answers here too, but it still cuts from the end, and a long enough replied-to message pushes the found one out again.
Cutting only the replied-to message to 300 characters kept every answer, and with it the start of the message it found always gets into the window. It also left the most relevant messages in the top 5 (26 of 30, direct and background answers together), and took about 40% less CPU time. The same 300 characters plus a 256-token cut was a bit cheaper (15.3 s), but on the set with long messages 256 tokens lose answers.
What changed
Since late October the search cuts the replied-to message to 300 characters before it builds the pair. The chat, the author and the date count toward those 300 characters, so a bit less of the message itself is kept. The reranker always reads the start of the message it found, with enough of the replied-to one to know what it answers. On a build with this change and the native ONNX Runtime from the first part I checked it again on a copy of my archive. All 6 questions had a direct answer in the top 5, and the native and WebAssembly runs agreed on 29 of 30 results.
Later I built a synthetic set with long messages, up to 7 KB, where in most questions the answer sits past the first thousand bytes on purpose. For real chats it's too hard a case, but it is a good test for cutting at fewer tokens. On it, cutting at 256 tokens lost 3 answers of 33 and 128 tokens lost 6, so I kept 512 tokens. Cutting the replied-to message to 300 characters neither helped nor hurt on that set, the result was the same as with the whole message. And even at 512 tokens, 598 of 2,100 pairs there were cut, so the reranker still doesn't read the end of a very long found message. Mostly because of that, long messages get far fewer answers in the top 3, 48% against 81% on the set with short ones.
6 questions on one chat is a small sample, so I wouldn't lean on the exact numbers. But if you put a model's input together from several pieces, I'd recommend counting the tokens in each pair and looking at what gets cut.
What I didn't measure
- Wall-clock time for each version of the input. The machine was busy, so the table has only CPU time, and the whole command's time after the release is in the first part.
- Other chats. The measurement on real data is one chat and 6 questions.
- I compared the input versions on a build where the input form could be switched with environment variables, and that change never shipped. Answers were graded with earlier judgments, and 1 or 2 new results in the shorter versions stayed ungraded.
Links
- The measurements, the setup and the scripts: reranker speed, "Reranker input".
- The set with long messages in cli-testing.
- Only totals come from my real messages here, the questions and the per-question rows stay private.
If your reranker input is also glued together from pieces and something else got cut, write to me, I'd like to compare.
