Production-Grade Agent Memory Framework for Agentic AI
Project description
๐ง GraphMem
Production-Grade Agent Memory Framework for Agentic AI
GraphMem is a state-of-the-art, self-evolving graph-based memory system designed for production-scale agentic AI applications. It provides human-like memory capabilities with automatic consolidation, decay, and rehydrationโall built on enterprise-grade storage backends.
โจ Key Features
๐ Self-Evolving Memory
- Memory Consolidation: Automatically merges related memories into coherent knowledge
- Importance Decay: Less relevant memories naturally fade over time
- Rehydration: Revive and strengthen memories when accessed
- Continuous Learning: Memory improves through usage patterns
๐ธ๏ธ Graph-Based Knowledge
- Entity Resolution: Intelligent deduplication and canonicalization
- Community Detection: Automatic topic clustering
- Rich Relationships: Capture complex entity connections
- Semantic Search: Find relevant context by meaning
๐ Multi-Modal Context Engineering
- Text Documents: Intelligent chunking with semantic boundaries
- PDFs: Extract text, images, and tables
- Images: OCR and vision model analysis
- Audio: Transcription to text
- Web Pages: Smart content extraction
- Code Files: Language-aware chunking
- Structured Data: JSON, CSV processing
๐ Production Ready
- Neo4j Backend: Enterprise graph database
- Redis Caching: Sub-millisecond retrieval
- Parallel Processing: Concurrent knowledge extraction
- Retry Logic: Resilient to transient failures
- Scalable: Handles millions of memories
๐ Quick Start
Installation
pip install graphmem
Or with all dependencies:
pip install graphmem[all]
Basic Usage
from graphmem import GraphMem
# Initialize with sensible defaults
memory = GraphMem()
# Ingest information
memory.ingest("""
TechCorp announced today that John Smith has been appointed as their new CEO.
Smith brings 20 years of experience from leading AI companies including DeepMind
and OpenAI. The company's stock rose 15% on the news.
""")
# Query the memory
response = memory.query("Who is the new CEO of TechCorp?")
print(response.answer)
# Output: "John Smith has been appointed as the new CEO of TechCorp."
# Memory evolves automatically
memory.evolve()
Configuration
from graphmem import GraphMem, MemoryConfig
config = MemoryConfig(
# LLM settings
llm_provider="azure_openai",
llm_api_key="your-api-key",
llm_endpoint="https://your-endpoint.openai.azure.com",
llm_deployment="gpt-4o",
# Embedding settings
embedding_provider="azure_openai",
embedding_deployment="text-embedding-3-small",
# Storage settings
neo4j_uri="bolt://localhost:7687",
neo4j_user="neo4j",
neo4j_password="password",
# Cache settings
redis_url="redis://localhost:6379",
# Evolution settings
auto_evolve=True,
evolution_interval=3600, # seconds
consolidation_threshold=0.85,
decay_rate=0.01,
)
memory = GraphMem(config)
๐๏ธ Architecture
GraphMem
โโโ Core
โ โโโ GraphMem # Main interface
โ โโโ Memory # Memory unit (nodes, edges, clusters)
โ โโโ MemoryNode # Entity representation
โ โโโ MemoryEdge # Relationship representation
โ โโโ MemoryCluster # Community/topic grouping
โ
โโโ Graph
โ โโโ KnowledgeGraph # Knowledge extraction & storage
โ โโโ EntityResolver # Entity deduplication
โ โโโ CommunityDetector # Topic clustering
โ
โโโ Evolution
โ โโโ MemoryEvolution # Evolution orchestrator
โ โโโ MemoryDecay # Importance decay
โ โโโ Consolidation # Memory merging
โ โโโ Rehydration # Memory restoration
โ
โโโ Retrieval
โ โโโ QueryEngine # Query processing
โ โโโ MemoryRetriever # Context retrieval
โ โโโ SemanticSearch # Embedding search
โ
โโโ Context
โ โโโ ContextEngine # Context window construction
โ โโโ DocumentChunker # Semantic chunking
โ โโโ MultiModalProcessor # Multi-modal handling
โ
โโโ LLM
โ โโโ LLMProvider # LLM abstraction
โ โโโ EmbeddingProvider # Embedding abstraction
โ
โโโ Stores
โโโ Neo4jStore # Graph persistence
โโโ RedisCache # Caching layer
๐ Advanced Usage
Custom Knowledge Extraction
from graphmem import GraphMem, KnowledgeGraph
# Create with custom extraction prompt
memory = GraphMem(
extraction_prompt="""
Extract entities and relationships from the text.
Focus on: People, Organizations, Products, Events
Text: {text}
"""
)
Multi-Modal Ingestion
from graphmem import GraphMem
memory = GraphMem()
# Ingest PDF
memory.ingest_file("report.pdf", modality="pdf")
# Ingest image
memory.ingest_file("diagram.png", modality="image")
# Ingest audio (transcribes automatically)
memory.ingest_file("meeting.mp3", modality="audio")
# Ingest web page
memory.ingest_url("https://example.com/article")
# Ingest code
memory.ingest_file("main.py", modality="code")
Manual Evolution Control
from graphmem import GraphMem, MemoryConfig
config = MemoryConfig(auto_evolve=False)
memory = GraphMem(config)
# Add content
memory.ingest("...")
# Manually trigger evolution
memory.consolidate() # Merge similar memories
memory.decay() # Apply importance decay
memory.prune() # Remove low-importance memories
Query with Filters
response = memory.query(
"What happened at TechCorp?",
filters={
"entity_type": "Organization",
"min_importance": 5,
},
top_k=20,
include_context=True,
)
print(response.answer)
print(response.confidence)
print(response.context)
Direct Graph Access
from graphmem import GraphMem
memory = GraphMem()
# Get entities
entities = memory.get_entities(entity_type="Person")
# Get relationships
relationships = memory.get_relationships(
source="John Smith",
relation_type="CEO_OF"
)
# Get communities
communities = memory.get_communities()
๐ง Configuration Options
| Option | Description | Default |
|---|---|---|
llm_provider |
LLM provider (azure_openai, openai, anthropic, ollama) | azure_openai |
embedding_provider |
Embedding provider | azure_openai |
neo4j_uri |
Neo4j connection URI | bolt://localhost:7687 |
redis_url |
Redis connection URL | redis://localhost:6379 |
auto_evolve |
Enable automatic memory evolution | True |
evolution_interval |
Seconds between evolution cycles | 3600 |
consolidation_threshold |
Similarity threshold for merging | 0.85 |
decay_rate |
Daily decay rate for importance | 0.01 |
chunk_size |
Document chunk size in characters | 1000 |
chunk_overlap |
Chunk overlap in characters | 200 |
top_k |
Default number of retrieval results | 10 |
min_similarity |
Minimum similarity for retrieval | 0.5 |
๐งช Testing
# Run tests
pytest tests/
# Run with coverage
pytest tests/ --cov=graphmem
# Run specific test
pytest tests/test_memory.py::test_ingestion
๐ฆ Dependencies
Required
- Python 3.9+
- numpy
- pydantic
Optional (by feature)
- LLM: openai, anthropic
- Storage: neo4j, redis
- PDF: PyMuPDF or PyPDF2
- OCR: pytesseract, Pillow
- Audio: openai-whisper
- Web: beautifulsoup4, requests
- Local Embeddings: sentence-transformers
๐ค Contributing
Contributions are welcome! Please read our Contributing Guide for details.
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
Built with inspiration from:
- GraphRAG by Microsoft
- LlamaIndex
- Human cognitive science research on memory consolidation
Made with โค๏ธ by Ameer AI
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 agentic_graph_mem-1.0.0.tar.gz.
File metadata
- Download URL: agentic_graph_mem-1.0.0.tar.gz
- Upload date:
- Size: 57.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a892c467b5fd70455149a728d265c0d2f047f900278c7b151627a2d313eced9e
|
|
| MD5 |
602412612882296145b4628727e7dab3
|
|
| BLAKE2b-256 |
5e92eeba8f9a13ceeb1de0a4053271e725935b2ca4f3654d3abcf46eb9abc84d
|
File details
Details for the file agentic_graph_mem-1.0.0-py3-none-any.whl.
File metadata
- Download URL: agentic_graph_mem-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06f9ce77591f0724b1889ebd47dd7b5ec8cd2cea920115959a52633b9c34b5a2
|
|
| MD5 |
38a122f7bec5bdf777c36da3ea6b558e
|
|
| BLAKE2b-256 |
bf700427ab52a3118516bfdbc160c736dfaa7e98b0b6106914b72106328539c0
|