graphrag-cli 0.1.0

Modern Terminal User Interface (TUI) for GraphRAG operations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
# 🚀 GraphRAG-CLI Complete User Guide

**GraphRAG-CLI** is a modern Terminal User Interface (TUI) for GraphRAG operations, built with Ratatui for interactive knowledge graph exploration.

## 📋 Table of Contents

- [Installation & Build]#installation--build
- [Quick Start]#quick-start
- [Usage Modes]#usage-modes
- [Slash Commands]#slash-commands
- [Workspace Management]#workspace-management
- [Keyboard Shortcuts]#keyboard-shortcuts
- [Practical Examples]#practical-examples
- [Troubleshooting]#troubleshooting

---

## 🔧 Installation & Build

### Prerequisites
- Rust 1.70 or higher
- Ollama installed and running (for LLM models)

### Building

```bash
# From the project root directory
cargo build --release -p graphrag-cli

# The binary will be available at:
# ./target/release/graphrag-cli
```

### Add to PATH (optional)

```bash
# Linux/macOS
export PATH="$PATH:$(pwd)/target/release"

# Or create a symbolic link
sudo ln -s $(pwd)/target/release/graphrag-cli /usr/local/bin/graphrag-cli
```

---

## ⚡ Quick Start

### 1. Launch the Interactive TUI

```bash
# Basic launch
./target/release/graphrag-cli

# With configuration file
./target/release/graphrag-cli --config docs-example/symposium_config.toml

# With specific workspace
./target/release/graphrag-cli --workspace my_project

# With debug logging
./target/release/graphrag-cli --debug
```

### 2. First Time Setup

1. **Start the TUI:**
   ```bash
   ./target/release/graphrag-cli
   ```

2. **Load a configuration:**
   In the TUI, press `Shift+Tab` to enter command mode, then type:
   ```
   /config docs-example/symposium_config.toml
   ```

3. **Load a document:**
   ```
   /load docs-example/platos_symposium.txt
   ```

4. **Execute queries:**
   Return to Query Mode (press `Shift+Tab`) and type:
   ```
   What does Socrates say about love?
   ```

---

## 🎯 Usage Modes

GraphRAG-CLI has **two primary modes**:

### 📝 Query Mode
- **Purpose:** Execute queries on the knowledge graph
- **How to use:** Type your question directly
- **Example:** `What are the main themes in the Symposium?`
- **Border color:** Green

### ⚙️ Command Mode
- **Purpose:** Execute system commands (slash commands)
- **How to use:** Press `Shift+Tab` to switch from Query Mode
- **Example:** `/config myfile.toml`
- **Border color:** Yellow

**Switch between modes:** `Shift+Tab`

---

## 🔀 Slash Commands

Slash commands are only available in **Command Mode**.

### `/config <file>`
Load a GraphRAG configuration file (TOML or JSON5)

```bash
# Example with TOML
/config docs-example/symposium_config.toml

# Example with absolute path
/config /home/user/graphrag-rs/my_config.toml

# Example with relative path
/config ../config/templates/academic_research.toml
```

**What it does:**
- Loads LLM configuration (Ollama, OpenAI, etc.)
- Configures embeddings and chunking strategy
- Initializes the knowledge graph

---

### `/load <file>`
Load and process a document into the knowledge graph

```bash
# Load a text file
/load docs-example/platos_symposium.txt

# Load a markdown file
/load ~/documents/research_paper.md

# Load multiple documents (execute multiple times)
/load document1.txt
/load document2.txt
/load document3.txt
```

**What it does:**
1. Reads the document
2. Splits into chunks (based on config)
3. Extracts entities and relationships using **REAL LLM calls** (not pattern matching!)
4. Builds the knowledge graph
5. Generates embeddings

**Processing time (with TRUE LLM gleaning extraction):**
- **Small docs** (5-10 pages): 5-15 minutes
- **Medium docs** (50-100 pages): 30-60 minutes
- **Large docs** (500-1000 pages): 2-4 hours

This is REAL semantic extraction with multi-round LLM refinement, not instant pattern matching!

---

### `/stats`
Show knowledge graph statistics

```bash
/stats
```

**Output:**
```
Knowledge Graph Statistics:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📚 Documents:      3
📄 Chunks:         127
👤 Entities:       45
🔗 Relationships:  89
📊 Graph Density:  0.087
```

---

### `/entities [filter]`
List entities in the knowledge graph with optional filter

```bash
# List all entities
/entities

# Filter by name
/entities socrates

# Filter by type
/entities PERSON

# Filter by concept
/entities love
```

**Output:**
```
Entities (filtered: "socrates"):
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

👤 Socrates [PERSON]
   Mentions: 34
   Confidence: 0.95
   Description: Greek philosopher, student of Plato...

💡 Socratic Method [CONCEPT]
   Mentions: 12
   Confidence: 0.89
   Description: Method of inquiry through questioning...
```

---

### `/workspace <name>`
Switch to a different workspace

```bash
# Switch workspace
/workspace my_project

# Switch to different workspace
/workspace philosophy_research
```

**What are workspaces?**
- Separate directories for different projects
- Each workspace has its own knowledge graph
- Each workspace has its own query history
- Allows working on multiple projects simultaneously

---

### `/help`
Show list of all available commands

```bash
/help
```

---

## 🗂️ Workspace Management

Workspaces allow you to organize multiple projects separately.

### Terminal Commands

```bash
# List all workspaces
./target/release/graphrag-cli workspace list

# Create new workspace
./target/release/graphrag-cli workspace create philosophy_research

# Show workspace information
./target/release/graphrag-cli workspace info <workspace-id>

# Delete workspace
./target/release/graphrag-cli workspace delete <workspace-id>
```

### Example: Create and Use a Workspace

```bash
# 1. Create workspace
./target/release/graphrag-cli workspace create philosophy_research

# Output:
# ✅ Workspace created successfully!
#    Name: philosophy_research
#    ID:   a1b2c3d4-e5f6-7890-abcd-ef1234567890
#
# Use it with: graphrag-cli tui --workspace a1b2c3d4-e5f6-7890-abcd-ef1234567890

# 2. Start TUI with the workspace
./target/release/graphrag-cli --workspace a1b2c3d4-e5f6-7890-abcd-ef1234567890

# 3. In the TUI, load configuration and documents
# (command mode)
/config docs-example/symposium_config.toml
/load docs-example/platos_symposium.txt
```

### Workspace Paths

Workspaces are saved in:
```
~/.local/share/graphrag-cli/workspaces/
└── <workspace-id>/
    ├── metadata.json          # Workspace information
    ├── query_history.json     # Query history
    ├── graph.db              # Knowledge graph (if persistent)
    └── embeddings/           # Vector embeddings
```

---

## ⌨️ Keyboard Shortcuts

### General Navigation

| Key | Action |
|-----|--------|
| `Shift+Tab` | Switch mode (Query ↔ Command) |
| `Ctrl+C` | Exit application |
| `?` | Show help overlay (in Query Mode) |
| `Esc` | Close help overlay |

### Input Mode

| Key | Action |
|-----|--------|
| `Enter` | Execute query/command |
| `` / `` | Navigate query/command history |
| `Ctrl+U` | Clear input line |
| `Ctrl+W` | Delete previous word |

### Results Navigation

| Key | Action |
|-----|--------|
| `j` / `` | Scroll down |
| `k` / `` | Scroll up |
| `Ctrl+D` / `PgDn` | Page down |
| `Ctrl+U` / `PgUp` | Page up |
| `Home` | Beginning of results |
| `End` | End of results |

### Help Mode (pressing `?`)

| Key | Action |
|-----|--------|
| `Esc` | Close help |
| `q` | Close help |
| `` / `` | Scroll help |

---

## 💡 Practical Examples

### Example 1: Philosophy Setup (Plato's Symposium)

```bash
# 1. Start TUI
./target/release/graphrag-cli

# 2. In Command Mode (Shift+Tab)
/config docs-example/symposium_config.toml
/load docs-example/platos_symposium.txt

# 3. Wait for processing (30-60 seconds)

# 4. In Query Mode (Shift+Tab to return)
What does Socrates say about love?
Who are the main speakers in the Symposium?
Explain the myth of the androgyne
```

### Example 2: Multi-Document Analysis

```bash
# 1. Start with configuration
./target/release/graphrag-cli --config config/templates/academic_research.toml

# 2. Load multiple documents (Command Mode)
/load papers/paper1.txt
/load papers/paper2.txt
/load papers/paper3.txt

# 3. Check statistics
/stats

# 4. Analytical queries (Query Mode)
Compare the methodologies used in the three papers
What are the common themes across all documents?
List all authors mentioned
```

### Example 3: Technical Research

```bash
# 1. Create dedicated workspace
./target/release/graphrag-cli workspace create rust_docs

# 2. Start with workspace
./target/release/graphrag-cli --workspace <workspace-id> \
  --config config/templates/technical_documentation.toml

# 3. Load documentation (WARNING: This will take time with real LLM processing!)
/load rust-docs/ownership.md    # ~10-15 minutes per document
/load rust-docs/concurrency.md
/load rust-docs/async.md

# 4. Technical queries
Explain Rust's ownership system
How does async/await work in Rust?
What are the main concurrency primitives?
```

### Example 4: Entity Exploration

```bash
# 1. After loading documents
/entities

# 2. Filter by type
/entities PERSON
/entities CONCEPT
/entities LOCATION

# 3. Search specific entities
/entities socrates
/entities love
/entities athens
```

---

## 🔍 Troubleshooting

### Problem: "Configuration not loaded"

**Symptoms:** Cannot load documents or execute queries

**Solution:**
```bash
# 1. Make sure to load configuration first
/config path/to/config.toml

# 2. Verify the file exists
ls -la path/to/config.toml

# 3. Check TOML syntax
cat path/to/config.toml
```

---

### Problem: "Failed to connect to Ollama"

**Symptoms:** Errors during document loading or queries

**Solution:**
```bash
# 1. Verify Ollama is running
ollama list

# 2. Start Ollama if necessary
ollama serve

# 3. Test connection
curl http://localhost:11434/api/tags

# 4. Verify configured model is available
ollama list | grep qwen3
```

---

### Problem: "Document processing is slow"

**Symptoms:** Document loading takes a very long time

**NOTE:** This is **EXPECTED BEHAVIOR** with real LLM-based gleaning extraction!
- Small docs (5-10 pages): 5-15 minutes
- Medium docs (50-100 pages): 30-60 minutes
- Large docs (500-1000 pages): 2-4 hours

**This is NOT a bug** - it's genuine semantic extraction with real LLM API calls.

**If you need faster processing (lower quality):**
```toml
# Speed optimizations in config.toml

[entities]
max_gleaning_rounds = 2      # Reduce from 4 to 2
use_llm_completion_check = false  # Skip LLM completion check

[text.chunking]
chunk_size = 1000            # Larger chunks = fewer LLM calls
chunk_overlap = 50           # Reduce overlap

[ollama]
chat_model = "llama3.1:3b"   # Use smaller/faster model
```

---

### Problem: "TUI is corrupted/garbled"

**Symptoms:** Strange characters, corrupted layout

**Solution:**
```bash
# 1. Reset terminal
reset

# 2. Check TERM variable
echo $TERM
# Should be: xterm-256color or similar

# 3. Set if necessary
export TERM=xterm-256color

# 4. Restart TUI
./target/release/graphrag-cli
```

---

### Problem: "Workspace not found"

**Symptoms:** Error loading workspace

**Solution:**
```bash
# 1. List available workspaces
./target/release/graphrag-cli workspace list

# 2. Create new workspace if necessary
./target/release/graphrag-cli workspace create my_project

# 3. Use correct ID
./target/release/graphrag-cli --workspace <correct-id>
```

---

### Problem: "Out of memory"

**Symptoms:** Crashes during large document processing

**Solution:**
```toml
# Reduce memory usage in config.toml

[text.chunking]
max_tokens = 300  # Reduce chunk size
overlap = 20      # Reduce overlap

[embeddings]
batch_size = 16   # Reduce batch for embeddings

[caching]
enabled = true    # Enable caching to save RAM
max_size_mb = 100 # Limit cache size
```

---

## 📊 Recommended Configurations

### For Small Documents (<100KB)

```toml
[text.chunking]
method = "semantic"
max_tokens = 500
overlap = 50

[entity.extraction]
use_gleaning = true
max_iterations = 3
```

### For Large Documents (>1MB)

```toml
[text.chunking]
method = "simple"
max_tokens = 300
overlap = 20

[entity.extraction]
use_gleaning = false
max_iterations = 1

[caching]
enabled = true
max_size_mb = 500
```

### For Maximum Performance

```toml
[text.chunking]
method = "simple"
max_tokens = 400

[entity.extraction]
use_gleaning = false

[async_processing]
enabled = true
max_concurrent_operations = 8

[caching]
enabled = true
cache_embeddings = true
```

---

## 📝 Configuration Examples

### Basic Template (TOML)

```toml
# my_config.toml

[llm]
provider = "ollama"
model = "qwen3:8b"
temperature = 0.7
max_tokens = 2000

[embeddings]
provider = "ollama"
model = "nomic-embed-text"
dimensions = 768

[text.chunking]
method = "semantic"
max_tokens = 500
overlap = 50

[entity.extraction]
use_gleaning = true
max_iterations = 2

[graph]
enable_pagerank = true
pagerank_damping = 0.85

[storage]
type = "memory"
```

### Advanced Template (JSON5)

```json5
// my_config.json5
{
  llm: {
    provider: "ollama",
    model: "qwen3:8b",
    temperature: 0.7,
    max_tokens: 2000,
  },

  embeddings: {
    provider: "ollama",
    model: "nomic-embed-text",
    dimensions: 768,
  },

  text: {
    chunking: {
      method: "hierarchical",
      max_tokens: 500,
      overlap: 50,
    },
  },

  entity: {
    extraction: {
      use_gleaning: true,
      max_iterations: 3,
      confidence_threshold: 0.7,
    },
  },

  graph: {
    enable_pagerank: true,
    enable_leiden: true,
  },

  caching: {
    enabled: true,
    max_size_mb: 200,
    cache_embeddings: true,
  },
}
```

---

## 🎓 Complete Tutorial: First Project

Follow this step-by-step tutorial for your first GraphRAG project:

### Step 1: Preparation

```bash
# 1. Create project directory
mkdir -p ~/graphrag-projects/philosophy
cd ~/graphrag-projects/philosophy

# 2. Create configuration file
cat > config.toml << 'EOF'
[llm]
provider = "ollama"
model = "qwen3:8b"
temperature = 0.7

[embeddings]
provider = "ollama"
model = "nomic-embed-text"

[text.chunking]
method = "semantic"
max_tokens = 500

[entity.extraction]
use_gleaning = true
max_iterations = 2
EOF

# 3. Prepare documents
mkdir documents
# Copy your documents to ./documents/
```

### Step 2: Launch and Configuration

```bash
# 1. Start GraphRAG-CLI
/path/to/graphrag-rs/target/release/graphrag-cli

# 2. In the TUI, switch to Command Mode
# Press: Shift+Tab

# 3. Load configuration
/config ~/graphrag-projects/philosophy/config.toml

# 4. Verify success (should see confirmation message)
```

### Step 3: Loading Documents

```bash
# In Command Mode, load documents one at a time
/load ~/graphrag-projects/philosophy/documents/doc1.txt

# Wait for completion (30-60 seconds)

/load ~/graphrag-projects/philosophy/documents/doc2.txt

# Repeat for all documents
```

### Step 4: Exploration

```bash
# 1. Check statistics
/stats

# 2. Explore entities
/entities

# 3. Filter entities by type
/entities PERSON
/entities CONCEPT
```

### Step 5: Querying

```bash
# Switch to Query Mode
# Press: Shift+Tab

# Execute analytical queries
What are the main philosophical concepts discussed?

# Queries about specific entities
Tell me about Socrates and his ideas

# Comparative queries
Compare Plato's and Aristotle's views on reality

# Thematic queries
What are the main themes in these documents?
```

---

## 🚀 Tips & Tricks

### 1. Use Query History

- Press `` / `` to navigate previous queries
- Edit and re-execute queries quickly
- History is persistent per workspace

### 2. Organize by Projects

```bash
# Create workspace for each project
graphrag-cli workspace create project_A
graphrag-cli workspace create project_B
graphrag-cli workspace create project_C

# Switch quickly between projects
graphrag-cli --workspace <project_A_id>
```

### 3. Optimize Performance

```toml
# Enable all performance features
[async_processing]
enabled = true
max_concurrent_operations = 8

[caching]
enabled = true
cache_embeddings = true

[parallel]
max_workers = 4
```

### 4. Debugging

```bash
# Start with debug logging
graphrag-cli --debug

# Logs are saved in:
# Linux: ~/.local/share/graphrag-cli/logs/graphrag-cli.log
# View logs in real-time:
tail -f ~/.local/share/graphrag-cli/logs/graphrag-cli.log
```

### 5. Batch Processing

```bash
# Use script to load many documents
for file in documents/*.txt; do
  echo "/load $file"
done > commands.txt

# Then execute manually in TUI
# (or integrate with future automation)
```

---

## 📚 Additional Resources

### Documentation

- [GraphRAG-Core README]../graphrag-core/README.md
- [Configuration Guide]../CONFIGURATION_GUIDE.md
- [Architecture Documentation]../ARCHITECTURE.md

### Configuration Templates

- `config/templates/academic_research.toml`
- `config/templates/technical_documentation.toml`
- `config/templates/narrative_fiction.toml`

### Examples

- `examples/multi_document_pipeline.rs`
- `examples/symposium_real_search.rs`
- `docs-example/symposium_config.toml`

---

## 🤝 Contributing

Found a bug or want to contribute? Open an issue or pull request at:
https://github.com/yourusername/graphrag-rs

---

## 📄 License

MIT License - See [LICENSE](../LICENSE) for details

---

## 🎯 Quick Reference Card

```
╔════════════════════════════════════════════════════════════╗
║              GraphRAG-CLI Quick Reference                  ║
╠════════════════════════════════════════════════════════════╣
║ STARTUP                                                    ║
║   graphrag-cli                      Start TUI              ║
║   graphrag-cli --config FILE        With configuration     ║
║   graphrag-cli --workspace ID       With workspace         ║
║                                                            ║
║ MODES                                                      ║
║   Shift+Tab    Switch Query ↔ Command Mode                ║
║   ?            Show help (Query Mode)                      ║
║   Ctrl+C       Exit                                        ║
║                                                            ║
║ COMMANDS (Command Mode)                                    ║
║   /config FILE      Load configuration                     ║
║   /load FILE        Load document                          ║
║   /stats            Show statistics                        ║
║   /entities [FILT]  List entities (with optional filter)   ║
║   /workspace NAME   Switch workspace                       ║
║   /help             Show all commands                      ║
║                                                            ║
║ WORKSPACE (from terminal)                                  ║
║   workspace list         List workspaces                   ║
║   workspace create NAME  Create workspace                  ║
║   workspace info ID      Workspace info                    ║
║   workspace delete ID    Delete workspace                  ║
║                                                            ║
║ NAVIGATION                                                 ║
║   ↑/↓         Navigate history / scroll results            ║
║   j/k         Vim-style scroll (down/up)                   ║
║   Ctrl+D/U    Page down/up                                 ║
║   Home/End    Beginning/end of results                     ║
║   Ctrl+U      Clear line (in input)                        ║
║   Ctrl+W      Delete word (in input)                       ║
╚════════════════════════════════════════════════════════════╝
```

---

**Happy GraphRAG-ing! 🚀✨**