Installation
pip install memorymachines
Quick Start
from memorymachines import MemoryMachines
mm = MemoryMachines( api_key = "YOUR_API_KEY" )
# Upload a document
mm.memorize( "meeting-notes.txt" )
# Ask a question
response = mm.ask( "What were the action items?" )
print (response)
Authentication
Direct
Environment Variable
mm = MemoryMachines( api_key = "YOUR_API_KEY" )
Store your API key in an environment variable for production use.
Methods
memorize()
Upload a document for memory extraction.
# From file path
result = mm.memorize( "notes.txt" )
# With metadata
result = mm.memorize(
"notes.txt" ,
user_name = "Alice" ,
source_type = "text" ,
item_id = "custom-id-123"
)
Path to the file to upload
Name associated with the memories
Type of content: text, email, notes, etc.
Custom identifier for the document
ask()
Ask a question and get an LMM-synthesized response.
response = mm.ask( "What did we discuss in the last meeting?" )
print (response)
# "Based on your meeting notes from January 15th, you discussed..."
Your question about stored memories
recall()
Retrieve raw memories without LMM synthesis.
memories = mm.recall( "meeting" )
for memory in memories:
print (memory.narrative)
print (memory.participants)
print (memory.when)
Search query for semantic memory retrieval
Returns a list of Memory objects with:
Field Type Description narrativestr First-person memory description participantslist People involved whenstr When it occurred wherestr Location (if known) tagslist Extracted keywords scorefloat Relevance score (0-1)
feedback()
Rate a memory to improve future results.
mm.feedback(
memory_id = "abc123_memory_0" ,
query = "action items" ,
rating = 1 # 1 = relevant, -1 = not relevant
)
The query that returned this memory
1 for relevant, -1 for not relevant
health()
Check API status.
status = mm.health()
print (status) # {"status": "healthy", "message": "..."}
Error Handling
from memorymachines import MemoryMachines, MemoryMachinesError
mm = MemoryMachines( api_key = "YOUR_API_KEY" )
try :
mm.memorize( "document.txt" )
except MemoryMachinesError as e:
print ( f "Error: { e } " )
Exception Cause AuthenticationErrorInvalid API key RateLimitErrorToo many requests ValidationErrorInvalid parameters MemoryMachinesErrorOther API errors
Complete Example
from memorymachines import MemoryMachines
mm = MemoryMachines()
# Upload meeting notes
result = mm.memorize(
"meeting-notes.txt" ,
user_name = "Alice" ,
source_type = "notes"
)
print ( f "Uploaded: { result[ 'item_id' ] } " )
# Wait for processing (10-15 seconds)
import time
time.sleep( 15 )
# Ask questions
answer = mm.ask( "What are my action items?" )
print (answer)
# Get raw memories
memories = mm.recall( "meeting" )
for m in memories:
print ( f "- { m.narrative } " )
# Provide feedback
if memories:
mm.feedback(
memory_id = memories[ 0 ].custom_id,
query = "meeting" ,
rating = 1
)
Next Steps