Skip to main content

A BYOK Hierarchical Graph Memory library for AI agents.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphmemo-0.1.2.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphmemo-0.1.2-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file graphmemo-0.1.2.tar.gz.

File metadata

  • Download URL: graphmemo-0.1.2.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

Hashes for graphmemo-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2b496ab443244977bdbcc891601a0940561ba7d59073c0d2f8c6ddafd30ced82
MD5 115957df89af48d37dffb27bf4f58d35
BLAKE2b-256 8279adc7fb9685aa2f95543ca8381e83afbdf803fe49275d3e6c1f7fdcd7d257

See more details on using hashes here.

File details

Details for the file graphmemo-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: graphmemo-0.1.2-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

Hashes for graphmemo-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be962e675f717096af51d0f097d5bcc34fc84b85acf90bebd7822e0a3b1e89a0
MD5 814936c39b571d06e50f3ee31ced23e8
BLAKE2b-256 36a99f25ba0271b584af336dbc2268948e77be04b9e04456965f986e0d69b845

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page