What is Memory?

Memory refers to the intermediate variables that UltraRAG automatically records and stores during each reasoning round for subsequent rounds to access. It allows developers to “look back” at the results of any previous round without manually managing the state history in loops. For example:
  • In round 1, the model uses the initial q_ls to retrieve ret_psg, with a length of [500];
  • UltraRAG automatically encapsulates it as memory_ret_psg = [[...500 passages...]];
  • In round 2, a new [500] result is retrieved again, and memory_ret_psg updates to [[...first round...], [...second round...]], with dimensions [2, 500].
As long as the variable x is defined in any round, UltraRAG will automatically create a memory_x variable to record historical values.

How to Use Memory?

You can access historical information in Tools like this:
# Iterate over the historical retrieval results of all rounds
for round_ret_psg in memory_ret_psg:
    # Iterate over each sample's passage in that round (usually a List[str])
    for passage in round_ret_psg:
        print(passage)
Or access the historical reasoning chain:
# Access the historical reasoning sentence of a sample in round 2
cot_sentence = memory_q_ls[2][sample_idx]
UltraRAG’s Memory module is essentially an automated intermediate variable history recording system that greatly simplifies data state management when developers build multi-round logic. Simply declare memory_x in Tools to get all historical round values of a variable x.