Back to Home
ODAM Documentation
API Reference & Guides
Code Examples & Use Cases
Practical examples showing how to integrate ODAM into different types of applications
Quick Integration Examples
Python - Basic Chat with Memory
Python
import requests
from datetime import datetime
class ChatWithMemory:
def __init__(self, user_id):
self.user_id = user_id
self.session_id = f"chat_{datetime.now().isoformat()}"
def chat(self, message):
# Get relevant memories from ODAM
memories = self.get_memories(message)
# Build context with memories
context = self.build_context(memories, message)
# Get AI response with context
response = self.get_ai_response(context)
# Save interaction to ODAM
self.save_interaction(message, response)
return response
def get_memories(self, query):
response = requests.post(
"http://localhost:8080/api/v1/search",
json={
"query": query,
"user_id": self.user_id,
"limit": 5
}
)
return response.json().get("memories", [])
# Usage
chat = ChatWithMemory("user123")
response = chat.chat("Hi, I'm Alex from Kyiv!")
print(response)
JavaScript - React Integration
JavaScript (React)
const ChatWithODAM = ({ userId }) => {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');
const sendMessage = async (message) => {
try {
const response = await fetch('/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message,
user_id: userId,
session_id: 'chat_' + Date.now()
})
});
const data = await response.json();
setMessages(prev => [
...prev,
{ role: 'user', content: message },
{ role: 'assistant', content: data.response }
]);
} catch (error) {
console.error('Chat error:', error);
}
};
return (
<div className="chat-container">
{/* Chat interface */}
</div>
);
};
Use Case Examples
Customer Support Bot
Remember customer history, previous issues, and preferences for personalized support.
Key Features:
- • Customer purchase history tracking
- • Previous support ticket context
- • Personalized communication style
- • Issue resolution tracking
Personal AI Assistant
Build AI companions that remember personal details, relationships, and life events.
Memory Types:
- • Personal preferences and interests
- • Family and relationship details
- • Important dates and events
- • Goals and aspirations
Educational AI Tutor
Track learning progress, identify knowledge gaps, and adapt teaching styles.
Learning Features:
- • Learning progress tracking
- • Knowledge gap identification
- • Adaptive teaching methods
- • Personalized curriculum
Performance Tips
•Cache frequent queries: Cache common memory searches to reduce API calls
•Batch operations: Group multiple memory operations when possible
•Async processing: Handle memory operations asynchronously for better UX