Python SDK for MemoryOS - Persistent memory for AI agents
Project description
MemoryOS Python SDK
Persistent memory for AI agents. Store, search, and retrieve memories with semantic understanding.
Installation
pip install memoryos
Quick Start
from memoryos import MemoryOS
# Initialize client
client = MemoryOS(api_key="your-api-key")
# Store a memory
memory_id = client.store(
"User prefers concise responses",
metadata={"user_id": "123"}
)
# Search memories (semantic search)
results = client.search("user preferences", limit=5)
for memory in results:
print(f"Similarity: {memory.similarity}")
print(f"Content: {memory.content}")
# List all memories
all_memories = client.list(limit=20)
# Get a specific memory
memory = client.get(memory_id)
# Delete a memory
client.delete(memory_id)
# Get statistics
stats = client.stats()
print(f"Total memories: {stats.total_memories}")
Integration with LangChain
from langchain.memory import ConversationBufferMemory
from memoryos import MemoryOS
client = MemoryOS(api_key="your-api-key")
# Store conversation context
def remember_conversation(user_input, response):
client.store(
f"User: {user_input}\nAssistant: {response}",
metadata={"type": "conversation"}
)
# Retrieve relevant context
def get_context(query):
results = client.search(query, limit=5)
return [m.content for m in results]
Integration with AutoGPT
from memoryos import MemoryOS
class MemoryManager:
def __init__(self, api_key):
self.client = MemoryOS(api_key=api_key)
def remember(self, fact, category):
"""Store a fact with category"""
self.client.store(fact, metadata={"category": category})
def recall(self, query, limit=5):
"""Retrieve relevant memories"""
return self.client.search(query, limit=limit)
def forget(self, memory_id):
"""Delete a memory"""
self.client.delete(memory_id)
# Usage
manager = MemoryManager(api_key="your-api-key")
manager.remember("User is in New York", category="location")
memories = manager.recall("where is the user")
API Reference
MemoryOS(api_key, base_url)
Initialize the MemoryOS client.
Parameters:
api_key(str): Your MemoryOS API keybase_url(str, optional): Base URL of the MemoryOS API
store(content, metadata=None)
Store a new memory.
Parameters:
content(str): Memory content (max 10,000 characters)metadata(dict, optional): Custom metadata
Returns: Memory ID (int)
search(query, limit=10)
Search memories using semantic search.
Parameters:
query(str): Search querylimit(int, optional): Max results (default: 10, max: 100)
Returns: List of Memory objects
list(limit=20, offset=0)
List all memories with pagination.
Parameters:
limit(int, optional): Results per page (default: 20, max: 100)offset(int, optional): Number to skip (default: 0)
Returns: List of Memory objects
get(memory_id)
Get a specific memory by ID.
Parameters:
memory_id(int): Memory ID
Returns: Memory object
delete(memory_id)
Delete a memory.
Parameters:
memory_id(int): Memory ID
Returns: True if successful
stats()
Get memory statistics.
Returns: MemoryStats object with total_memories, oldest_memory, newest_memory
Error Handling
from memoryos import MemoryOSError
try:
client.store("Some memory")
except MemoryOSError as e:
print(f"Error: {e.message}")
print(f"Status code: {e.status_code}")
Getting Your API Key
- Sign up at https://billiondna-vaiyukai.manus.space
- Go to your dashboard
- Create a new API key in the "API Keys" section
- Use it in your code
Support
For issues and questions, visit https://billiondna-vaiyukai.manus.space/docs
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memoryos_api-0.1.0.tar.gz.
File metadata
- Download URL: memoryos_api-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e00b94d3d564d8a3acb76454e84089e8e270b86fbd029adb2638ed39cb3f47ff
|
|
| MD5 |
39b952253572d74050ed8afafe7aaab1
|
|
| BLAKE2b-256 |
3132df1b2b39f051fb5e023f9a1b38de0a6411395eb649baf8961a3e006989da
|
File details
Details for the file memoryos_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: memoryos_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c30798ae772e31c6a8014c4b73e074451174f475120b6dce04558a141e6fc843
|
|
| MD5 |
6a3addc49b457445f218370544f26bc9
|
|
| BLAKE2b-256 |
096f6bede75dff9b09da47b93bcfc1a60a523faf43c4379543344ca30f4e13b7
|