Export
π§ Neode as Memory for OpenAI
This notebook demonstrates using Neode as a persistent knowledge graph that functions as memory for OpenAI's GPT models. The LLM can store facts and retrieve them later using Neode as a tool.
How It Works
- Store Memory: When the LLM learns new information, it calls Neode to extract and store triples
- Recall Memory: When asked questions, the LLM searches Neode for relevant knowledge
- Persistent: Knowledge persists across conversations and sessions
Use Cases
- Personal AI assistants that remember user preferences
- Research assistants that accumulate domain knowledge
- Chatbots with long-term memory
[ ]
Define Memory Tools
We'll give the LLM two tools:
store_memory: Save information to the knowledge graphrecall_memory: Search for relevant information
[2]
β Memory tools defined: β’ store_memory: Store information in long-term memory. Use this when you lea... β’ recall_memory: Search long-term memory for relevant information. Use this w...
Implement Memory Functions
These functions connect the LLM tools to Neode:
[8]
β Memory functions implemented!
Create the Chat Assistant
A chat function that handles tool calls automatically:
[9]
β Chat function ready!
Demo: Teaching the Assistant
Let's have a conversation where we teach the assistant some facts:
[5]
π€ User: Hi! My name is Alex and I'm a software engineer. I work at TechCorp and I love building AI applications.
π§ Calling store_memory({'information': "User's name is Alex. They are a software engineer at TechCorp and love building AI applications."})
π Result: Stored 11 facts:
Alex β has_occupation β software engineer
Alex β has_occupation β software engineer...
π€ Assistant: Nice to meet you, Alex β software engineer at TechCorp, and into building AI applications.
Iβve stored that info so I can remember it for later.
[6]
π€ User: I'm currently working on a project using Python and FastAPI. My favorite programming language is Rust though!
π§ Calling store_memory({'information': 'Alex is currently working on a project using Python and FastAPI. Their favorite programming language is Rust.'})
π Result: Stored 10 facts:
Alex β is_working_on_project_using β Python
Alex β is_working_on_project_using β Fa...
π€ Assistant: Got it β youβre currently working with Python + FastAPI, and your favorite language is Rust.
Iβve stored that for later.
Demo: Recalling Information
Now let's test if the assistant can recall what we told it:
[12]
π€ User: What do you know about me, Alex?
π§ Calling recall_memory({'query': 'Alex user details preferences personal info'})
π Result: Found memories:
β’ Alex has occupation software engineer
β’ Alex has occupation software engineer
β’ Al...
π€ Assistant: From what I have saved in memory about you:
- Your name is **Alex**.
- Youβre a **software engineer**.
- Youβre **employed by TechCorp**.
Thatβs all I currently have stored.
[13]
π€ User: What programming languages do I use?
π§ Calling recall_memory({'query': 'programming languages Alex uses'})
π Result: Found memories:
β’ Alex favorite programming language Rust
β’ Alex favorite programming language Rust
...
π€ Assistant: I have stored that your favorite programming language is **Rust**.
Interactive Chat
Run this cell to have an interactive conversation with memory:
[15]
π§ Chat with Memory (type 'quit' to exit) ================================================== π€ You: quit Goodbye!
View Stored Knowledge
Check what's been stored in your Neode knowledge graph:
[16]
π Knowledge Graph Contents: ============================================================ Alex β is_working_on_project_using β Python Alex β is_working_on_project_using β FastAPI Alex β favorite_programming_language β Rust Python β is_a β programming language FastAPI β is_a β web framework for building APIs with Python Rust (programming language) β is_a β programming language FastAPI β is_based_on β Starlette FastAPI β uses β Pydantic FastAPI β is_authored_by β SebastiΓ‘n RamΓrez Rust (programming language) β first_released_in β 2010 Alex β is_working_on_project_using β Python Alex β is_working_on_project_using β FastAPI Alex β favorite_programming_language β Rust Python β is_a β programming language FastAPI β is_a β web framework for building APIs with Python Rust (programming language) β is_a β programming language FastAPI β is_based_on β Starlette FastAPI β uses β Pydantic FastAPI β is_authored_by β SebastiΓ‘n RamΓrez Rust (programming language) β first_released_in β 2010 Alex β has_occupation β software engineer Alex β has_occupation β software engineer Alex β employed_by β TechCorp Alex β interested_in β building AI applications Techcorp LLC β provides β information technology solutions Techcorp LLC β provides β consulting services Techcorp LLC β supports β Artificial Intelligence Techcorp LLC β located_at β 3703 Green St, Claymont, Delaware 19703 Techcorp Information Systems Technology Company LLC β located_in β Riyadh 12621, Kingdom of Saudi Arabia TECHCORP β located_at β PO Box 17868, Fountain Hills, Arizona 85269 TechCorp β founded_in β 2015 Alex β has_occupation β software engineer Alex β has_occupation β software engineer Alex β employed_by β TechCorp Alex β interested_in β building AI applications Techcorp LLC β provides β information technology solutions Techcorp LLC β provides β consulting services Techcorp LLC β supports β Artificial Intelligence Techcorp LLC β located_at β 3703 Green St, Claymont, Delaware 19703 Techcorp Information Systems Technology Company LLC β located_in β Riyadh 12621, Kingdom of Saudi Arabia TECHCORP β located_at β PO Box 17868, Fountain Hills, Arizona 85269 TechCorp β founded_in β 2015 Alex β is_working_on_project_using β FastAPI FastAPI β is_a β web framework FastAPI β programming_language β Python FastAPI β builds β APIs FastAPI β uses β Python type hints Rust β is_a β programming language Rust β current_version β 1.90.0 Rust β has_package_manager β Cargo
[ ]