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.1.tar.gz (17.1 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.1-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: graph_rag_memory-0.1.1.tar.gz
  • Upload date:
  • Size: 17.1 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.1.tar.gz
Algorithm Hash digest
SHA256 c388825b6fc35ad0a8370e6748ca8c8f9eeec7145c9300ecf6b4a04329daf7ec
MD5 a41569330dd0f0f1179a75a22024d892
BLAKE2b-256 09b3626946475edd394f3f402a0376a750e2d94ea91f41e04943beb8ecc0b83b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graph_rag_memory-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2cd79dd745850b1aabefde870b33419568b172c8ae2471759b520470ef5587a
MD5 f8aae039c1b11c6464ada390a8acb4f8
BLAKE2b-256 e9424798d0828886b76903fc03c797521543c04418ddc1bcaab4f6ed7036c111

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