Bi-temporal knowledge graph memory system using ryugraph
Project description
Ryumem
Bi-temporal Knowledge Graph Memory System
Ryumem is a production-ready memory system for building intelligent agents with persistent, queryable memory using a bi-temporal knowledge graph architecture.
Features
✨ Key Capabilities:
- 📝 Episode-first ingestion - Every piece of information starts as an episode
- 🧠 Automatic entity & relationship extraction - Powered by LLM (OpenAI, Gemini, Ollama, or LiteLLM)
- ⏰ Bi-temporal data model - Track when facts were valid and when they were recorded
- 🔍 Advanced hybrid retrieval - Combines semantic search, BM25 keyword search, and graph traversal
- ⏱️ Temporal decay scoring - Recent facts automatically score higher with configurable decay
- 🌐 Community detection - Automatic clustering of related entities using Louvain algorithm
- 🧹 Memory pruning & compaction - Keep graphs efficient by removing obsolete data
- 👥 Full multi-tenancy - Support for user_id, agent_id, session_id, group_id
- ♻️ Automatic contradiction handling - Detects and invalidates outdated facts
- 📊 Incremental updates - No batch reprocessing required
- 🔧 Automatic tool tracking - Track all tool executions and query patterns
- 🔄 Query augmentation - Enrich queries with historical context from similar past queries
- ⚙️ Dynamic configuration - Hot-reload settings without server restart
- 🎨 Beautiful web dashboard - Modern Next.js UI with graph visualization
Quick Start
Getting Access
To use Ryumem, request API access from contact@predictable.sh. You'll receive:
- API endpoint URL
- API key (starts with
ryu_)
Installation
pip install ryumem
Basic Usage with Google ADK
from google.adk.agents import Agent
from google.adk.tools import FunctionTool
from ryumem import Ryumem
from ryumem.integrations import add_memory_to_agent, wrap_runner_with_tracking
# Initialize Ryumem - auto-loads from environment variables
# RYUMEM_API_URL and RYUMEM_API_KEY
ryumem = Ryumem(
augment_queries=True, # Enable query augmentation
similarity_threshold=0.3, # Match queries with 30%+ similarity
top_k_similar=5, # Use top 5 similar queries for context
)
# Create your agent with tools
agent = Agent(
model="gemini-2.0-flash-exp",
name="my_agent",
instruction="You are a helpful assistant with memory.",
tools=[...] # Your tools here
)
# Add memory to agent - automatically creates search_memory() and save_memory() tools
agent = add_memory_to_agent(agent, ryumem)
# Wrap runner for automatic tool tracking and query augmentation
runner = wrap_runner_with_tracking(runner, agent)
Environment Setup
# Required - Get from contact@predictable.sh
export RYUMEM_API_URL="https://api.ryumem.io" # Your endpoint
export RYUMEM_API_KEY="ryu_..." # Your API key
Python SDK Usage
Initialization
The Ryumem client automatically loads configuration from environment variables:
from ryumem import Ryumem
# Basic initialization - loads RYUMEM_API_URL and RYUMEM_API_KEY from env
ryumem = Ryumem()
# With query augmentation enabled
ryumem = Ryumem(
augment_queries=True, # Enable augmentation with historical context
similarity_threshold=0.3, # Match queries with 30%+ similarity
top_k_similar=5, # Use top 5 similar queries
)
# With tool tracking enabled
ryumem = Ryumem(
track_tools=True, # Automatically track all tool executions
augment_queries=True, # Augment with historical tool usage
)
Configuration Options
ryumem = Ryumem(
# Query Augmentation
augment_queries=True, # Enable query augmentation (default: False)
similarity_threshold=0.3, # Similarity threshold for augmentation (default: 0.5)
top_k_similar=5, # Number of similar queries to use (default: 3)
# Tool Tracking
track_tools=True, # Enable automatic tool tracking (default: False)
# Entity Extraction
extract_entities=True, # Enable entity extraction (default: True)
# Search Settings
default_strategy="hybrid", # Default search strategy
)
Core Operations
# The SDK provides auto-generated tools when integrated with agents:
# - search_memory(query: str) -> results
# - save_memory(content: str) -> confirmation
# These tools are automatically available to your agent after:
agent = add_memory_to_agent(agent, ryumem)
Google ADK Integration
Complete Example
import asyncio
from google.adk.agents import Agent
from google.adk.tools import FunctionTool
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
from ryumem import Ryumem
from ryumem.integrations import add_memory_to_agent, wrap_runner_with_tracking
# App configuration
APP_NAME = "my_app"
USER_ID = "user_123"
SESSION_ID = "session_456"
# Define your tools
def get_weather(city: str) -> dict:
"""Get weather for a city."""
return {"status": "success", "report": f"Weather in {city} is sunny"}
weather_tool = FunctionTool(func=get_weather)
# Create agent
agent = Agent(
model="gemini-2.0-flash-exp",
name="weather_agent",
instruction="You are a helpful weather assistant with memory.",
tools=[weather_tool]
)
# Add memory + tool tracking + query augmentation in ONE line!
ryumem = Ryumem(
augment_queries=True,
similarity_threshold=0.3,
top_k_similar=5,
)
agent = add_memory_to_agent(agent, ryumem)
# Setup session and runner
async def main():
session_service = InMemorySessionService()
await session_service.create_session(
app_name=APP_NAME,
user_id=USER_ID,
session_id=SESSION_ID
)
runner = Runner(
agent=agent,
app_name=APP_NAME,
session_service=session_service
)
# Wrap runner to automatically track queries and augment with history
runner = wrap_runner_with_tracking(runner, agent)
# Use the runner
content = types.Content(
role='user',
parts=[types.Part(text="What's the weather in London?")]
)
events = runner.run(
user_id=USER_ID,
session_id=SESSION_ID,
new_message=content
)
# Process response
for event in events:
if event.is_final_response():
print(event.content.parts[0].text)
asyncio.run(main())
Features Demonstrated
-
Automatic Tool Tracking: All tool executions are logged with:
- Tool name and parameters
- Execution results
- Timestamp and user context
- Hierarchical episode tracking (queries link to tool executions)
-
Query Augmentation: Similar past queries enrich new queries with:
- Historical tool usage patterns
- Previous results and context
- Learned patterns and relationships
-
Memory Integration: Agent automatically gets two new tools:
search_memory(query)- Search the knowledge graphsave_memory(content)- Store new information
Examples
See the examples/ directory for complete working examples:
Key Examples
-
- Demonstrates automatic tool tracking and query augmentation
- Weather + sentiment analysis agent
- Shows how similar queries share context
-
- Tests query augmentation with a password guessing game
- Agent learns from previous attempts
- Demonstrates pattern recognition across similar queries
Other Examples
- basic_usage.py - Core features walkthrough
- ollama_usage.py - Local Ollama models
- litellm_usage.py - Multiple LLM providers
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 ryumem-0.1.5.tar.gz.
File metadata
- Download URL: ryumem-0.1.5.tar.gz
- Upload date:
- Size: 64.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fca38547e4a40a230f94b42e3c20c0a2203e3cefb638d8aba94b4d8201e776d3
|
|
| MD5 |
ffcd4a5f5c6765e0c6d4f92ddcc2931c
|
|
| BLAKE2b-256 |
ce80c5c99296a2f62b4c283275b6fc11f9e21e6dec54eb0fb9023e40e6a8c559
|
File details
Details for the file ryumem-0.1.5-py3-none-any.whl.
File metadata
- Download URL: ryumem-0.1.5-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87cd0e0b03b24ffd5e0c44f0dcd3c2298db593287d114d576472c4da7466738d
|
|
| MD5 |
8209f1fbc10bf315d5d347a6d953b949
|
|
| BLAKE2b-256 |
1fd9ce356e22c41fe45ffb2d58795c82632958bcd030596d5f575093068cc60d
|