Agentmemory
Easy-to-use agent memory, powered by chromadb and postgres
Install / Use
/learn @elizaOS/AgentmemoryREADME
agentmemory <a href="https://discord.gg/qetWd7J9De"><img style="float: right" src="https://dcbadge.vercel.app/api/server/qetWd7J9De" alt=""></a> <a href="https://github.com/AutonomousResearchGroup/agentmemory/stargazers"><img style="float: right; padding: 5px;" src="https://img.shields.io/github/stars/AutonomousResearchGroup/agentmemory?style=social" alt=""></a>
Easy-to-use memory for agents, document search, knowledge graphing and more.
<img src="resources/image.jpg">Installation
pip install agentmemory
Quickstart
from agentmemory import create_memory, search_memory
# create a memory
create_memory("conversation", "I can't do that, Dave.", metadata={"speaker": "HAL", "some_other_key": "some value, could be a number or string"})
# search for a memory
memories = search_memory("conversation", "Dave") # category, search term
print(str(memories))
# memories is a list of dictionaries
[
{
"id": int,
"document": string,
"metadata": dict{...values},
"embeddings": (Optional) list[float] | None
},
{
...
}
]
Debugging
You can enable debugging by passing debug=True to most functions, or by setting DEBUG=True in your environment to get global memory debugging.
create_memory("conversation", "I can't do that, Dave.", debug=True)
Deployment
CLIENT_TYPE='POSTGRES' | 'CHROMA' POSTGRES_CONNECTION_STRING=postgres://postgres:MagickDatabase123!@db.xnzvmluhwpbngdufsbrd.supabase.co:6543/postgres
By default, agentmemory will use a local ChromaDB instance. If you want to use a Postgres instance, you can set the environment variable CLIENT_TYPE to POSTGRES and set the POSTGRES_CONNECTION_STRING environment variable to your Postgres connection string.
You can deploy an agentmemory-based application to the cloud in minutes using Supabase. Here is a tutorial and an explanation of pgvector.
Basic Usage Guide
Importing into your project
from agentmemory import (
create_memory,
create_unique_memory,
get_memories,
search_memory,
get_memory,
update_memory,
delete_memory,
delete_similar_memories,
count_memories,
wipe_category,
wipe_all_memories
)
Create a Memory
# category, document, metadata
create_memory("conversation", "I can't do that, Dave.", metadata={"speaker": "HAL", "some_other_key": "some value, could be a number or string"})
Search memories
memories = search_memory("conversation", "Dave") # category, search term
# memories is a list of dictionaries
[
{
"id": int,
"document": string,
"metadata": dict{...values},
"embeddings": (Optional) list[float] | None
},
{
...
}
]
Get all memories
memories = get_memories("conversation") # can be any category
# memories is a list of dictionaries
[
{
"id": int,
"document": string,
"metadata": dict{...values},
"embeddings": (Optional) list[float] | None
},
{
...
}
]
Get a memory
memory = get_memory("conversation", 1) # category, id
Update a memory
update_memory("conversation", 1, "Okay, I will open the podbay doors.")
Delete a Memory
delete_memory("conversation", 1)
Delete Similar Memories
delete_similar_memories(category, content, similarity_threshold=0.95)
Search for memories that are similar to the one that contains the given content and removes them.
Parameters
category(str): The category of the collection.content(str): The content to search for.similarity_threshold(float, optional): The threshold for determining similarity. Defaults to 0.95.
Returns
bool: True if the memory item is found and removed, False otherwise.
API Reference
Create a Memory
create_memory(category, text, id=None, embedding=None, metadata=None)
Create a new memory in a collection.
Arguments
# Required
category (str): Category of the collection.
text (str): Document text.
# Optional
id (str): Unique id. Generated incrementally unless set.
metadata (dict): Metadata.
embedding (array): Embedding of the document. Defaults to None. Use if you already have an embedding.
Example
>>> create_memory(category='sample_category', text='sample_text', id='sample_id', metadata={'sample_key': 'sample_value'})
Create Unique Memory
create_unique_memory(category, content, metadata={}, similarity=0.95)
Create a new memory only if there aren't any that are very similar to it. If a similar memory is found, the new memory's "novel" metadata field is set to "False" and it is linked to the existing memory.
Parameters
category(str): The category of the collection.content(str): The text of the memory.metadata(dict, optional): Metadata for the memory.similarity(float, optional): The threshold for determining similarity.
Returns
None
Search Memory
search_memory(category, search_text, n_results=5, min_distance=None, max_distance=None, filter_metadata=None, contains_text=None, include_embeddings=True, novel=False)
Search a collection with given query texts.
A note about distances: the filters are applied after the query, so the n_results may be dramatically shortened. This is a current limitation of Chromadb.
Arguments
# Required
category (str): Category of the collection.
search_text (str): Text to be searched.
# Optional
n_results (int): Number of results to be returned.
filter_metadata (dict): Metadata for filtering the results.
contains_text (str): Text that must be contained in the documents.
include_embeddings (bool): Whether to include embeddings in the results.
include_distances (bool): Whether to include distances in the results.
max_distance (float): Only include memories with this distance threshold maximum.
0.1 = most memories will be exluded, 1.0 = no memories will be excluded
min_distance (float): Only include memories that are at least this distance
0.0 = No memories will be excluded, 0.9 = most memories will be excluded
novel (bool): Whether to return only novel memories.
Returns
list: List of search results.
Example
>>> search_memory('sample_category', 'search_text', min_distance=0.01, max_distance=0.7, n_results=2, filter_metadata={'sample_key': 'sample_value'}, contains_text='sample', include_embeddings=True, include_distances=True)
[{'metadata': '...', 'document': '...', 'id': '...'}, {'metadata': '...', 'document': '...', 'id': '...'}]
Get a Memory
get_memory(category, id, include_embeddings=True)
Retrieve a specific memory from a given category based on its ID.
Arguments
# Required
category (str): The category of the memory.
id (str/int): The ID of the memory.
#optional
include_embeddings (bool): Whether to include the embeddings. Defaults to True.
Returns
dict: The retrieved memory.
Example
>>> get_memory("books", "1")
Get Memories
get_memories(category, sort_order="desc", filter_metadata=None, n_results=20, include_embeddings=True, novel=False)
Retrieve a list of memories from a given category, sorted by ID, with optional filtering. sort_order controls whether you get from the beginning or end of the list.
Arguments
# Required
category (str): The category of the memories.
# Optional
sort_order (str): The sorting order of the memories. Can be 'asc' or 'desc'. Defaults to 'desc'.
filter_metadata (dict): Filter to apply on metadata. Defaults to None.
n_results (int): The number of results to return. Defaults to 20.
include_embeddings (bool): Whether to include the embeddings. Defaults to True.
novel (bool): Whether to return only novel memories. Defaults to False.
Returns
list: List of retrieved memories.
Example
>>> get_memories("books", sort_order="asc", n_results=10)
Update a Memory
update_memory(category, id, text=None, metadata=None)
Update a memory with new text and/or metadata.
Arguments
# Required
category (str): The category of the memory.
id (str/int): The ID of the memory.
# Optional
text (str): The new text of the memory. Defaults to None.
metadata (dict): The new metadata of the memory. Defaults to None.
Example
# with keyword arguments
update_memory(category="conversation", id=1, text="Okay, I will open the podbay doors.", metadata={ "speaker": "HAL", "sentiment": "positive" })
# with positional arguments
update_memory("conversation", 1, "Okay, I will open the podbay doors.")
Delete a Memory
delete_memory(category, id, contains_metadata=None, contains_text=None)
Delete a memory by ID.
Arguments
# Required
category (str): The category of the memory.
id (str/int): The ID of the memory.
# Optional
Example
>>> delete_memory("books", "1")
delete_memories(category, document=None, metadata=None)
Delete all memories in the category either by document, or by metadata, or by both.
Arguments
# Required
cat
Related Skills
node-connect
353.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
