| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
The plug-and-play memory layer for smart, contextual agents
Memlayer adds persistent, intelligent memory to any LLM in just 3 lines of code, enabling agents that recall context across conversations, extract structured knowledge, and surface relevant information when it matters.
<100ms Fast Search • Noise-Aware Memory Gate • Multi-Tier Retrieval Modes • 100% Local • Zero Config
pip install memlayerfrom memlayer import OpenAI
# Initialize with memory capabilities
client = OpenAI(
model="gpt-4.1-mini",
storage_path="./memories",
user_id="user_123"
)
# Store information automatically
client.chat([
{"role": "user", "content": "My name is Alice and I work at TechCorp"}
])
# Retrieve information automatically (no manual prompting needed!)
response = client.chat([
{"role": "user", "content": "Where do I work?"}
])
# Response: "You work at TechCorp."That's it! Memlayer automatically:
Not all conversation content is worth storing. Memlayer uses salience gates to intelligently filter:
Memories are stored in two complementary systems:
After each conversation, background threads:
Memlayer offers three modes that control both memory filtering (salience) and storage:
client = Ollama(operation_mode="local")client = OpenAI(operation_mode="online")client = OpenAI(operation_mode="lightweight")Performance Comparison:
Mode Startup Time Accuracy API Cost Storage ────────────────────────────────────────────────────────────── LOCAL ~10s High Free Vector+Graph ONLINE ~2s High $0.0001/op Vector+Graph LIGHTWEIGHT <1s Medium Free Graph-only
Memlayer provides three search tiers optimized for different latency requirements:
# Automatic - LLM chooses based on query complexity
response = client.chat([{"role": "user", "content": "What's my name?"}])# Automatic - handles most queries well
response = client.chat([{"role": "user", "content": "Tell me about my projects"}])# Explicit request or auto-detected for complex queries
response = client.chat([{
"role": "user",
"content": "Use deep search: Tell me everything about Alice and her relationships"
}])Memlayer works with all major LLM providers:
from memlayer import OpenAI
client = OpenAI(
model="gpt-4.1-mini", # or gpt-4.1, gpt-5, etc.
storage_path="./memories",
user_id="user_123"
)from memlayer import Claude
client = Claude(
model="claude-4-sonnet",
storage_path="./memories",
user_id="user_123"
)from memlayer import Gemini
client = Gemini(
model="gemini-2.5-flash",
storage_path="./memories",
user_id="user_123"
)from memlayer import Ollama
client = Ollama(
host="http://localhost:11434",
model="qwen3:14b", # or llama3.2, mistral, etc.
storage_path="./memories",
user_id="user_123",
operation_mode="local" # Run 100% offline!
)from memlayer import LMStudio
client = LMStudio(
host="http://localhost:11434/v1",
model="qwen/qwen3-14b",
storage_path="./memories",
user_id="user_123",
)All providers share the same API - switch between them seamlessly!
# User schedules a task
client.chat([{
"role": "user",
"content": "Remind me to submit the report next Friday at 9am"
}])
# Later, when the task is due, Memlayer automatically injects it
response = client.chat([{"role": "user", "content": "What should I do today?"}])
# Response includes: "Don't forget to submit the report - it's due today at 9am!"response = client.chat(messages)
# Inspect search performance
if client.last_trace:
print(f"Search tier: {client.last_trace.events[0].metadata.get('tier')}")
print(f"Total time: {client.last_trace.total_duration_ms}ms")
for event in client.last_trace.events:
print(f" {event.event_type}: {event.duration_ms}ms")# Control memory filtering strictness
client = OpenAI(
salience_threshold=-0.1 # Permissive (saves more)
# salience_threshold=0.0 # Balanced (default)
# salience_threshold=0.1 # Strict (saves less)
)# Manually extract structured knowledge
kg = client.analyze_and_extract_knowledge(
"Alice leads Project Phoenix in the London office. The project uses Python and React."
)
print(kg["facts"]) # ["Alice leads Project Phoenix", ...]
print(kg["entities"]) # [{"name": "Alice", "type": "Person"}, ...]
print(kg["relationships"]) # [{"subject": "Alice", "predicate": "leads", "object": "Project Phoenix"}]Explore the examples/ directory for comprehensive examples:
# Getting started
python examples/01_basics/getting_started.py# Try all three search tiers
python examples/02_search_tiers/fast_tier_example.py
python examples/02_search_tiers/balanced_tier_example.py
python examples/02_search_tiers/deep_tier_example.py
# Compare them side-by-side
python examples/02_search_tiers/tier_comparison.py# Proactive task reminders
python examples/03_features/task_reminders.py
# Knowledge graph visualization
python examples/03_features/test_knowledge_graph.py# Compare salience modes
python examples/04_benchmarks/compare_operation_modes.py# Try different LLM providers
python examples/05_providers/openai_example.py
python examples/05_providers/claude_example.py
python examples/05_providers/gemini_example.py
python examples/05_providers/ollama_example.pySee examples/README.md for full documentation.
Real-world startup times from benchmarks:
Mode First Use Memory Savings Trade-off ───────────────────────────────────────────────────────── LIGHTWEIGHT ~5s No embeddings No semantic search ONLINE ~5s 5s faster Small API cost LOCAL ~10s No API cost 11s model loading
Typical query latencies:
Tier Latency Vector Results Graph Use Case ──────────────────────────────────────────────────────────── Fast 50-150ms 2 No Real-time chat Balanced 200-600ms 5 No General use Deep 800-2500ms 10 Yes Research queries
Background processing (non-blocking):
Step Time Async ────────────────────────────────────────────── Salience filtering ~10ms Yes Knowledge extraction ~1-2s Yes (background thread) Vector storage ~50ms Yes Graph storage ~20ms Yes Total (non-blocking) ~0ms User doesn't wait!
The project exposes several runtime/configuration knobs you can tune to match latency, cost, and accuracy trade-offs. Detailed docs for each area live in the docs/ folder:
Use the docs when tuning for production. The following docs/ files were added to this repository and provide detailed, practical guidance.
# Clone repository
git clone https://github.com/divagr18/memlayer.git
cd memlayer
# Install dependencies
pip install -e .
# Run tests
python -m pytest tests/
# Run examples
python examples/01_basics/getting_started.pymemlayer/ ├── memlayer/ # Core library │ ├── wrappers/ # LLM provider wrappers │ ├── storage/ # Storage backends (ChromaDB, NetworkX) │ ├── services.py # Search & consolidation services │ ├── ml_gate.py # Salience filtering │ └── embedding_models.py # Embedding model implementations ├── examples/ # Organized examples by category │ ├── 01_basics/ │ ├── 02_search_tiers/ │ ├── 03_features/ │ ├── 04_benchmarks/ │ └── 05_providers/ ├── tests/ # Tests and benchmarks ├── docs/ # Documentation └── README.md # This file
Contributions are welcome! Here's how you can help:
Please keep PRs focused and include tests for new features.
For security vulnerabilities, please email directly with SECURITY in the subject line instead of opening a public issue.
MIT License - see LICENSE for details.
Made with ❤️ for the AI community
Give your LLMs memory. Try Memlayer today!
| Back | FazBrowse Home | New Git URL |