MCPcopy Create free account
hub / github.com/CaviraOSS/OpenMemory / basicExample

Function basicExample

examples/js-sdk/basic-usage.js:3–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import { OpenMemory } from 'openmemory-sdk';
2
3async function basicExample() {
4 console.log('🧠 OpenMemory JavaScript SDK - Basic Example');
5 console.log('============================================');
6
7 // Initialize with local-first configuration
8 const mem = new OpenMemory({
9 path: './data/demo.sqlite',
10 tier: 'fast',
11 embeddings: {
12 provider: 'synthetic' // Use 'openai', 'gemini', 'ollama', or 'synthetic'
13 }
14 });
15
16 console.log('✅ OpenMemory initialized (local-first mode)');
17
18 // Add some memories
19 console.log('\n1. Adding memories...');
20 const mem1 = await mem.add("I went to Paris yesterday and loved the Eiffel Tower", {
21 tags: ["travel", "paris"],
22 metadata: { location: "Paris, France" }
23 });
24 console.log(`✅ Episodic memory stored: ${mem1.id}`);
25
26 const mem2 = await mem.add("I feel really excited about the new AI project", {
27 tags: ["emotion", "ai"]
28 });
29 console.log(`✅ Emotional memory stored: ${mem2.id}`);
30
31 const mem3 = await mem.add("My morning routine: coffee, then check emails, then code", {
32 tags: ["routine", "procedural"]
33 });
34 console.log(`✅ Procedural memory stored: ${mem3.id}`);
35
36 // Query memories
37 console.log('\n2. Querying memories...');
38 const results = await mem.query("Paris travel experience", { limit: 5 });
39 console.log(`✅ Found ${results.length} matching memories:`);
40
41 results.forEach((match, i) => {
42 console.log(` ${i+1}. [score: ${match.score?.toFixed(3)}] ${match.content.substring(0, 50)}...`);
43 });
44
45 // Get all memories
46 console.log('\n3. Listing all memories...');
47 const all = await mem.getAll({ limit: 10 });
48 console.log(`✅ Total memories: ${all.length}`);
49
50 // Delete a memory
51 if (results.length > 0) {
52 console.log('\n4. Deleting a memory...');
53 await mem.delete(results[results.length - 1].id);
54 console.log('✅ Memory deleted');
55 }
56
57 console.log('\n✨ Example completed!');
58}
59
60basicExample().catch(console.error);

Callers 1

basic-usage.jsFile · 0.85

Calls 4

addMethod · 0.95
queryMethod · 0.95
getAllMethod · 0.95
deleteMethod · 0.95

Tested by

no test coverage detected