Notebooks
N
Neode
OpenAI Memory

OpenAI Memory

Memoryneode-notebooks

🧠 Neode as Memory for OpenAI

Open in Alph

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

  1. Store Memory: When the LLM learns new information, it calls Neode to extract and store triples
  2. Recall Memory: When asked questions, the LLM searches Neode for relevant knowledge
  3. 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 graph
  • recall_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
[ ]