Memori automatically captures information from conversations and recalls it when relevant. This guide shows you how to get started with basic memory operations.
from openai import OpenAIfrom memori import Memori# Initialize OpenAI clientclient = OpenAI()# Initialize Memori and register the LLM clientmem = Memori().llm.register(client)mem.attribution(entity_id="user-123", process_id="my-app")# First conversation - establish factsresponse1 = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "user", "content": "My favorite color is blue and I live in Paris"} ],)print(response1.choices[0].message.content)# Second conversation - Memori recalls context automaticallyresponse2 = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "What's my favorite color?"}],)print(response2.choices[0].message.content) # Output: "Your favorite color is blue"
import { OpenAI } from 'openai';import { Memori } from 'memori';// Initialize OpenAI clientconst client = new OpenAI();// Initialize Memori and register the LLM clientconst mem = new Memori().llm.register(client);mem.attribution('user-123', 'my-app');async function main() { // First conversation - establish facts const response1 = await client.chat.completions.create({ model: 'gpt-4o-mini', messages: [ { role: 'user', content: 'My favorite color is blue and I live in Paris' } ], }); console.log(response1.choices[0]?.message?.content); // Give the cloud API a brief moment to index the new memory await new Promise((resolve) => setTimeout(resolve, 2000)); // Second conversation - Memori recalls context automatically const response2 = await client.chat.completions.create({ model: 'gpt-4o-mini', messages: [{ role: 'user', content: "What's my favorite color?" }], }); console.log(response2.choices[0]?.message?.content); // Output: "Your favorite color is blue"}main().catch(console.error);
You can manually retrieve relevant memories without making an LLM call.
Python
TypeScript
from memori import Memorimem = Memori()mem.attribution(entity_id="user-123")# Manually search for relevant factsfacts = mem.recall("What are my preferences?")for fact in facts: print(f"- {fact['content']}") print(f" Relevance: {fact.get('score', 0):.2f}")
import { Memori } from 'memori';const mem = new Memori();mem.attribution('user-123');// Manually search for relevant factsconst facts = await mem.recall('What are my preferences?');facts.forEach((fact) => { console.log(`- ${fact.content}`); console.log(` Relevance: ${fact.score?.toFixed(2)}`);});