🧠 The Illusion of Memory
part3.ipynb— Continuing in level1 folder*
Here's one of the most mind-bending truths about AI chat systems:
💡 LLMs don't actually remember anything — they just make it feel like they do.
⚡ Every LLM Call Starts Fresh
Each API request is completely stateless — meaning the model wakes up with zero memory of:
💬 Your previous messages
🪪 Your name
📜 Any earlier conversations
Unless you manually send the history along with every new request, it's as if the conversation never happened.
✅ Lets gets the hands on Experience
Env Variable Import
▶️ Create a new code cell and run it:
import os
from dotenv import load_dotenv
load_dotenv(override=True)
api_key = os.getenv('OPENAI_API_KEY')
if not api_key:
print("No API key was found - please head over to the troubleshooting notebook in this folder to identify & fix!")
elif not api_key.startswith("sk-proj-"):
print("An API key was found, but it doesn't start sk-proj-; please check you're using the right key - see troubleshooting notebook")
else:
print("API key found and looks good so far!")Creating new OpenAI Instance
▶️ Create a new code cell and run it:
from openai import OpenAI
openai = OpenAI()Setting Message dicts for OpenAI
▶️ Create a new code cell and run it:
messages = [
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hi! I'm Bhaskar!"}
]
Making the API call and Printing the Response
▶️ Create a new code cell and run it:
response = openai.chat.completions.create(model="gpt-4.1-mini", messages=messages)
response.choices[0].message.content
# Example Response
# 'Hello Bhaskar! How can I assist you today?'Now, Lets ask a follow up question
▶️ Create a new code cell and run it:
messages = [
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "What's my name?"}
]Again Making API call and printing response
▶️ Create a new code cell and run it:
response = openai.chat.completions.create(model="gpt-4.1-mini", messages=messages)
response.choices[0].message.content
# Example Response
# 'I’m sorry, but I don’t know your name. Could you please tell me?'2😲 Did You Notice That?
In the first call you told GPT your name — yet in the second call, it had absolutely no idea who you were! 🤯
🔄 Here's Why
Every single call to an LLM is completely stateless — it's a brand new conversation every time, with zero recollection of what came before.
🧑💻 This is where we come in!
As AI engineers, it's our job to build techniques that simulate memory — crafting the illusion that the LLM actually remembers. 🎭