Skip to main content

A BYOK Hierarchical Graph Memory library for AI agents.

Project description

Graph-Memory

A blazingly fast, agentic memory library for Chatbots. Graph-Memory combines an L1 Short-Term Buffer with a background L2 Hierarchical Topic Graph and Quantitative JSON State.

Features

  • < 200ms Retrieval Latency: Never wait for an LLM to read chat history.
  • Async Graph Construction: Builds a conceptual memory graph in the background without blocking the user.
  • Dual Semantic Search: Prevents "Catastrophic Misrouting" by searching against both 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.

Installation

pip install graph-rag-memory

Quick Start (BYOK)

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 graph_memory 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'])

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

graph_rag_memory-0.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

graph_rag_memory-0.1.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file graph_rag_memory-0.1.0.tar.gz.

File metadata

  • Download URL: graph_rag_memory-0.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for graph_rag_memory-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bbbdfda87cb8d630483917cfad4df9f1c3c38a7b1c6387d5fe398a8bf2fe3d8c
MD5 e32cc1724d13fad5021205feb3ca904a
BLAKE2b-256 a4f9f5208d9a927e3787a8e2fc0f8b44a784a745737d233a5a90f069efbbe12d

See more details on using hashes here.

File details

Details for the file graph_rag_memory-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for graph_rag_memory-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6655f36221564d83c012be66c0e9e30d9401259132dac1d79fee4baccdc157f
MD5 d734c56208478af1c249c9fd274b7312
BLAKE2b-256 2a7c7bc21b7952f5e476c6d925bfa966503909860f86ca7f1563c96d277f533a

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