This folder contains examples for each supported LLM provider.
Choose your provider and run the corresponding example:
export OPENAI_API_KEY='sk-...'
python examples/05_providers/openai_example.pyModels: gpt-5, gpt-4.1, gpt-4.1-mini
export ANTHROPIC_API_KEY='sk-ant-...'
python examples/05_providers/claude_example.pyModels: claude-4-5-sonnet, claude-4-5-haiku, claude-4-opus
export GOOGLE_API_KEY='...'
python examples/05_providers/gemini_example.pyModels: gemini-2.5-flash-lite, gemini-2.5-pro, gemini-2.5-flash
# No API key needed! Run locally
ollama pull qwen3:1.7b
python examples/05_providers/ollama_example.pyModels: llama3.2, qwen3, mistral, phi3, deepseek-r1, and 100+ more
export OPENAI_API_KEY='your-key-here'
export ANTHROPIC_API_KEY='your-key-here'
export GOOGLE_API_KEY='your-key-here'$env:OPENAI_API_KEY='your-key-here'
$env:ANTHROPIC_API_KEY='your-key-here'
$env:GOOGLE_API_KEY='your-key-here'set OPENAI_API_KEY=your-key-here
set ANTHROPIC_API_KEY=your-key-here
set GOOGLE_API_KEY=your-key-here| Provider | Best For | Cost | Speed | Quality |
|---|---|---|---|---|
| OpenAI | General purpose, production apps | $$$ | Fast | Excellent |
| Claude | Long context, detailed analysis | $$$ | Medium | Excellent |
| Gemini | Multimodal, fast prototyping | $$ | Very Fast | Good |
| Ollama | Privacy, offline, no cost | FREE | Variable | Good |
All providers share the same API:
from memlayer.wrappers.{provider} import {Provider}
# Initialize with memory
client = Provider(
model="model-name",
storage_path="./memories",
user_id="user_id",
operation_mode="local" # or "online" or "lightweight"
)
# Chat with automatic memory
response = client.chat(messages=[
{"role": "user", "content": "Remember my name is Alice"}
])
# Memory is automatically stored and retrieved!Each provider supports three memory modes:
- Uses sentence-transformers locally
- High accuracy semantic filtering
- ~10s startup time, no API costs
- Best for: High-volume usage, offline apps
- Uses OpenAI embeddings API
- Fast startup (~2s), small API cost
- Requires OPENAI_API_KEY
- Best for: Production apps, serverless
- Keyword-based filtering only
- Instant startup, no embeddings
- Best for: Prototyping, testing
Example:
client = Provider(
model="...",
operation_mode="online", # Fast startup!
storage_path="./memories"
)- Mix and match: Use different providers for different tasks
- Ollama for dev: Use Ollama locally, then switch to cloud provider for production
- Online mode for serverless: Use
operation_mode="online"in AWS Lambda/Cloud Functions - Share memories: All providers can read the same memory storage if using same
storage_path
- Basics:
examples/01_basics/ - Search Tiers:
examples/02_search_tiers/ - Advanced Features:
examples/03_features/ - Benchmarks:
examples/04_benchmarks/