When a model remembers past conversation, we want to check how well it keeps important details without mixing up or forgetting. Key metrics include Recall to see if the model remembers all relevant past info, and Precision to ensure it doesn't add wrong or unrelated info. Also, F1 score balances these two. These metrics help us know if the memory is accurate and complete, which is vital for smooth, meaningful chats.
Memory for conversation history in Prompt Engineering / GenAI - Model Metrics & Evaluation
Start learning this pattern below
Jump into concepts and practice - no test required
|-----------------------------|
| | Predicted Memory |
| Actual | Relevant | Wrong |
| Memory | | |
|-----------------------------|
| Relevant | TP | FP |
| Wrong | FN | TN |
|-----------------------------|
TP = Correctly remembered important info
FP = Incorrect or unrelated info remembered
FN = Important info forgotten
TN = Correctly ignored irrelevant info
High Precision, Low Recall: The model remembers only very sure facts, avoiding mistakes but forgetting some details. Good if wrong info is harmful.
High Recall, Low Precision: The model tries to remember everything, including some wrong or irrelevant details. Good if missing info is worse than some mistakes.
For example, in a customer support chat, high recall helps remember all user issues, but high precision avoids confusing the user with wrong info.
Good: Precision and Recall both above 0.8 means the model remembers most important info and rarely adds wrong details.
Bad: Precision below 0.5 means many wrong memories; Recall below 0.5 means many forgotten details. Either harms conversation quality.
- Accuracy paradox: High overall accuracy can hide poor memory if irrelevant info dominates.
- Data leakage: If test data leaks past conversation, metrics look better but don't reflect real memory ability.
- Overfitting: Model may memorize training chats perfectly but fail on new conversations.
Your chat model has 98% accuracy remembering conversation history but only 12% recall on important past details. Is it good for real use? Why or why not?
Answer: No, it is not good. The low recall means the model forgets most important info, even if overall accuracy looks high. This will cause poor chat quality because key details are missed.
Practice
Solution
Step 1: Understand the role of memory in AI conversations
Memory keeps track of previous messages so the AI can understand the flow of the conversation.Step 2: Identify the correct purpose
Storing past messages helps the AI respond with context, making conversations meaningful.Final Answer:
To store past user and AI messages for context -> Option AQuick Check:
Memory = store past messages [OK]
- Thinking memory speeds up internet
- Believing memory deletes all messages
- Assuming memory generates random replies
Solution
Step 1: Recall Python list methods for adding items
Python lists useappend()to add an item at the end.Step 2: Match method to memory update
Since conversation memory is often a list,append()is the correct method to add a new message.Final Answer:
memory.append(new_message) -> Option AQuick Check:
Python list add = append() [OK]
- Using add() which is for sets
- Using insert() without index
- Using push() which is not a Python list method
memory = ['Hi', 'How are you?'] new_message = 'I am fine' memory.append(new_message) print(len(memory))
What will be the output?
Solution
Step 1: Check initial memory length
Memory starts with 2 messages: 'Hi' and 'How are you?'.Step 2: Append new message and count
Appending 'I am fine' adds one more message, so total becomes 3.Final Answer:
3 -> Option BQuick Check:
2 + 1 = 3 messages [OK]
- Forgetting append adds item
- Thinking length stays same
- Assuming code causes error
memory = [] new_message = 'Hello' memory.add(new_message)
What is the error and how to fix it?
Solution
Step 1: Identify the error cause
Python lists do not have anadd()method; this causes an AttributeError.Step 2: Correct method to add item to list
Useappend()to add an item to a list, so replaceadd()withappend().Final Answer:
Error: list has no add(); fix by using memory.append(new_message) -> Option CQuick Check:
List add() wrong, use append() [OK]
- Using add() on list
- Thinking new_message is undefined
- Confusing list with dict
Solution
Step 1: Add new message to memory
Useappend()to add the new message at the end.Step 2: Keep only last 3 messages
Slicing withmemory[-3:]keeps the last 3 items, removing older ones.Final Answer:
memory.append(new_message) memory = memory[-3:] -> Option DQuick Check:
Append then slice last 3 [OK]
- Slicing before append loses new message
- Using insert at start changes order
- Popping removes wrong message
