Skip to main content
An assistant that remembers past conversations has to choose which memories to put in its prompt. This example ranks the candidates your own search found, and says which ones help with the message. Use it at the start of a turn, before you build the prompt.

How it works

The context is JSON with the user’s message and memories, an object that maps an ID to each memory’s text. The keys are yours to choose. One single decision, recall, asks which memory would most help answer the message. It has one outcome per memory, plus none. The outcome IDs must match the keys in context.memories. That is how the model knows which outcome is which memory. Your memory store stays in your system: you send only the candidates your search found, up to a few dozen.

Try it

Open this recipe in the playground to run it without an account. The message there asks what kind of films to watch this weekend. Six memories are offered, from a note about The Godfather to a flight to Lisbon. To run it from your code, set SQWISH_API_KEY as in the quickstart, then send this request:

Act on the answer

The probabilities add up to 1 across all the memories and none. When several memories help, they share the probability, so don’t wait for each one to pass 0.5. Recall every memory whose probability is above that of none:
If recalled is empty, answer from the message alone.

Adapt it to your data

  • Your IDs. Use your store’s own IDs, or short ones such as m1 that you map back. Each one must be both a key in context.memories and an outcome.
  • Dates. Keep each memory’s date in its text, as the sample does.
  • How many. Send the memories your search found most similar, up to a few dozen. It is one decision however many you send, and a decision can have up to 255 outcomes, none included.
  • Many messages. Send one request per message.

What to watch

  • Useful memories left out, and stale ones pulled in. Both show up as odd replies.
  • Your search sets the limit. A memory it doesn’t find can’t be recalled.

How well it works

Measured with kettei-core on 600 examples from a public dataset, it chose the right answer 86.3% of the time. Always picking the most common answer scores 33.3%. Your own data will differ, so measure it on examples of yours before you rely on it (improve a decision).
Always picking the most common answer has an accuracy of 0.3333, and guessing by how common each answer is has a log loss of 1.9279.These are past results on one dataset, not a promise of accuracy on yours.
The test used that dataset’s own candidate memories, so your search and the number of memories you send will give different results.

Next steps