An interactive command-line interface for creating and querying knowledge graphs from PDF documents using nano-graphrag.
- 📄 PDF Processing: Extract text from PDFs and build knowledge graphs
- 🧠 Multiple Query Modes: Local, global, and naive RAG queries
- 💾 Session Management: Multiple isolated research sessions
- 🔄 Interactive Mode: Persistent CLI that stays running
- ⚡ Fast Setup: Uses nano-graphrag for lightweight GraphRAG implementation
uv pip install -r requirements.txt
Create a .env
file:
cp .env.example .env
Edit .env
and add your OpenAI API key:
OPENAI_API_KEY=your-api-key-here
uv run python main.py
-
Create a session:
research-router> session create my_research
-
Add PDF documents:
research-router (my_research)> insert document.pdf research-router (my_research)> insert papers/
-
Query the knowledge graph:
research-router (my_research)> query "What are the main findings?" research-router (my_research)> query --mode local "Tell me about methodology"
session create <name>
- Create a new research sessionsession list
- List all sessionssession switch <name>
- Switch to a different sessionsession delete <name>
- Delete a sessionstatus
- Show current session status
insert <pdf_path>
- Insert a single PDFinsert <directory>
- Insert all PDFs from directoryinsert *.pdf
- Insert PDFs matching pattern
query <question>
- Query using global mode (default)query --mode local <question>
- Local search within documentsquery --mode global <question>
- Global thematic analysisquery --mode naive <question>
- Simple RAG without graphiquery
- Start interactive query mode
config
- Show configuration statushelp
- Show available commandsexit
- Exit the CLI
- Global Mode: Best for high-level questions about themes, trends, and overall insights across all documents
- Local Mode: Best for specific questions about particular documents or sections
- Naive Mode: Traditional RAG without knowledge graph structure
Each session maintains its own:
- Working directory for knowledge graph files
- Isolated knowledge graph data
- Independent document collections
Sessions are stored in ./sessions/
and persist between CLI runs.
The CLI supports both OpenAI and Azure OpenAI:
OpenAI (recommended):
OPENAI_API_KEY=sk-...
Azure OpenAI:
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_KEY=your-azure-key
research-router-cli/
├── main.py # CLI entry point
├── research_router_cli/
│ ├── commands/
│ │ ├── session.py # Session management
│ │ ├── insert.py # PDF insertion
│ │ └── query.py # Knowledge graph querying
│ └── utils/
│ ├── config.py # Configuration management
│ └── pdf_processor.py # PDF text extraction
├── sessions/ # Session data (auto-created)
├── requirements.txt # Dependencies
└── .env.example # Environment template
No API key configured:
- Ensure
.env
file exists withOPENAI_API_KEY
- Check
config
command output
PDF extraction fails:
- Ensure PDF files are not corrupted or password-protected
- Try with a different PDF to test
Knowledge graph not found:
- Use
insert
command to add documents first - Check
status
command for session info
Session issues:
- Use
session list
to see all sessions - Use
session create
to create a new session
- nano-graphrag: Lightweight GraphRAG implementation
- typer: CLI framework
- rich: Enhanced terminal output
- pdfplumber: PDF text extraction
- python-dotenv: Environment variable management