This module provides tools for extracting AI/ML concepts from content, organizing them into a knowledge graph, and visualizing concept relationships.
The Knowledge Graph module is built on top of the concept extraction system and provides:
- Concept Extraction: Extract AI/ML concepts and their relationships from content using Claude
- Knowledge Graph Construction: Build a graph representation of concepts and relationships
- Graph Analysis: Analyze concept centrality, communities, and relationship patterns
- Visualization: Generate interactive and static visualizations of the concept knowledge graph
- Command-line Interface: Access all functionality through command-line arguments
The Knowledge Graph system requires the following Python packages:
networkx- For graph construction and analysismatplotlib- For static visualizationsplotly- For interactive HTML visualizationsanthropic- For concept extraction using Claude
All required packages are included in the main requirements.txt file.
To use the Knowledge Graph system, follow these steps:
-
Extract Concepts: First, you need to extract concepts from content in the database
python run.py --concepts --concepts-batch
-
Analyze the Knowledge Graph: View statistics about the extracted concepts and relationships
python run.py --kg-analyze
-
Generate Visualizations: Create visual representations of the concept graph
python run.py --kg-visualize
The following command-line arguments are available for Knowledge Graph operations:
--concepts: Run AI concept extraction--concepts-batch: Run extraction in batch mode (recommended)--concepts-batch-size N: Set batch size for extraction (default: 10)--concepts-limit N: Maximum number of items to process--concepts-source TYPE: Only extract from a specific source type (research_paper,github, orinstagram)--concepts-force: Force reprocessing of content that already has concepts
--kg-analyze: Show knowledge graph statistics--kg-concept ID: Analyze a specific concept by ID--kg-search "TERM": Search and visualize concepts matching a term--kg-visualize: Generate standard visualizations of the knowledge graph--kg-output-dir DIR: Set the output directory for visualizations (default:visualizations)
python run.py --concepts --concepts-batchpython run.py --concepts --concepts-source research_paper --concepts-batchpython run.py --kg-analyzepython run.py --kg-visualize --kg-output-dir my_visualizations# First, find a concept ID using search:
python run.py --kg-search "transformer"
# Then analyze that specific concept:
python run.py --kg-concept 123python run.py --kg-search "neural network" --kg-output-dir visualizationsWhen you run --kg-visualize, the system generates:
- Static graph image (
knowledge_graph.png) - A PNG visualization using matplotlib - Interactive HTML (
knowledge_graph.html) - An interactive visualization using Plotly - Community visualization (
knowledge_graph_communities.html) - Communities of related concepts - JSON export (
knowledge_graph.json) - Graph data in JSON format for custom visualization - GEXF export (
knowledge_graph.gexf) - Graph data for use in Gephi (advanced graph visualization tool)
For advanced usage, you can directly use the knowledge_graph.py module, which provides a richer set of commands:
# Query the knowledge graph
python knowledge_graph.py query --concepts
python knowledge_graph.py query --category "algorithm"
python knowledge_graph.py query --search "transformer"
python knowledge_graph.py query --related 42
# Generate visualizations
python knowledge_graph.py visualize --concept-id 42 --interactive
python knowledge_graph.py visualize --all --output-dir my_visualizations
# Analyze the graph
python knowledge_graph.py analyze --stats
python knowledge_graph.py analyze --concept-id 42
python knowledge_graph.py analyze --communities
python knowledge_graph.py analyze --centralityYou can also use the Knowledge Graph API directly in your Python code:
from knowledge_graph import ConceptQuery, KnowledgeGraph, GraphVisualizer, KnowledgeGraphManager
# Query concepts
query = ConceptQuery()
concepts = query.search_concepts("neural network")
related = query.get_related_concepts(concept_id=42)
# Build and analyze graph
kg = KnowledgeGraph()
graph = kg.build_graph(min_confidence=0.6)
central_concepts = kg.get_central_concepts(centrality_type="pagerank")
communities = kg.get_concept_communities()
# Generate visualizations
viz = GraphVisualizer(graph)
viz.visualize_interactive(output_file="my_graph.html")Future enhancements to the Knowledge Graph system may include:
- Web interface for knowledge graph exploration
- Natural language querying of the knowledge graph
- Integration with other concept sources
- Time-based analysis of concept evolution
- Enhanced visualization options with custom layouts
For issues or feature requests, please submit an issue to the project repository.