A BYOK Hierarchical Graph Memory library for AI agents.
Project description
Graphmemo provides a sub-200ms dual-layered memory architecture (L1 Short-Term Buffer + L2 Hierarchical Graph) designed for LLM agents. It completely eliminates the latency of traditional RAG by executing graph construction asynchronously while providing instant routing.
🚀 Key Features
- < 200ms Retrieval Latency: Never wait for an LLM to read chat history. The query context is returned instantly.
- Async Graph Construction: Builds a conceptual memory graph in the background without blocking the user conversation.
- Dual Semantic Search: Prevents "Catastrophic Misrouting" by searching against both exact Topic Labels and Expanded Topic Descriptions.
- Bring Your Own Key (BYOK): Use your own free local embeddings (e.g., HuggingFace) and your own LLM provider (Groq, OpenAI, Gemini) to avoid vendor lock-in and high SaaS fees.
- 100% Local DB: Stores state cleanly in a local FAISS index + SQLite/SQLAlchemy database, meaning your data never leaves your environment.
📦 Installation
Graphmemo is lightweight and highly modular.
For a lightning-fast install (if using external API embeddings like OpenAI, Google, Anthropic):
pip install graphmemo
To include local embeddings (installs sentence-transformers and PyTorch, which may take a few minutes):
pip install "graphmemo[local]"
⚡ Quick Start
Because this library requires no paid SaaS subscription, you must inject your own LLM and Embedding functions.
import os
from pydantic import BaseModel
from typing import Optional, Any
from groq import Groq
from sentence_transformers import SentenceTransformer
from graphmemo import MemoryClient
# 1. Define your free local embedder
embedder = SentenceTransformer('all-MiniLM-L6-v2')
def embed_func(text: str) -> list[float]:
return embedder.encode(text).tolist()
# 2. Define your LLM generator (e.g., using Groq for blazing speed)
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
def llm_func(sys_prompt: str, user_prompt: str, schema: Optional[BaseModel] = None) -> Any:
# If a Pydantic schema is provided, force JSON output
# (Implementation omitted for brevity, use instructor or standard JSON mode)
pass
# 3. Initialize the Memory Client
memory = MemoryClient(
llm_generate=llm_func,
embed_text=embed_func,
use_query_expansion=True # Turn off for absolute maximum speed
)
# 4. Use it in your chatbot loop
user_id = "user_123"
# Add messages (silently batches to the Graph in the background)
memory.add_message(user_id, "user", "I bought a new Tesla Model 3 today!")
# Retrieve instant, highly accurate context for your chatbot's prompt
context = memory.retrieve_context(user_id, "What car do I drive?")
print(context['short_term_history'])
print(context['long_term_graph_context'])
print(context['global_state'])
📖 Architecture Overview
Graphmemo relies on a dual-engine system:
- The Fast Router: When a user queries your agent, Graphmemo bypasses the LLM entirely. It embeds the query and runs a highly optimized multi-dimensional FAISS search over your historical topic graph. Latency:
~50-150ms. - The Background Constructor: As the user speaks, Graphmemo silently pushes conversations into an Async Queue. An LLM agent processes batches in the background, updating topics and maintaining global state quantitative values without blocking the chat UI.
🤝 Contributing
Contributions are welcome! If you find a bug, or have a feature request, please open an issue.
📄 License
Graphmemo is MIT Licensed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphmemo-0.1.1.tar.gz.
File metadata
- Download URL: graphmemo-0.1.1.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfb9260d6bd5b4a99b47bd23c49ca86781c78f4f764e87f889559223be56a8fc
|
|
| MD5 |
54e408d01cb629fb1486297f637bdb4f
|
|
| BLAKE2b-256 |
1e3f33a08570595067d8805719adfb58e050792ee5a7e5ca4197e7d16afbcba1
|
File details
Details for the file graphmemo-0.1.1-py3-none-any.whl.
File metadata
- Download URL: graphmemo-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bd20efc806f79d3179838791f771bae3098f5651e86c28ec32ff7c626d3f85d
|
|
| MD5 |
fa2463e4474784b40e3c8b40ce4091bf
|
|
| BLAKE2b-256 |
5b624d701095527e9e5c03d3c52bca745f71401e833c723a7c6cd7b52923c99d
|