█

AI/TLDR

Buy me a coffee
Buy me a coffee

Memoripy

Short-term and long-term memory for AI apps, with decay and concept graphs

Agent MemoryOpen source
Language
Python
License
Apache-2.0
$pip install memoripy
IN SHORT

What is Memoripy?

Memoripy is a Python library that manages and retrieves context-aware memory for AI applications. It keeps interactions in both short-term and long-term storage, then surfaces the most relevant past ones when you handle a new prompt. It sits in the Agent Memory category of the Agents & Automation tools and is open-source, written in Python and licensed Apache-2.0.

Overview

Memoripy is a Python library that manages and retrieves context-aware memory for AI applications. It keeps interactions in both short-term and long-term storage, then surfaces the most relevant past ones when you handle a new prompt.

It is aimed at developers building chat assistants or agents that need to remember earlier conversations. Memoripy works with OpenAI, Azure OpenAI, OpenRouter, and Ollama APIs for generating embeddings and extracting concepts.

As a memory framework, it goes beyond a plain history log: it models memory decay so older items fade, reinforces frequently used memories, and builds a concept graph to retrieve associated interactions by relevance.

What it does

  • Manages memory as short-term or long-term based on usage and relevance
  • Retrieves relevant past interactions using embeddings, concepts, and cosine similarity
  • Extracts concepts and generates embeddings via OpenAI or Ollama models
  • Builds a concept graph and uses spreading activation for relevance-based retrieval
  • Clusters similar memories into semantic groups with hierarchical clustering
  • Decays unused memories over time while reinforcing those accessed often

Getting started

Install Memoripy from PyPI, then wire a chat model, an embedding model, and a storage backend into a MemoryManager.

Install with pip

Memoripy and its dependencies (openai, faiss-cpu, numpy, networkx, scikit-learn, langchain, ollama) are installed automatically.

bashbash
pip install memoripy

Initialize the MemoryManager

Create a MemoryManager with a chat model, an embedding model, and a storage option such as JSONStorage or InMemoryStorage.

pythonpython
from memoripy import MemoryManager, JSONStorage
from memoripy.implemented_models import OpenAIChatModel, OllamaEmbeddingModel

api_key = "your-key"
storage_option = JSONStorage("interaction_history.json")

memory_manager = MemoryManager(
    OpenAIChatModel(api_key, "gpt-4o-mini"),
    OllamaEmbeddingModel("mxbai-embed-large"),
    storage=storage_option,
)

Retrieve memory and store the interaction

Pull recent and relevant interactions to build context, generate a response, then add the new interaction with its embedding and concepts.

pythonpython
new_prompt = "My name is Khazar"

short_term, _ = memory_manager.load_history()
last_interactions = short_term[-5:] if len(short_term) >= 5 else short_term
relevant = memory_manager.retrieve_relevant_interactions(new_prompt, exclude_last_n=5)

response = memory_manager.generate_response(new_prompt, last_interactions, relevant)

combined_text = f"{new_prompt} {response}"
concepts = memory_manager.extract_concepts(combined_text)
embedding = memory_manager.get_embedding(combined_text)
memory_manager.add_interaction(new_prompt, response, embedding, concepts)

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Give a chatbot recall of earlier turns so it stays consistent across a long conversation
  • Let an AI assistant remember user facts and preferences between sessions via JSON storage
  • Surface related past interactions by concept rather than just the most recent ones
  • Run memory locally with Ollama embeddings when you want to avoid sending data to a hosted API

How Memoripy compares

Memoripy alongside other open-source agent memory tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Claude-Mem★ 121kPersistent memory layer for coding agents: it captures what an agent does during a session, compresses it into semantic summaries, and injects the relevant parts back into later sessions.
Mem0★ 69.7kA memory layer that you add to existing LLM agents to extract, store, and recall user facts and preferences across sessions using vector, graph, and key-value backends.
Hindsight★ 64.3kAn agent memory server that stores facts and experiences, consolidates them into observations and mental models, and serves them back through retain, recall, and reflect operations.
MemPalace★ 60.8kLocal-first agent memory that stores conversations verbatim instead of summarising them, with a structured palace index, pluggable vector backends and an MCP server.
OpenViking★ 43.1kA context database that stores an agent's memories, resources, and skills as one browsable viking:// filesystem with three-tier (abstract/overview/details) on-demand loading.
Cognee★ 33.7kA graph-native memory engine that turns raw documents and conversations into a queryable knowledge graph for agents that need to build lasting knowledge.
Graphiti★ 33.2kA library that builds a temporal knowledge graph from an agent's conversations and data so facts can be tracked and queried as they change over time.
Memoripy★ 693Short-term and long-term memory for AI apps, with decay and concept graphs