Skip to main content

Production-Grade Agent Memory Framework for Agentic AI

Project description

๐Ÿง  GraphMem

Production-Grade Agent Memory Framework for Agentic AI

Python 3.9+ License: MIT Code Style: Black

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 agentic-graph-mem

Or with all dependencies:

pip install agentic-graph-mem[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


Download files

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

Source Distribution

agentic_graph_mem-1.0.1.tar.gz (57.6 kB view details)

Uploaded Source

Built Distribution

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

agentic_graph_mem-1.0.1-py3-none-any.whl (73.4 kB view details)

Uploaded Python 3

File details

Details for the file agentic_graph_mem-1.0.1.tar.gz.

File metadata

  • Download URL: agentic_graph_mem-1.0.1.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

Hashes for agentic_graph_mem-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b0d40ec7885216ccff20cbcad9de1750026cd0861fb1d37b105c0e9756117464
MD5 691fc76faa471855e79fa2c627e5d88c
BLAKE2b-256 59c90a5e54600906ddc43bf3c6caca500f92af74e2be8963f260b3087336a7bb

See more details on using hashes here.

File details

Details for the file agentic_graph_mem-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for agentic_graph_mem-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4badbf4efccfae21ecf7a0f4c22bcc841f1a593b89d7bb2768e5c39406ca4d5
MD5 33f1b3c3bcf9a8fd29d9a762a80c8ec0
BLAKE2b-256 13327abba2cedb9a02614f274712589fb7ec88f88e40afbd1352520f245cb8b7

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