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.3.tar.gz (57.9 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.3-py3-none-any.whl (73.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentic_graph_mem-1.0.3.tar.gz
  • Upload date:
  • Size: 57.9 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.3.tar.gz
Algorithm Hash digest
SHA256 3551c1cfba3196f09a7aaed4d57f72d2466bc4e0e0f60d79872ff840b366abdd
MD5 f24f554774e7c6ac8490eaf2f2ad0d76
BLAKE2b-256 54280a4b48b5644d773aa17a658b45be789b837de8277054380d200621fb4af7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agentic_graph_mem-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 47313d1d89863aac47a8d4b958ee3210bd162151d6ba0fee1134c86f50676ad7
MD5 7a655cf12dd686433331f422a59a8708
BLAKE2b-256 5ebe583d144c08fd4d97de1e56175835a270e54d2226318616dbf70caad38fb1

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