()
| 7 | from openmemory import OpenMemory |
| 8 | |
| 9 | def basic_example(): |
| 10 | print('🧠 OpenMemory Python SDK - Basic Example') |
| 11 | print('=========================================') |
| 12 | |
| 13 | # Initialize with local-first configuration |
| 14 | mem = OpenMemory( |
| 15 | path='./data/demo.sqlite', |
| 16 | tier='fast', |
| 17 | embeddings={ |
| 18 | 'provider': 'synthetic' # Use 'openai', 'gemini', 'ollama', or 'synthetic' |
| 19 | } |
| 20 | ) |
| 21 | |
| 22 | print('✅ OpenMemory initialized (local-first mode)') |
| 23 | |
| 24 | # Add some memories |
| 25 | print('\n1. Adding memories...') |
| 26 | mem1 = mem.add("I went to Paris yesterday and loved the Eiffel Tower", |
| 27 | tags=["travel", "paris"], |
| 28 | metadata={"location": "Paris, France"}) |
| 29 | print(f"✅ Episodic memory stored: {mem1['id']}") |
| 30 | |
| 31 | mem2 = mem.add("I feel really excited about the new AI project", |
| 32 | tags=["emotion", "ai"]) |
| 33 | print(f"✅ Emotional memory stored: {mem2['id']}") |
| 34 | |
| 35 | mem3 = mem.add("My morning routine: coffee, then check emails, then code", |
| 36 | tags=["routine", "procedural"]) |
| 37 | print(f"✅ Procedural memory stored: {mem3['id']}") |
| 38 | |
| 39 | # Query memories |
| 40 | print('\n2. Querying memories...') |
| 41 | results = mem.query("Paris travel experience") |
| 42 | print(f"✅ Found {len(results)} matching memories:") |
| 43 | |
| 44 | for i, match in enumerate(results): |
| 45 | content_preview = match['content'][:50] + "..." if len(match['content']) > 50 else match['content'] |
| 46 | score = match.get('score', 0) |
| 47 | print(f" {i+1}. [score: {score:.3f}] {content_preview}") |
| 48 | |
| 49 | # Get all memories |
| 50 | print('\n3. Listing all memories...') |
| 51 | all_mems = mem.getAll(limit=10) |
| 52 | print(f"✅ Total memories: {len(all_mems)}") |
| 53 | |
| 54 | # Delete a memory |
| 55 | if results: |
| 56 | print('\n4. Deleting a memory...') |
| 57 | mem.delete(results[-1]['id']) |
| 58 | print('✅ Memory deleted') |
| 59 | |
| 60 | print('\n✨ Example completed!') |
| 61 | mem.close() |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | basic_example() |
no test coverage detected