Why Memory is Important in Every AI Application: An Intro to Memori

Aug 27, 2025

The reason you have good conversations with your fellow human beings is that we all have brains that help us process and remember things.

Imagine you had a discussion with your friend concerning the book "The Power of Your Subconscious Mind” by Joseph Murphy last week, and you come back next week and say, "I saw that book in the library today." Your friend immediately remembers the book you're talking about, and then you continue conversing with them.

This is possible because the moment you said "that book," their brain, which serves as memory, processed and was able to recall that the book you're talking about is "The Power of Your Subconscious Mind." Imagine your friend didn't have a memory. You'd need to explain everything from scratch every single time you wanted to continue a conversation. Frustrating, right?

In that same way, AI applications, agents, and workflows need memory to remember conversations.

When you open ChatGPT and ask it, "Who is the president of the United States?" it will answer, "Donald Trump." Then you go ahead and ask it, "How old is he?" It will remember that you're talking about the president of the United States without needing to mention it again, and it will give you the answer.

Imagine if you asked, "How old is he?" and it replied with "How old is who? Who are we talking about?" Imagine having to give it full context every time you ask a question. It wouldn't be helpful, and it would sound like you're talking to a different person every time. ChatGPT can answer your follow-up questions because the builders of ChatGPT (OpenAI) have integrated a kind of memory within it. With that, it can remember your previous chat and, based on that, know what to answer you at every point.

The Importance of Adding Memory to Your AI

Some of the key benefits of adding memory to your AI applications include:

  • Contextual Conversations: Your AI can maintain context across multiple interactions, making conversations feel natural and human-like.

  • Improved User Experience: Users don't need to repeat information or provide full context every time they interact with your AI.

  • Personalised Interactions: AI can remember user preferences, past conversations, and tailor responses accordingly.

  • Enhanced Problem Solving: AI can build upon previous discussions and solutions, creating more sophisticated and helpful responses.

  • Reduced Redundancy: Eliminates the need to re-explain background information or context constantly.

  • Better Decision Making: AI can reference past decisions and outcomes to make more informed choices.

  • Scalable Knowledge Base: Memory allows AI to accumulate knowledge over time, becoming more effective with each interaction

Over time, AI engineers and people building AI applications have used different methods and frameworks to add memory to their applications. In this article, we'll focus on Memori, a framework that makes adding memory to AI applications easy.

An Intro to Memori

Memori is an open-source memory layer for AI agents and multi-agent systems. In simple terms, Memori is an open-source framework/library that is used to add memory to your AI applications.

With Memori, you can give your AI agents structured, persistent, and conscious memory using professional-grade architecture.

The GibsonAI team develops it. If you're not familiar with GibsonAI, it is an all-in-one AI-powered database platform that enables you to design, manage, deploy, and scale serverless SQL databases using plain English.

Key Features of Memori

  1. Universal Integration: It works with any LLM library (LiteLLM, OpenAI, Anthropic, etc.)

  2. Intelligent Processing: Pydantic-based memory with entity extraction

  3. Auto-Context Injection: It ensures that relevant memories are automatically added to conversations.

  4. Multiple Memory Types: You can use different memory types, like short-term, long-term, rules, and entity relationships

  5. Advanced Search: You can perform a full-text search with semantic ranking

  6. Production-Ready: It offers comprehensive error handling, logging, and configuration

  7. Database Support: SQLite, PostgreSQL, MySQL

  8. Type Safety: Full Pydantic validation and type checking

Seeing Memori in Action

Below, we will explore how to integrate Memori into your AI application. We will build a simple chatbot that works in the terminal and also remembers, just like a human, having both long-term and short-term memory.

Step 1: Install Required Dependencies

Install Memori and LiteLLM using pip:

Step 2: Set Up Your API Key

Export your OpenAI API key as an environment variable:

export OPENAI_API_KEY="sk-your-openai-key-here"

Step 3: Create the Chatbot

Create a new file called chatbot.py and add the following code:

from memori import Memori  # Import the Memori class for memory management
from litellm import completion  # Import completion function for AI model interactions

# Initialise Memori with SQLite database
memori_manager = Memori(
    database_connect="sqlite:///memory.db",  # SQLite database file path
    auto_ingest=True,  # Automatically store conversations in memory
    conscious_ingest=True,  # Enable intelligent memory filtering
    verbose=True,  # Enable detailed logging for debugging
)

# Activate the memori system (This now allows memori to save all conversations)
memori_manager.enable()

# Welcome message for the user
print("Chat started! Type 'quit' or 'exit' to end the conversation.\\n")

# Main conversation loop - continues until user decides to quit
while True:
    # Get user input and remove leading/trailing whitespace
    user_input = input("You: ").strip()
    
    # Check if user wants to quit the conversation
    if user_input.lower() in ["quit", "exit", "q"]:
        print("Goodbye!")
        break
    
    # Skip empty inputs to avoid unnecessary API calls
    if not user_input:
        continue
    
    try:
        # Send user input to the AI model and get a response
        response = completion(
            model="gpt-4o-mini",  # Using GPT-4o-mini for cost-effective responses
            messages=[{"role": "user", "content": user_input}],
        )
        
        # Extract and display the AI's response
        ai_response = response.choices[0].message.content
        print("Assistant:", ai_response)
        print() 
        
    except Exception as e:
        # Handle any errors that might occur during the API call
        print(f"Error: {e}")
        print()

Step 4: Run Your Chatbot

Execute the chatbot in your terminal:

python chatbot.py

Understanding the Memory System

When you run the code, you'll notice that three database files are created:

  • memori.db - Main database file

  • memori.db-shm - Shared memory file

  • memori.db-wal - Write-ahead log file

These files store all conversation data, enabling the AI to maintain context across conversations.

Now, start conversing with the AI and ask follow-up questions. You'll see that the AI can remember and reference previous parts of your conversation, demonstrating its memory capabilities.

Database Structure

If you want to explore what's being stored, install the SQLite Viewer extension in your code editor and open the memori.db file. You'll find four main tables:

1. Chat History: This table stores complete conversation logs, including both user input and AI responses.

2. Long-Term Memory: This stores important information for extended periods, making the AI more personalized over time. This includes:

Category

Description

Examples

Facts

Factual information, definitions, technical details

"I use PostgreSQL for databases"

Preferences

User preferences, likes/dislikes, personal choices

"I prefer clean, readable code"

Skills

Skills, abilities, competencies, learning progress

"Experienced with FastAPI"

Context

Project context, work environment, current situations

"Working on e-commerce platform"

Rules

Rules, policies, procedures, guidelines

"Always write tests first"

3. Memory Entities: This table stores extracted entities such as people, keywords, topics, and other important entities.

4. Short-Term Memory: Stores temporary information with a 30-day retention period.

Database Support Options

In this tutorial, we used SQLite due to its simplicity. However, Memori is designed to support multiple database systems for production use.

  • SQLite: Perfect for development and small applications

  • PostgreSQL: Production-ready with full-text search capabilities

  • MySQL: Enterprise database support

  • Connection Pooling: Optimized performance with connection management

For production applications, consider upgrading from SQLite to PostgreSQL or MySQL for better performance and scalability.

Why Memory Changes Everything

Memory transforms AI from a basic responder into a genuine conversational partner. Without it, interactions can feel robotic; with it, your AI can remember, adapt, and provide more human-like experiences.

Memori simplifies this process by offering a production-ready memory layer for any LLM workflow. You can start small, experiment, and observe how your AI becomes smarter with each conversation.

🧠 Ready to give your AI a brain?

📄 Check out the Memori Documentation for more examples and to learn more about how it works.

💻 Visit the Memori GitHub Repository and don’t forget to give it a star if you find it useful.

Get started free

Build your next database with the power of GibsonAI.

Get started free

Build your next database with the power of GibsonAI.

Sign up today

Get started free

Build your next database with the power of GibsonAI.