Getting Started with Memoid
Set up your first memory-enabled AI application in under 10 minutes.
Prerequisites
- Python 3.8+ or Node.js 18+
- A Memoid account (free tier available)
- Basic understanding of REST APIs
In this tutorial, you’ll learn how to set up Memoid and add memory to your first AI application.
Step 1: Create an Account
First, sign up for a free Memoid account at memoid.dev/register.
Once logged in, navigate to the Dashboard and create your first project.
Step 2: Get Your API Key
In your project settings, you’ll find your API key. Copy it — you’ll need it for the next steps.
# Your API key will look something like this:
mem_sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx Keep it safe! Never commit your API key to version control.
Step 3: Install the SDK
Choose your preferred language:
Python
pip install memoid JavaScript/Node.js
npm install memoid
# or
pnpm add memoid Go
go get github.com/memoid/memoid-go Step 4: Initialize the Client
Create a new file and initialize the Memoid client:
Python
from memoid import MemoryClient
client = MemoryClient("your-api-key") JavaScript
import { MemoryClient } from 'memoid';
const client = new MemoryClient('your-api-key'); Step 5: Add Your First Memory
Now let’s store a memory from a conversation:
Python
# Add a memory
result = client.add(
messages=[
{"role": "user", "content": "My name is Alex and I love hiking"},
{"role": "assistant", "content": "Nice to meet you, Alex! Hiking is great exercise."}
],
user_id="user_123"
)
print(f"Added {len(result.memories)} memories")
# Output: Added 2 memories
# - User's name is Alex
# - User loves hiking JavaScript
const result = await client.add({
messages: [
{ role: 'user', content: 'My name is Alex and I love hiking' },
{ role: 'assistant', content: 'Nice to meet you, Alex! Hiking is great exercise.' }
],
userId: 'user_123'
});
console.log(`Added ${result.memories.length} memories`); Step 6: Search Memories
Now search for relevant memories using natural language:
Python
# Search memories
results = client.search(
query="What are the user's hobbies?",
user_id="user_123",
limit=5
)
for memory in results:
print(f"- {memory.memory} (score: {memory.score:.2f})")
# Output:
# - User loves hiking (score: 0.92) JavaScript
const results = await client.search({
query: "What are the user's hobbies?",
userId: 'user_123',
limit: 5
});
results.forEach(m => {
console.log(`- ${m.memory} (score: ${m.score.toFixed(2)})`);
}); Step 7: Use Memories in Your App
Here’s a complete example integrating memories with OpenAI:
import openai
from memoid import MemoryClient
memory = MemoryClient("your-memoid-key")
openai.api_key = "your-openai-key"
def chat_with_memory(user_id: str, message: str) -> str:
# Get relevant memories
memories = memory.search(query=message, user_id=user_id, limit=5)
# Build context from memories
context = "\n".join([f"- {m.memory}" for m in memories])
# Generate response with context
response = openai.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": f"You are a helpful assistant. Here's what you know about this user:\n{context}"
},
{"role": "user", "content": message}
]
)
assistant_reply = response.choices[0].message.content
# Store the conversation
memory.add(
messages=[
{"role": "user", "content": message},
{"role": "assistant", "content": assistant_reply}
],
user_id=user_id
)
return assistant_reply
# Try it out
response = chat_with_memory("user_123", "What outdoor activities do you think I'd enjoy?")
print(response)
# The assistant will know you love hiking and can make personalized suggestions! Next Steps
Congratulations! You’ve added memory to your AI application. Here’s what to explore next:
- Building a Chatbot with Memory — A complete chatbot implementation
- Semantic Search Deep Dive — Advanced search techniques
- Knowledge Graphs — Extract entities and relationships
Need Help?
- Check out the full documentation
- Join our Discord community
- Email us at support@memoid.dev