A powerful Python library for generating hierarchical mind maps from any topic using Large Language Models (LLMs). Decompose complex themes into structured, hierarchical representations for analysis, visualization, and knowledge exploration.
LLM MindMap transforms any topic into a structured, hierarchical mind map by leveraging the reasoning capabilities of modern LLMs. Whether you're exploring "Artificial Intelligence," analyzing "Climate Change," or breaking down complex business concepts, this tool provides an intuitive way to visualize relationships between ideas and concepts.
- Topic Decomposition: Generate hierarchical mind maps from any theme using LLM reasoning
- Multiple Generation Modes:
- One-shot: Single-pass generation for quick results
- Refined: Iterative enhancement of existing mind maps
- Dynamic: Time-based evolution of mind maps across intervals
- Bootstrapped: Parallel generation of multiple refined variants
- Multiple LLM Providers: Support for OpenRouter and iFlow with easy switching
- Flexible Configuration: Configure via environment variables, JSON file, or direct parameters
- Rich Visualization: Export to Graphviz PDFs, Plotly interactive treemaps
- Data Export: Export to JSON, pandas DataFrames for further analysis
- Parallel Processing: Generate multiple refined mindmaps concurrently
- Robust Parsing: Automatic JSON repair and validation for reliable LLM output handling
- Python 3.12 or higher
- uv package manager (recommended)
# Clone the repository
git clone https://github.com/yourusername/llm_mindmap.git
cd llm_mindmap
# Install dependencies
uv syncFor Plotly visualization:
uv pip install plotlyFor Graphviz visualization, install the Graphviz binary:
macOS:
brew install graphvizLinux (Debian/Ubuntu):
sudo apt-get install graphvizWindows: Download and install from graphviz.org
Create .local/llms.json (already in .gitignore):
{
"default_provider": "iflow",
"default_model": "qwen3-max",
"providers": {
"openrouter": {
"api_key": "your-openrouter-api-key",
"base_url": "https://openrouter.ai/api/v1"
},
"iflow": {
"api_key": "your-iflow-api-key",
"base_url": "https://apis.iflow.cn"
}
}
}export OPENROUTER_API_KEY="your-openrouter-api-key"
export IFLOW_API_KEY="your-iflow-api-key"Pass configuration directly in code using dictionary or string format (see Usage examples below).
from llm_mindmap.mindmap import generate_theme_tree
# Use default configuration from .local/llms.json
mindmap = generate_theme_tree(
main_theme="Artificial Intelligence",
focus="machine learning applications"
)
# Display as text
mindmap.print()
# Visualize with Graphviz (creates PDF)
mindmap.visualize(engine="graphviz")
# Visualize with Plotly (interactive)
mindmap.visualize(engine="plotly")
# Export to JSON
mindmap.save_json("mindmap.json")
# Export to DataFrame
df = mindmap.to_dataframe()
print(df)# String format (provider::model)
config = "openrouter::gpt-4o-mini"
# Dictionary format with custom configuration
config = {
"provider": "openrouter",
"model": "gpt-4o-mini",
"connection_config": {
"api_key": "your-api-key",
"base_url": "https://your-provider.com/v1"
},
"temperature": 0.0,
"timeout": 60
}
mindmap = generate_theme_tree(
main_theme="Climate Change",
focus="renewable energy",
llm_model_config=config
)from llm_mindmap.mindmap import MindMapGenerator
generator = MindMapGenerator(
llm_model_config_base="openrouter::gpt-4o-mini"
)
mindmap, results = generator.generate_one_shot(
main_theme="Climate Change",
focus="renewable energy",
map_type="theme"
)Enhance an existing mind map with additional context:
generator = MindMapGenerator(
llm_model_config_base="openrouter::gpt-4o-mini",
llm_model_config_reasoning="openrouter::gpt-4o"
)
initial_mindmap = '''
{
"label": "Software Development",
"node": 1,
"summary": "Creating software applications",
"children": []
}
'''
refined_mindmap, results = generator.generate_refined(
main_theme="Software Development",
focus="full-stack development",
initial_mindmap=initial_mindmap,
output_dir="./refined_mindmaps"
)Generate multiple refined variants in parallel:
results = generator.bootstrap_refined(
main_theme="Climate Change",
focus="renewable energy",
initial_mindmap=initial_mindmap,
n_elements=10,
max_workers=4,
output_dir="./bootstrapped_mindmaps"
)Evolve mind maps across time intervals:
month_intervals = [
("2024-01-01", "2024-01-31"),
("2024-02-01", "2024-02-29"),
("2024-03-01", "2024-03-31")
]
month_names = ["January", "February", "March"]
mindmaps, results = generator.generate_dynamic(
main_theme="Climate Change",
focus="renewable energy",
month_intervals=month_intervals,
month_names=month_names,
output_dir="./dynamic_mindmaps"
)# Get all label-summary pairs
label_summaries = mindmap.get_label_summaries()
# Get terminal (leaf) nodes only
terminal_labels = mindmap.get_terminal_labels()
terminal_summaries = mindmap.get_terminal_summaries()
# Get parent-child relationships
parent_mapping = mindmap.get_label_to_parent_mapping()
# Convert to DataFrame (all nodes or leaves only)
df_all = mindmap.to_dataframe()
df_leaves = mindmap.to_dataframe(leaves_only=True)custom_instructions = """
You are an expert in technology trends.
Generate a focused mind map with the following constraints:
- Maximum 3 levels of depth
- Each sub-theme must be practical and actionable
- Include at least 2 sub-themes for each main branch
"""
mindmap, results = generator.generate_one_shot(
main_theme="Blockchain Technology",
focus="enterprise applications",
instructions=custom_instructions,
map_type="theme"
)Run the included examples to see the library in action:
# Basic usage example
uv run examples/mindmap_demo.py
# Advanced usage examples
uv run examples/advanced_demo.pySimple one-shot mind map generation.
Parameters:
main_theme(str): Primary theme to analyzefocus(str, optional): Specific aspect to guide sub-theme generationllm_model_config(str|dict|LLMConfig, optional): LLM configuration
Returns: MindMap object
Hierarchical tree structure representing a mind map.
Attributes:
label(str): Node namenode(int): Unique identifiersummary(str): Brief explanationchildren(list[MindMap]): Child nodeskeywords(list[str]): Keywords
Methods:
print(): Display as text treevisualize(engine): Render with Graphviz or Plotlysave_json(filepath): Save to JSON fileto_json(): Convert to JSON stringto_dataframe(leaves_only): Convert to pandas DataFrameget_label_summaries(): Extract all label-summary pairsget_terminal_labels(): Get leaf node labelsget_terminal_summaries(): Get leaf node summariesget_label_to_parent_mapping(): Get parent-child relationships
Advanced generator with multiple generation modes.
Methods:
generate_one_shot(): Single-pass generationgenerate_refined(): Iterative refinementbootstrap_refined(): Parallel generation of variantsgenerate_dynamic(): Time-based evolution
Access to multiple LLM providers through a single API.
Supported models:
gpt-4o-mini,gpt-4oclaude-3.5-sonnet,claude-3.5-haiku- And many more via OpenRouter
High-performance LLM API service.
Supported models:
qwen3-max,qwen3-plusdeepseek-v3glm-4.6,glm-4.5
See iFlow API for available models.
llm_mindmap/
├── llm/
│ ├── base.py # LLMConfig, LLMProvider (ABC), LLMEngine
│ ├── openrouter.py # OpenRouterProvider implementation
│ ├── iflow.py # IFlowProvider implementation
│ └── utils.py # Concurrent/parallel execution utilities
├── mindmap/
│ ├── mindmap.py # MindMap dataclass, generate_theme_tree()
│ ├── mindmap_generator.py # MindMapGenerator (advanced modes)
│ └── mindmap_utils.py # Prompts, save/load utilities
└── __init__.py
examples/
├── mindmap_demo.py # Basic usage
└── advanced_demo.py # Advanced features
tests/
├── llm_mindmap/
│ ├── llm/ # LLM component tests
│ └── mindmap/ # MindMap component tests
└── examples/ # Integration tests
# Clone and install
git clone https://github.com/yourusername/llm_mindmap.git
cd llm_mindmap
uv sync
# Activate virtual environment
source .venv/bin/activate # On Windows: .venv\Scripts\activate# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=llm_mindmap --cov-report=html
# Run specific test file
uv run pytest tests/llm_mindmap/mindmap/test_mindmap.py
# Run with verbose output
uv run pytest -vThe project uses standard Python conventions. When contributing:
- Follow PEP 8 style guidelines
- Add type hints for new functions
- Include docstrings for public APIs
- Write tests for new features
All generated outputs are saved to the _out/ directory:
mindmap.gv- Graphviz source filemindmap.gv.pdf- Rendered PDF visualizationmindmap_output.json- JSON export- DataFrames are displayed in console and can be saved to CSV
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
uv run pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
If you find a bug or have a feature request, please open an issue on GitHub with:
- A clear description of the problem
- Steps to reproduce the issue
- Expected vs. actual behavior
- Environment details (Python version, OS, etc.)
Built with:
- Pydantic for configuration validation
- Graphviz for visualization
- pandas for data manipulation
- tqdm for progress bars
- json-repair for robust JSON parsing