Skip to main content

Graphmemo

A blazingly fast, agentic BYOK memory library for chatbots.

PyPI Version Python Versions License Downloads


Graphmemo provides a sub-400ms 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

  • < 400ms 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:

  1. 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: ~300-400ms.
  2. 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.

Metadata

Release files for graphmemo 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphmemo 0.1.2
File Size Uploaded Provenance Actions
graphmemo-0.1.2.tar.gz 19.0 kB Without provenance Details for graphmemo-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graphmemo 0.1.2
File Interpreter ABI Platform Actions
graphmemo-0.1.2-py3-none-any.whl Python 3 none any Details for graphmemo-0.1.2-py3-none-any.whl

Total release size: 37.6 kB

Release files / graphmemo-0.1.2.tar.gz

Download URL graphmemo-0.1.2.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2b496ab443244977bdbcc891601a0940561ba7d59073c0d2f8c6ddafd30ced82
BLAKE2b-256 checksum
How to use checksums
8279adc7fb9685aa2f95543ca8381e83afbdf803fe49275d3e6c1f7fdcd7d257
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / graphmemo-0.1.2-py3-none-any.whl

Download URL graphmemo-0.1.2-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be962e675f717096af51d0f097d5bcc34fc84b85acf90bebd7822e0a3b1e89a0
BLAKE2b-256 checksum
How to use checksums
36a99f25ba0271b584af336dbc2268948e77be04b9e04456965f986e0d69b845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for graphmemo 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page