Skip to main content

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 key
  • base_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 query
  • limit (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

  1. Sign up at https://billiondna-vaiyukai.manus.space
  2. Go to your dashboard
  3. Create a new API key in the "API Keys" section
  4. Use it in your code

Support

For issues and questions, visit https://billiondna-vaiyukai.manus.space/docs

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memoryos_api-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memoryos_api-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for memoryos_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e00b94d3d564d8a3acb76454e84089e8e270b86fbd029adb2638ed39cb3f47ff
MD5 39b952253572d74050ed8afafe7aaab1
BLAKE2b-256 3132df1b2b39f051fb5e023f9a1b38de0a6411395eb649baf8961a3e006989da

See more details on using hashes here.

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

Hashes for memoryos_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c30798ae772e31c6a8014c4b73e074451174f475120b6dce04558a141e6fc843
MD5 6a3addc49b457445f218370544f26bc9
BLAKE2b-256 096f6bede75dff9b09da47b93bcfc1a60a523faf43c4379543344ca30f4e13b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page