A graph-based memory system for LLMs with intelligent retrieval using knowledge graphs, hybrid search, and semantic embeddings
Project description
MemoGraph ๐ง
A graph-based memory system for LLMs with intelligent retrieval. MemoGraph provides a powerful solution to the LLM memory problem by combining knowledge graphs, hybrid retrieval, and semantic search.
โจ Features
- Graph-Based Memory: Navigate knowledge using bidirectional wikilinks and backlinks
- Hybrid Retrieval: Combines keyword matching, graph traversal, and optional vector embeddings
- Markdown-Native: Human-readable markdown files with YAML frontmatter
- Memory Types: Support for episodic, semantic, procedural, and fact-based memories
- Smart Indexing: Efficient caching system that only re-indexes changed files
- CLI & Python API: Use via command line or integrate into your Python applications
- Multiple LLM Providers: Works with Ollama, Claude, and OpenAI
- Context Compression: Intelligent token budgeting for optimal context windows
- Salience Scoring: Memory importance ranking for better retrieval
๐ Quick Start
Installation
pip install memograph
Install with optional dependencies:
# For OpenAI support
pip install memograph[openai]
# For Anthropic Claude support
pip install memograph[anthropic]
# For Ollama support
pip install memograph[ollama]
# For embedding support
pip install memograph[embeddings]
# Install everything
pip install memograph[all]
Python Usage
from memograph import MemoryKernel, MemoryType
# Initialize the kernel attached to your vault path
kernel = MemoryKernel("~/my-vault")
# Ingest all notes in the vault
stats = kernel.ingest()
print(f"Indexed {stats['indexed']} memories.")
# Programmatically add a new memory
kernel.remember(
title="Meeting Note",
content="Decided to use BFS graph traversal for retrieval.",
memory_type=MemoryType.EPISODIC,
tags=["design", "retrieval"]
)
# Retrieve context for an LLM query
context = kernel.context_window(
query="how does retrieval work?",
tags=["retrieval"],
depth=2,
top_k=8
)
print(context)
๐ฏ CLI Usage
MemoGraph comes with a powerful CLI for managing your vault and chatting with it.
Ingest
Index your markdown files into the graph database:
memograph --vault ~/my-vault ingest
Force re-indexing all files:
memograph --vault ~/my-vault ingest --force
Remember
Quickly add a memory from the command line:
memograph --vault ~/my-vault remember \
--title "Team Sync" \
--content "Discussed Q3 goals." \
--tags planning q3
Context Window
Generate context for a query:
memograph --vault ~/my-vault context \
--query "What did we decide about the database?" \
--tags architecture \
--depth 2 \
--top-k 5
Ask (Interactive Chat)
Start an interactive chat session with your vault context:
memograph --vault ~/my-vault ask --chat --provider ollama --model llama3
Or ask a single question:
memograph --vault ~/my-vault ask \
--query "Summarize our design decisions" \
--provider claude \
--model claude-3-5-sonnet-20240620
Diagnostics
Check your environment and connection to LLM providers:
memograph --vault ~/my-vault doctor
๐ Core Concepts
Memory Types
MemoGraph supports different types of memories inspired by cognitive science:
- Episodic: Personal experiences and events (e.g., meeting notes)
- Semantic: Facts and general knowledge (e.g., documentation)
- Procedural: How-to knowledge and processes (e.g., tutorials)
- Fact: Discrete factual information (e.g., configuration values)
Graph Traversal
The library uses BFS (Breadth-First Search) to traverse your knowledge graph:
# Retrieve nodes with depth=2 (2 hops from seed nodes)
nodes = kernel.retrieve_nodes(
query="graph algorithms",
depth=2, # Traverse up to 2 levels deep
top_k=10 # Return top 10 relevant memories
)
Salience Scoring
Each memory has a salience score (0.0-1.0) that represents its importance:
---
title: "Critical Architecture Decision"
salience: 0.9
memory_type: semantic
---
We decided to use PostgreSQL for better ACID guarantees...
๐๏ธ Project Structure
MemoGraph/
โโโ memograph/ # Main package
โ โโโ core/ # Core functionality
โ โ โโโ kernel.py # Memory kernel
โ โ โโโ graph.py # Graph implementation
โ โ โโโ retriever.py # Hybrid retrieval
โ โ โโโ indexer.py # File indexing
โ โ โโโ parser.py # Markdown parsing
โ โโโ adapters/ # LLM and embedding adapters
โ โ โโโ embeddings/ # Embedding providers
โ โ โโโ frameworks/ # Framework integrations
โ โ โโโ llm/ # LLM providers
โ โโโ storage/ # Storage and caching
โ โโโ cli.py # CLI implementation
โโโ tests/ # Test suite
โโโ examples/ # Example usage
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
-
Clone the repository:
git clone https://github.com/Indhar01/MemoGraph.git cd MemoGraph
-
Install in development mode:
pip install -e ".[all,dev]"
-
Install pre-commit hooks:
pre-commit install -
Run tests:
pytest
๐ Documentation
- Contributing Guide - How to contribute to the project
- Code of Conduct - Community guidelines
- Security Policy - Security reporting and best practices
- Changelog - Version history and changes
๐ Security
See our Security Policy for reporting vulnerabilities.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
Inspired by the need for better memory management in LLM applications. Built with:
- Graph-based knowledge representation
- Hybrid retrieval strategies
- Cognitive science principles
๐ฌ Contact & Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ฆ Status
This project is in active development. While the core functionality is stable, the API may change in minor versions until we reach v1.0.0.
Made with โค๏ธ for better LLM memory management
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
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 memograph-0.0.2.tar.gz.
File metadata
- Download URL: memograph-0.0.2.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c5c1ed30866008e4f4bf2f4b2616f0f342d5c4fd20c277f92bc6b5ea833cb1c
|
|
| MD5 |
94c878c00618991faff3b27207bf3db6
|
|
| BLAKE2b-256 |
6a18752b5e7a409d76706bb4b4f1ff6bc0498dd15fba939060f9359c1a8bf871
|
Provenance
The following attestation bundles were made for memograph-0.0.2.tar.gz:
Publisher:
publish.yml on Indhar01/MemoGraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memograph-0.0.2.tar.gz -
Subject digest:
3c5c1ed30866008e4f4bf2f4b2616f0f342d5c4fd20c277f92bc6b5ea833cb1c - Sigstore transparency entry: 1022439674
- Sigstore integration time:
-
Permalink:
Indhar01/MemoGraph@e7fed99c850b779522e4b7c132447c95bf33ee27 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Indhar01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e7fed99c850b779522e4b7c132447c95bf33ee27 -
Trigger Event:
release
-
Statement type:
File details
Details for the file memograph-0.0.2-py3-none-any.whl.
File metadata
- Download URL: memograph-0.0.2-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
022391736778e95b37bbb48748f6c5fc17388b0807dd1a3447c056ccf904a2cd
|
|
| MD5 |
e1fe981f49222a15c57074196ad24e3a
|
|
| BLAKE2b-256 |
f65c62c738a52852a756eff3968a96f6bcae0552cf97398e8533f6df9579eed3
|
Provenance
The following attestation bundles were made for memograph-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on Indhar01/MemoGraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memograph-0.0.2-py3-none-any.whl -
Subject digest:
022391736778e95b37bbb48748f6c5fc17388b0807dd1a3447c056ccf904a2cd - Sigstore transparency entry: 1022439716
- Sigstore integration time:
-
Permalink:
Indhar01/MemoGraph@e7fed99c850b779522e4b7c132447c95bf33ee27 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Indhar01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e7fed99c850b779522e4b7c132447c95bf33ee27 -
Trigger Event:
release
-
Statement type: