graphrag-search 0.2.12

GraphRAG โ€” Hybrid search engine: vector embeddings + knowledge graph over Markdown notes. 100% local, single Rust binary.
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
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
# graphrag

<div align="center">

**Hybrid search engine: vector embeddings + knowledge graph over Markdown notes.**

[![Crates.io](https://img.shields.io/crates/v/graphrag.svg)](https://crates.io/crates/graphrag)
[![Crates.io Downloads](https://img.shields.io/crates/d/graphrag)](https://crates.io/crates/graphrag)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Rust](https://img.shields.io/badge/rust-1.75%2B-orange)](https://www.rust-lang.org)
[![Built with](https://img.shields.io/badge/built%20with-Rust-1f425f.svg)](https://www.rust-lang.org)

**A single Rust binary โ€” no Python, no npm, no servers. 100% local and private.**

</div>

---

## ๐Ÿงญ GraphRAG for absolute beginners

*(If you already know what RAG, vectors, and knowledge graphs are, skip ahead to [What is Graph RAG?](#-what-is-graph-rag))*

### The problem: hundreds of notes, can't find anything

Imagine you've been taking notes about Linux for years. You have a `~/linux-notes/`
folder with **500 Markdown files** on topics like:

```
linux-notes/
โ”œโ”€โ”€ apt-comandos-basicos.md
โ”œโ”€โ”€ systemd-crear-servicio.md
โ”œโ”€โ”€ docker-compose-nginx.md
โ”œโ”€โ”€ particionar-disco-gpt.md
โ”œโ”€โ”€ script-bash-backup.md
โ”œโ”€โ”€ firewall-ufw-reglas.md
โ”œโ”€โ”€ kernel-compilar-modulo.md
โ”œโ”€โ”€ ssh-tunel-inverso.md
โ”œโ”€โ”€ lvm-redimensionar.md
โ”œโ”€โ”€ nginx-proxy-inverso.md
โ”œโ”€โ”€ rsync-incremental-backup.md
โ”œโ”€โ”€ ... (500 files)
```

When you need to find something, you do the usual:

```bash
grep -ri "partitions" ~/linux-notes/
```

And it works... until it doesn't. Because:

- You search **"partitions"** but the note is titled **"resizing LVM"** and never uses that word
- You search **"network monitoring"** but your note talks about **"ntopng"** and **"iftop"** without saying "monitoring"
- You search **"high availability"** and get one note, but you miss the **"keepalived"** and **"nginx load balancing"** notes that are closely related

**Your knowledge is there. The problem is you don't know it's there.**

---

### The solution: a search engine that understands *relationships*, not just words

GraphRAG scans your 500 Linux notes, automatically extracts key concepts
(apt, systemd, LVM, Nginx, Docker, firewalld...) and builds a **knowledge map**
that knows how they relate to each other.

Now, when you search:

```bash
graphrag search "hard disk partitions" linux.db
```

GraphRAG doesn't just find the note mentioning "partitions". It also shows you:
- The note about **LVM** (because LVM and partitions are neighboring concepts in the graph)
- The note about **GPT vs MBR** (connected through `partitioning`)
- The note about **mounting filesystems** (connected by `disk` โ†’ `storage`)

**This is Graph RAG**: a search engine that uncovers connections you didn't even know existed.

---

### Real-world example: how it works with your Linux notes

#### 1. Build the knowledge map

```bash
# One command scans all your notes and builds the graph
graphrag build ~/linux-notes linux.db
```

Under the hood, GraphRAG:
1. Reads each note and splits it into sections
2. Sends sections to a local AI (Ollama) that extracts entities like `systemd`,
   `docker`, `nginx`, `partitioning`, `firewall`
3. Detects which entities appear together in the same notes (co-occurrence)
4. Builds a graph where each entity is a node and each co-occurrence is a connection
5. Computes embeddings (vectors) for each note and entity

The result is a SQLite database that knows:
```
[Docker] โ”€โ”€co-occursโ”€โ”€ [Nginx] โ”€โ”€co-occursโ”€โ”€ [reverse-proxy]
                                              โ”€โ”€co-occursโ”€โ”€ [certbot-ssl]
                                              โ”€โ”€co-occursโ”€โ”€ [load-balancing]
```

#### 2. Search for something specific

```bash
graphrag search "secure web server" linux.db -k 5
```

Results:
```
 1. Nginx as reverse proxy                  Score: 0.92
    Connections: nginx, reverse-proxy, http

 2. Certbot: SSL certificates with Let's Encrypt  Score: 0.67
    Connections: ssl, certbot, nginx
    โ†‘ Appears because it shares "nginx" with the previous note

 3. Fail2ban: protecting SSH and services    Score: 0.45
    Connections: fail2ban, firewall, security
    โ†‘ Appears because "security" is connected to "nginx" in the graph
```

Note 3 never mentions "secure web server" โ€” but GraphRAG knows that
fail2ban is used to protect web servers, because both notes share
entities in the graph. **grep would never have shown you that note.**

#### 3. Explore connections

```bash
# What does Docker have to do with systemd?
graphrag path "Docker" "systemd" linux.db
# โ†’ Docker โ†’ containers โ†’ systemd โ†’ services

# What entities surround "firewall"?
graphrag graph "firewall" linux.db -d 1
# Neighbors: ufw, iptables, nftables, fail2ban, security, ports

# General statistics
graphrag stats linux.db
# โ†’ 500 notes, 1200 entities, 3400 connections
```

---

### And all this without internet?

Yes. GraphRAG is a **single Rust binary** that:
- Doesn't need Python, Node.js, or Docker
- Runs entirely on your machine, 100% local
- Never sends your data to any server
- If you don't have Ollama, uses synthetic embeddings (no external AI needed)
- The SQLite database is smaller than an MP3 and fully portable

**In summary:** If you have hundreds of Markdown notes and you're tired of searching
with grep or missing notes you know exist but can't find,
GraphRAG is the search engine that turns your file chaos into an
explorable knowledge map.

---

## ๐Ÿ“– What is Graph RAG?

**Graph RAG** (Retrieval-Augmented Generation with Graphs) is a retrieval technique that improves on plain vector search by incorporating **graph structure** into relevance ranking.

Instead of just finding notes that *mention* your query, it discovers notes connected through **shared concepts and entities** โ€” even if those notes never use the same words.

### Why it matters

| Search method | What it finds | What it misses |
|:---|---|:---|
| **FTS** (full-text) | Exact keyword matches | Synonyms, typos, related concepts |
| **Vector search** | Semantically similar content | Indirect relationships |
| **Graph RAG** | Semantic matches **+** graph-connected content | Nothing โ€” it's strictly better |

**Concrete example:** You have notes about "Docker Compose", "PostgreSQL", and "Patroni HA clusters". Vector search for "PostgreSQL replication" finds the PostgreSQL note. Graph RAG also surfaces the Patroni note โ€” not because it mentions PostgreSQL, but because both connect through the entity `high-availability` in the knowledge graph.

### The three-phase pipeline

```
Query "Python databases"
    โ”‚
    โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ PHASE 1 โ€” Vector Search                                  โ”‚
โ”‚ Cosine similarity: query vs every note/entity embedding  โ”‚
โ”‚ โ†’ Top-K candidates ranked by semantic proximity          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ PHASE 2 โ€” Reranking                                      โ”‚
โ”‚ Boost: title match (+0.1) โ€ข note type (+0.2)             โ”‚
โ”‚ Combine vector score + graph score via ฮฑ (default 0.7)   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ PHASE 3 โ€” Graph Expansion                                โ”‚
โ”‚ From top candidates, traverse the knowledge graph         โ”‚
โ”‚ via recursive CTE (SQLite). Neighbors get decaying score  โ”‚
โ”‚ โ†’ Discovers notes connected through shared entities      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Results: hybrid score โ€ข note content โ€ข neighbors         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

> **TL;DR:** Vector search tells you what's similar. Graph expansion tells you what's *connected*. Together they find what you didn't know to look for.

### When to use it

- ๐Ÿง  **Personal knowledge bases** โ€” connect ideas across hundreds of notes
- ๐Ÿ“˜ **Technical documentation** โ€” find related tools, libraries, and concepts
- ๐Ÿ”ฌ **Research workflows** โ€” discover papers and notes linked by shared entities
- ๐ŸŒฑ **Zettelkasten / digital gardens** โ€” surface implicit links between atomic notes
- ๐Ÿ‘ฅ **Team wikis** โ€” find documents connected through shared terminology

---

## โœจ Features

| | Feature | Why it matters |
|---|---|---|
| ๐Ÿ” | **Hybrid search** (vectors + graph) | Finds relevant notes *and* connected content you didn't explicitly search for |
| ๐Ÿงฉ | **Entity extraction** via Ollama LLM | Automatically builds the knowledge graph from your notes โ€” no manual tagging |
| ๐Ÿ˜๏ธ | **Community detection** (Leiden algorithm) | Groups related entities into clusters for higher-level understanding |
| ๐Ÿ“ | **Narrative answers** (`--answer`) | Get LLM-generated summaries grounded in community context, not just result lists |
| ๐Ÿ“„ | **FTS5 full-text search** | Classic keyword search when you know exactly what you're looking for |
| ๐Ÿ”— | **Path finding** | Shortest path between any two nodes โ€” discover surprising connections |
| ๐Ÿ“Š | **Graph statistics** | Understand your knowledge base structure at a glance |
| ๐Ÿ–ฅ๏ธ | **Concept map TUI** (`map`) | Interactive terminal UI to visually explore the knowledge graph โ€” navigate nodes, inspect details, filter by type |
| โšก | **Incremental builds** | Only processes new/modified files (SHA256). Second build is instant |
| ๐Ÿ”„ | **Parallel NER** | N worker threads for entity extraction, 1 serial writer โ€” no SQLite lock contention |
| ๐Ÿค– | **MCP server** | Claude Desktop, Cline, and other AI assistants can query your graph in real-time |
| ๐Ÿ“ | **Neovim plugin** | Search and insert related notes without leaving your editor |
| ๐Ÿšซ | **Zero external deps** | SQLite compiled statically. No Python, Node, Docker, or servers needed |
| ๐Ÿ”’ | **100% local & private** | Everything runs on your machine. No data ever leaves your computer |

---

## ๐Ÿš€ Quick start (under 2 minutes)

```bash
# 1. Install
cargo install graphrag-search

# 2. Populate demo data (44 nodes, ~113 edges)
graphrag seed demo.db

# 3. Search โ€” finds notes semantically related to "Python"
graphrag search "Python" demo.db -k 5

# 4. Path โ€” discovers how two technologies connect
graphrag path "Docker" "SQLite" demo.db
# โ†’ Docker โ†’ virtualization โ†’ embedded-database โ†’ SQLite

# 5. Graph โ€” see what's connected to a concept
graphrag graph "machine-learning" demo.db -d 2

# 6. Stats โ€” understand your graph
graphrag stats demo.db
```

### Sample output

```
$ graphrag search "Python" demo.db -k 3

Results for "Python" (ฮฑ=0.70, depth=2):
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
 1. Python: A versatile language
    Score: 0.982 | Type: note
    Python is widely used in data science, web development, and automation.
    Neighbors: pandas, flask, machine-learning, data-science

 2. pandas: Data analysis library
    Score: 0.623 | Type: note
    pandas provides high-performance, easy-to-use data structures.
    Neighbors: Python, numpy, data-science, jupyter

 3. Data Science overview
    Score: 0.412 | Type: note
    An introduction to data science concepts and tooling.
    Neighbors: Python, R, machine-learning, statistics
```

### Full demo walkthrough

```bash
# Create a database with demo data
graphrag seed graph.db

# Hybrid search with graph expansion (depth 2)
graphrag search "Docker security" graph.db -k 5

# Search with narrative answer (requires community detect + summarize)
graphrag community detect graph.db
graphrag community summarize graph.db
graphrag search "Docker security" graph.db --answer

# Exact text search
graphrag fts "Python" graph.db -l 10

# Explore the graph
graphrag graph "Docker" graph.db -d 1
graphrag path "Python" "Docker" graph.db
graphrag stats graph.db

# Interactive concept map
graphrag map graph.db

# Clean up when done
graphrag reset graph.db
```

---

## ๐Ÿ“ฆ Installation

### From crates.io (recommended)

```bash
cargo install graphrag-search
```

### From source

```bash
git clone https://github.com/atareao/graphrag
cd graphrag
cargo build --release

# Binary at:
#   target/release/graphrag (~6.5 MB)
```

**Requirements:** Rust โ‰ฅ 1.75 only. SQLite is compiled statically via `rusqlite` bundled feature โ€” no system libraries needed.

### Optional: Ollama setup

GraphRAG works **without Ollama** using synthetic (deterministic hash-based) embeddings.
For better results, install [Ollama](https://ollama.ai/) and pull the models you need:

```bash
# Minimal setup (fast, works on any hardware)
ollama pull llama3.2:3b    # NER โ€” 3.2B params, ~2GB VRAM
ollama pull nomic-embed-text  # Embeddings โ€” 137M params, ~0.5GB VRAM

# Recommended setup (best quality)
ollama pull gemma4:e2b      # NER โ€” 5.1B params, ~5GB VRAM
ollama pull bge-m3          # Embeddings โ€” 566M params, ~1GB VRAM
```

---

## โš™๏ธ Configuration

GraphRAG auto-creates a config file at `~/.config/graphrag/config.toml` on first run.
**All fields are optional** โ€” CLI flags always override config values.

```toml
# =============================================
# GraphRAG configuration
# =============================================

# --- Database ---
db = "graph.db"                    # Default DB path

# --- Ollama connection ---
ollama_url = "http://localhost:11434"
embed_model = "bge-m3:latest"      # Embedding model
ner_model = "gemma4:e2b"           # Entity extraction model

# --- Search defaults ---
k = 5                              # Results count
depth = 2                          # Graph expansion hops
alpha = 0.7                        # Vector weight (0=graph only, 1=vector only)

# --- Notes directory ---
notes_dir = "~/notes"              # Used by `graphrag build` when no dir is given

# --- Build ---
num_threads = 4                    # Parallel NER workers
```

### Practical config examples

<details>
<summary><b>๐Ÿ“‹ Minimal config (no Ollama, synthetic embeddings only)</b></summary>

```toml
db = "search.db"
notes_dir = "~/notes"
k = 10
depth = 2
# No Ollama fields โ€” uses deterministic synthetic embeddings automatically
```

</details>

<details>
<summary><b>๐Ÿ“‹ Knowledge base with 1000+ notes</b></summary>

```toml
db = "~/kb/search.db"
notes_dir = "~/kb/notes"
ner_model = "gemma4:e2b"
embed_model = "bge-m3:latest"
k = 10
depth = 2
alpha = 0.7
num_threads = 6
```

</details>

---

## ๐Ÿ› ๏ธ CLI commands

```
graphrag <COMMAND> [ARGS] [OPTIONS]
```

### Core commands

| Command | Description |
|---------|-------------|
| [`build`]#graphrag-build-repo-db | ๐Ÿ“ฅ Scan `.md` files โ†’ extract entities โ†’ build knowledge graph |
| [`search`]#graphrag-search-query-db | ๐Ÿ” Hybrid vector + graph search |
| [`ask`]#graphrag-ask-query-db | ๐Ÿ’ก RAG: answer questions with sources (retrieval + LLM) |
| [`fts`]#graphrag-fts-query-db | ๐Ÿ“„ Exact full-text search (FTS5) |
| [`graph`]#graphrag-graph-label-db | ๐Ÿ•ธ๏ธ Show neighbors of a node |
| [`map`]#graphrag-map-db | ๐Ÿ–ฅ๏ธ Interactive concept map TUI |
| [`path`]#graphrag-path-from-to-db | ๐Ÿ”— Shortest path between two nodes |
| [`seed`]#graphrag-seed-db | ๐ŸŒฑ Populate demo data |
| [`stats`]#graphrag-stats-db | ๐Ÿ“Š Graph statistics |
| [`reset`]#graphrag-reset-db | ๐Ÿ—‘๏ธ Delete DB and recreate empty |

### Advanced commands

| Command | Description |
|---------|-------------|
| [`community detect`]#graphrag-community-detect-db | ๐Ÿ˜๏ธ Leiden community detection |
| [`community summarize`]#graphrag-community-summarize-db | ๐Ÿ“ LLM summaries per community |
| [`mcp`]#graphrag-mcp | ๐Ÿค– MCP server for AI assistants |
| [`init db`]#graphrag-init-db-db | ๐Ÿ†• Create empty database |
| [`init neovim`]#graphrag-init-neovim---output-path | ๐Ÿ“ Generate Neovim plugin config |
| [`completions`]#graphrag-completions-bashzshfish | โŒจ๏ธ Shell completions (bash/zsh/fish) |

---

### `graphrag init db [DB]`

Create an empty SQLite database with the GraphRAG schema.

```bash
graphrag init db graph.db
```

### `graphrag init neovim [--output <path>]`

Generate Neovim plugin Lua config ready for [lazy.nvim](https://github.com/folke/lazy.nvim).

```bash
# Print to stdout
graphrag init neovim

# Save directly
graphrag init neovim --output ~/.config/nvim/lua/plugins/graphrag.lua
```

---

### `graphrag community detect [DB]`

Run **Leiden community detection** on the entity graph โ€” groups related entities into clusters.

```bash
graphrag community detect graph.db

# Coarser communities (lower resolution = fewer, larger groups)
graphrag community detect graph.db --resolution 0.8

# Finer communities (higher resolution = more, smaller groups)
graphrag community detect graph.db --resolution 1.5
```

| Flag | Default | Description |
|------|---------|-------------|
| `--resolution` | 1.0 | CPM quality function resolution parameter |

### `graphrag community summarize [DB]`

Generate LLM summaries for all detected communities. Requires `community detect` first.

```bash
graphrag community summarize graph.db --summary-model gemma4:e2b
```

| Flag | Default | Description |
|------|---------|-------------|
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--summary-model` | `llama3.2:3b` | LLM for generating summaries |
| `--embed-model` | `nomic-embed-text` | Embedding model |

After summarizing, use `graphrag search --answer` to get **narrative answers** grounded in community context.

---

### `graphrag completions <bash|zsh|fish>`

Generate shell completion scripts.

```bash
graphrag completions bash > ~/.local/share/bash-completion/completions/graphrag
graphrag completions zsh > _graphrag
graphrag completions fish > graphrag.fish
```

---

### `graphrag seed [DB]`

Populate a database with demo data (44 nodes: notes, entities, tags; ~113 edges).

```bash
graphrag seed graph.db
graphrag search "Docker security" graph.db -k 5
```

| Flag | Default | Description |
|------|---------|-------------|
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--embed-model` | `nomic-embed-text` | Embedding model |

---

### `graphrag build [REPO] [DB]`

The heart of GraphRAG โ€” scan `.md` files, extract entities via Ollama, and build the graph.

**Optimized for large repos:**
| Optimization | How it works |
|:---|---|
| โšก **Incremental** | Skips unchanged files via SHA256 hash. Second builds are near-instant |
| ๐Ÿงต **Parallel NER** | N worker threads extract entities in parallel |
| โœ๏ธ **Serial writer** | Single thread writes to SQLite โ€” no lock contention |
| ๐Ÿ“ฆ **Batch NER** | All chunks of a file sent in one Ollama call |
| ๐Ÿ” **Retry with backoff** | 3 attempts (2s, 4s, 8s) on connection errors |
| ๐Ÿงน **Auto-cleanup** | Deleted notes and orphaned entities pruned automatically |

```bash
# Build from configured notes directory
graphrag build

# Build from a specific directory
graphrag build ~/notes graph.db

# Build with specific model
graphrag build ~/notes graph.db --ner-model gemma4:e2b
```

| Flag | Default | Description |
|------|---------|-------------|
| `--embed-model` | `nomic-embed-text` | Embedding model |
| `--ner-model` | `llama3.2:3b` | Entity extraction model |
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |

---

### `graphrag reset [DB]`

Delete the database and recreate it empty (equivalent to `rm + init`).

```bash
graphrag reset
graphrag reset /data/notes/graph.db
```

---

### `graphrag search <QUERY> [DB]`

Hybrid search โ€” semantic vectors + graph expansion. This is what makes GraphRAG special.

```bash
graphrag search "Python and databases" graph.db -k 10 -d 2
```

| Flag | Default | Description |
|------|---------|-------------|
| `-k` | 5 | Number of results |
| `-d` | 2 | Graph expansion depth (hops from initial results) |
| `-a` | 0.7 | Vector weight (0.0 = pure graph, 1.0 = pure vector) |
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--embed-model` | `nomic-embed-text` | Embedding model |
| `--notes-only` | โ€” | Show only notes (hide entities and tags) |
| `--min-weight` | โ€” | Minimum edge weight for graph expansion |
| `--filter` | โ€” | Filter by metadata (repeatable). Format: `'field op value'` e.g. `--filter 'date >= 2023'` |
| `--answer` | โ€” | Narrative answer using community context (requires `community detect + summarize`) |
| `--format` | `table` | Output format: `table`, `list`, or `json` |

---

### `graphrag ask <QUERY> [DB]`

RAG in one command: hybrid retrieval + community summaries + chunk evidence โ†’ a grounded natural-language answer generated with Ollama, with cited sources.

```bash
graphrag ask "how do I configure nginx?" notes.db
graphrag ask "backups" notes.db -k 10 --filter 'date >= 2024'
graphrag ask "nginx" notes.db --format json
graphrag ask "nginx" notes.db --model gpt-oss:latest --communities 5
```

| Flag | Description |
|:---|---|
| `-k, --k` | Retrieval results used as evidence (default 5) |
| `-d, --depth` | Graph expansion depth (default 2; 0 = vector-only) |
| `-a, --alpha` | Vector weight, 0.0โ€“1.0 (default 0.7) |
| `--min-weight` | Minimum edge weight for expansion |
| `--notes-only` | Only notes (hide entities and tags) |
| `--filter` | Metadata filter (repeatable), e.g. `'date >= 2023'` |
| `--communities` | Max community summaries in the context (default 3) |
| `--model` | Ollama model for generation (default: `summary_model` from config) |
| `--format` | Output format: `table` \| `list` \| `json` |

If Ollama is unreachable, `ask` degrades to plain retrieval and exits 0. Community context requires `graphrag community detect` followed by `graphrag community summarize`. With `--format json` the output is `{ "answer", "sources", "results" }`.

---

### `graphrag similar --label <LABEL> --file <PATH> [DB]`

Find semantically similar notes. Two modes:
- `--label`: find notes similar to an **existing** indexed note (no Ollama needed โ€” uses stored embeddings)
- `--file`: find notes similar to an **external** `.md` file (chunks and embeds via Ollama)

Both modes use **match individual**: each chunk of the source is compared independently, and each target note is scored by its best-matching chunk pair.

```bash
# Find notes similar to an existing note
$ graphrag similar --label "Python frameworks" graph.db -k 5

# Find notes similar to an external file
$ graphrag similar --file ~/drafts/new-idea.md graph.db -k 10 -d 2
```

| Flag | Default | Description |
|------|---------|-------------|
| `--label` | โ€” | Label of an existing note in the database |
| `--file` | โ€” | Path to an external `.md` file |
| `-k` | 5 | Number of results |
| `-d` | 2 | Graph expansion depth |
| `--notes-only` | โ€” | Show only notes (no entities/tags) |
| `--min-weight` | โ€” | Minimum edge weight for expansion |
| `--filter` | โ€” | Filter by metadata field (`--filter "category = tutorial"`) |
| `--format` | `table` | Output format: `table`, `list`, or `json` |

Note: `--label` and `--file` are mutually exclusive. Use exactly one.

### `graphrag fts <QUERY> [DB]`

Exact full-text search via SQLite FTS5 โ€” classic keyword search.

```bash
graphrag fts "Python" graph.db -l 20
```

| Flag | Default | Description |
|------|---------|-------------|
| `-l` | 10 | Number of results |
| `--notes-only` | โ€” | Show only notes (no entities/tags) |
| `--format` | `table` | Output format: `table`, `list`, or `json` |

---

### `graphrag graph <LABEL> [DB]`

Show neighbors of a node in the knowledge graph. Great for exploring.

```bash
graphrag graph "Docker" graph.db -d 2
```

---

### `graphrag map [DB]`

Interactive concept map TUI โ€” visually explore the knowledge graph in the terminal.

```bash
# Full graph
graphrag map graph.db

# Subgraph centered on a node
graphrag map --from Python --depth 3 graph.db
```

| Flag | Default | Description |
|------|---------|-------------|
| `--from` | โ€” | Starting node label (omit for full graph) |
| `-d` | 2 | Graph expansion depth from starting node |

**Controls:**

| Key | Action |
|-----|--------|
| `โ†‘โ†“โ†โ†’` / `hjkl` | Navigate between nodes |
| `Enter` | Select node (details in right panel) |
| `t` | Cycle filter: all โ†’ notes โ†’ entities โ†’ tags |
| `/` | Search nodes by name |
| `q` / `Esc` | Quit |
| Mouse click | Select node |

---

### `graphrag path <FROM> <TO> [DB]`

Shortest path between two nodes โ€” discovers how concepts connect.

```bash
graphrag path "Python" "Docker" graph.db
# โ†’ Python โ†’ web-development โ†’ containerization โ†’ Docker
```

| Flag | Default | Description |
|------|---------|-------------|
| `-d` | 10 | Maximum traversal depth |

---

### `graphrag stats [DB]`

Graph statistics. Omits the DB path to use the configured default.

```bash
graphrag stats graph.db
graphrag stats            # uses config default
```

Output example:
```
Graph Statistics
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 Nodes:    156
  โ€ข notes:      89
  โ€ข entities:   52
  โ€ข tags:       15
 Edges:    342
 Density:  0.028
 Communities: 12
```

---

### `graphrag mcp`

Start an MCP server over stdio for AI assistant integration (see [MCP section](#-mcp-server)).

```bash
graphrag mcp --db graph.db
graphrag mcp --db graph.db --ollama-url http://localhost:11434
```

| Flag | Default | Description |
|------|---------|-------------|
| `--db` | `graphrag.db` | Path to SQLite database |
| `--ollama-url` | `http://localhost:11434` | Ollama server URL |
| `--embed-model` | `nomic-embed-text` | Embedding model |

---

## ๐ŸŽฏ Use cases & examples

### ๐Ÿ” Personal knowledge base

You have 300 notes about programming, DevOps, and system design. You search for
"async Rust" and get back notes about tokio and async/await โ€” *plus* a note
about the "actor model" that never mentions those words.

```bash
# Build the graph
graphrag build ~/zettelkasten kb.db

# Hybrid search โ€” finds connected content you didn't explicitly search for
graphrag search "async Rust" kb.db -k 10 -d 2

# Example result you wouldn't get with vector-only search:
# "Actor Model in Distributed Systems" โ€” Score: 0.34 (from graph expansion)
# Connected via: concurrency (shared entity with async Rust notes)
```

### ๐Ÿ“š Technical documentation

Search across multiple project docs and discover cross-project connections.

```bash
graphrag build ~/docs --ner-model gemma4:12b
graphrag search "PostgreSQL high availability" -k 10 -d 3
graphrag path "Kubernetes" "SQLite"
# โ†’ Kubernetes โ†’ container-orchestration โ†’ Docker โ†’ embedded-database โ†’ SQLite
```

### ๐Ÿงช Research paper collection

200 ML paper summaries. Find cross-disciplinary connections.

```bash
graphrag build ~/papers research.db

# Searching for "transformer attention" also surfaces a paper about
# "sparse mixture of experts" โ€” both connect through "self-attention"
graphrag search "transformer attention mechanisms" research.db -k 15 -d 2

# Explore concepts
graphrag graph "self-attention" research.db -d 1
```

### ๐Ÿ”— Hidden connections

Discover how seemingly unrelated topics connect through your graph.

```bash
# CSS to PostgreSQL? There's a path through web development
graphrag path "CSS" "PostgreSQL"
# โ†’ CSS โ†’ frontend โ†’ web-development โ†’ backend โ†’ PostgreSQL

# Explore an entity's neighborhood
graphrag graph "machine-learning" -d 2

# Get a narrative answer about a topic
graphrag community detect research.db
graphrag community summarize research.db --summary-model gemma4:e2b
graphrag search "attention mechanisms" research.db --answer
```

### ๐Ÿค– AI assistant integration (MCP)

Let Claude, Cline, or any MCP-compatible AI assistant query your knowledge base
in real-time during conversations.

```json
{
  "mcpServers": {
    "graphrag": {
      "command": "/usr/local/bin/graphrag",
      "args": ["mcp", "--db", "/home/user/kb.db"]
    }
  }
}
```

Claude can now use tools to explore your knowledge graph:
- `search` โ€” hybrid semantic + graph search ๐Ÿ”
- `graph` โ€” explore neighbors of a node ๐Ÿ•ธ๏ธ
- `path` โ€” find connections between concepts ๐Ÿ”—
- `stats` โ€” understand graph structure ๐Ÿ“Š

---

## ๐Ÿ“ Neovim plugin

Search and insert related notes without leaving your editor.

### Installation

```bash
graphrag init neovim --output ~/.config/nvim/lua/plugins/graphrag.lua
```

[lazy.nvim](https://github.com/folke/lazy.nvim) loads it automatically from `lua/plugins/`.

### Commands & keymaps

| Command | Keymap | Description |
|---------|--------|-------------|
| `:GraphRAG related` | `,gr` | Find notes related to current buffer (floating window) |
| `:GraphRAG insert` | `,gi` | Find related and insert `## Related` links at end of file |
| `:GraphRAG search <q>` | โ€” | Hybrid search from command line |
| `:GraphRAG fts <q>` | โ€” | Full-text search |
| `:GraphRAG path <A> <B>` | โ€” | Shortest path |
| `:GraphRAG stats` | โ€” | Graph statistics |

---

## ๐Ÿค– MCP server

Expose your knowledge graph to any MCP-compatible AI assistant (Claude Desktop, Cline, etc.).

### Claude Desktop configuration

```json
{
  "mcpServers": {
    "graphrag": {
      "command": "/usr/local/bin/graphrag",
      "args": ["mcp", "--db", "/Users/me/knowledge/kb.db"]
    }
  }
}
```

### Tools exposed

| Tool | Description |
|------|-------------|
| `build` | Build or update the graph from your notes directory |
| `search` | Hybrid search (vectors + graph) |
| `fts` | Full-text search |
| `graph` | Show neighbors of a node |
| `path` | Shortest path between two nodes |
| `stats` | Graph statistics |
| `seed` | Populate demo data |

### Resources exposed

| URI | Content |
|-----|---------|
| `graphrag://stats` | Graph statistics |
| `graphrag://nodes` | All nodes |
| `graphrag://notes` | Notes only |
| `graphrag://entities` | Entities only |
| `graphrag://edges` | All edges |
| `graphrag://nodes/<label>` | Single node details |

---

## ๐Ÿ—๏ธ Architecture

### Module map

```
๐Ÿ“ฆ graphrag  (single ~6.5 MB binary)
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs              โ† CLI entrypoint (clap, 12 subcommands)
โ”‚   โ”œโ”€โ”€ config.rs            โ† TOML config (auto-created, all fields optional)
โ”‚   โ”œโ”€โ”€ mcp/mod.rs           โ† MCP server (stdio, JSON-RPC 2.0)
โ”‚   โ”œโ”€โ”€ db/
โ”‚   โ”‚   โ””โ”€โ”€ schema.rs        โ† SQLite schema + FTS5 virtual table
โ”‚   โ”œโ”€โ”€ graph/
โ”‚   โ”‚   โ”œโ”€โ”€ build.rs         โ† Incremental build (parallel NER, serial writer)
โ”‚   โ”‚   โ””โ”€โ”€ expand.rs        โ† Recursive CTE expansion + shortest path
โ”‚   โ”œโ”€โ”€ search/
โ”‚   โ”‚   โ””โ”€โ”€ hybrid.rs        โ† 3-phase hybrid search engine
โ”‚   โ”œโ”€โ”€ embed/
โ”‚   โ”‚   โ””โ”€โ”€ ollama.rs        โ† Ollama HTTP client (blocking reqwest)
โ”‚   โ”œโ”€โ”€ vector/
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs           โ† f32 โ†” BLOB, cosine similarity
โ”‚   โ”‚   โ””โ”€โ”€ synthetic.rs     โ† Deterministic hash-based embeddings
โ”‚   โ”œโ”€โ”€ chunking/
โ”‚   โ”‚   โ””โ”€โ”€ markdown.rs      โ† Frontmatter parsing + section chunking
โ”‚   โ”œโ”€โ”€ ner/
โ”‚   โ”‚   โ””โ”€โ”€ ollama_ner.rs    โ† LLM entity extraction (batch mode)
โ”‚   โ”œโ”€โ”€ map/
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs           โ† Data loading (load_graph, cmd_map)
โ”‚   โ”‚   โ”œโ”€โ”€ layout.rs        โ† Force-directed layout algorithm
โ”‚   โ”‚   โ””โ”€โ”€ tui.rs           โ† Interactive TUI (ratatui)
โ”‚   โ””โ”€โ”€ seed/
โ”‚       โ””โ”€โ”€ demo_data.rs     โ† Demo data generator (44 nodes, 113 edges)
```

### How data flows

```
BUILD PIPELINE:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ .md filesโ”‚ โ†’ โ”‚ SHA256   โ”‚ โ†’ โ”‚ N worker threads:     โ”‚ โ†’ โ”‚ 1 writer โ”‚
โ”‚          โ”‚   โ”‚ pre-scan โ”‚   โ”‚ frontmatter โ†’ chunk   โ”‚   โ”‚ thread   โ”‚
โ”‚          โ”‚   โ”‚          โ”‚   โ”‚ โ†’ NER batch (Ollama)  โ”‚   โ”‚ โ†’ SQLite โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ†“                         โ†“
                              Entities + co-occurrence    Nodes + Edges
                                                                 โ†“
                              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ†“
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚ Prune    โ”‚ โ†’ Repopulate FTS5
                         โ”‚ deleted  โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

SEARCH PIPELINE:
Query โ†’ Embed โ†’ Cosine similarity โ†’ Rerank โ†’ Graph expansion โ†’ Results
  โ”‚        โ”‚           โ”‚               โ”‚            โ”‚              โ”‚
  โ”‚    Ollama or   Top-K scores    +title      Recursive     Hybrid score
  โ”‚    synthetic   by semantic     +type       CTE from      + content
  โ”‚                 similarity     +alpha      candidates    + neighbors
```

### Database schema

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      nodes       โ”‚       โ”‚        edges          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค       โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ id        INT PK โ”‚โ”€โ”€โ”    โ”‚ source_id INT FK      โ”‚
โ”‚ key       TEXT UQโ”‚  โ””โ”€โ”€โ”€โ”€โ”ค target_id INT FK      โ”‚
โ”‚ label     TEXT   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”ค type       TEXT        โ”‚
โ”‚ type      TEXT   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”ค type       TEXT        โ”‚
โ”‚ embedding BLOB  โ”‚  โ”‚    โ”‚ weight     REAL        โ”‚
โ”‚ metadata  JSON  โ”‚  โ”‚    โ”‚ context    TEXT        โ”‚
โ”‚ created_at INT  โ”‚  โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
                      โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      notes_fts       โ”‚    โ”‚      node_types       โ”‚
   (FTS5 virtual)     โ”‚    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
                      โ”‚    โ”‚ note                  โ”‚
                      โ”‚    โ”‚ entity                โ”‚
                      โ”‚    โ”‚ tag                   โ”‚
                      โ””โ”€โ”€โ”€โ”€โ”ค                       โ”‚
                           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

**Node identity:** every node has a unique `key`. Notes use `key = "note:" + <relative path>`; entities, tags and directories use `key = "node:" + <label>`. This means two notes with the same title โ€” and even a note whose title matches an entity โ€” are stored as separate nodes instead of overwriting each other, so incremental builds converge.

---

## โšก Performance

### Recommended Ollama models

| Purpose | Model | Params | VRAM | Quality |
|:---|---:|:---:|:---:|:---:|
| NER | `gemma4:e2b` | 5.1B | ~5GB | โญโญโญ Very good |
| NER | `gemma4:12b` | 11.9B | ~7GB | โญโญโญ Excellent |
| NER | `llama3.2:3b` | 3.2B | ~2GB | โญโญ Good (fast) |
| Embeddings | `bge-m3` | 566M | ~1GB | โญโญโญ Excellent |
| Embeddings | `nomic-embed-text` | 137M | ~0.5GB | โญโญ Good |

### Build throughput

| Scenario | Files | Time | Notes |
|:---|---:|---:|:---|
| First build | 100 | ~20 min | With `gemma4:e2b`, 4 threads |
| First build | 6254 | ~22 h | Large docs repo |
| Incremental | 1 changed | ~2 s | Only re-processes modified files |
| No Ollama | any | ~5 s | Synthetic embeddings, no NER |

> **Tip:** The first build is the slowest (NER is LLM-bound). Subsequent builds are
> near-instant because only new/modified files are processed.

### Memory

| Setup | RAM | Notes |
|:---|---:|:---|
| No Ollama (synthetic) | ~15 MB | Minimal |
| With `nomic-embed-text` | ~500 MB | + Ollama process |
| With `bge-m3` | ~1.5 GB | + Ollama process |
| With `gemma4:e2b` (NER) | ~5 GB | + Ollama process |

---

## ๐Ÿงช Tests

```bash
# All tests (123 tests, no external services needed)
cargo test

# Ollama-dependent tests (2 tests, requires Ollama running)
cargo test -- --ignored

# Lint
cargo clippy -- -D warnings

# Format check
cargo fmt --check
```

Tests use `tempfile` for temporary databases โ€” no cleanup needed.

---

## ๐Ÿ”ง Troubleshooting

### "Ollama is not running"

```
Error: connection refused
```

GraphRAG works without Ollama using synthetic embeddings. If you want Ollama
for better results:

```bash
# Start Ollama
ollama serve

# Verify it's running
curl http://localhost:11434/api/tags
```

### "Model not found"

```
WARN: model "gemma4:e2b" not found, skipping...
```

Pull the model:

```bash
ollama pull gemma4:e2b
```

### Build is slow

The first build runs NER (entity extraction) via LLM on every file. This is
expected โ€” LLMs are slow. After the first build, only changed files are processed.

Tips:
- Increase `num_threads` in config (watch your VRAM)
- Use a smaller NER model: `llama3.2:3b` is 2ร— faster than `gemma4:e2b`
- Use `--ollama-url` to point to a remote Ollama server on a GPU machine

### "No entities found for any chunks"

Some models don't support Ollama's `format: json` mode. Try:

```bash
# Switch to a model that handles JSON output well
graphrag build --ner-model llama3.2:3b

# Or use gemma4 which has excellent JSON support
graphrag build --ner-model gemma4:e2b
```

### "graphrag.db" uses config but I wanted a literal file

If you pass `graphrag.db` (the default), GraphRAG substitutes the path from
your config file. To force a literal `graphrag.db` file, use the config path:

```toml
# In config.toml
db = "graphrag.db"
```

---

## โ“ FAQ

<details>
<summary><b>Does GraphRAG need Ollama?</b></summary>
No. Without Ollama, GraphRAG uses deterministic synthetic embeddings (hash-based).
Search still works โ€” just without the semantic quality that LLM embeddings provide.
</details>

<details>
<summary><b>Can I use it with non-Markdown files?</b></summary>
Currently only `.md` files are supported. The build pipeline parses Markdown
frontmatter and section headers for chunking.
</details>

<details>
<summary><b>How is this different from Microsoft's GraphRAG?</b></summary>
Microsoft GraphRAG is a Python project that uses global community summarization
for question-answering over large datasets. This project is a lightweight Rust
binary focused on personal knowledge bases โ€” instant search, no server, single
binary, works entirely offline.
</details>

<details>
<summary><b>Can I share the database between machines?</b></summary>
Yes โ€” the SQLite database is portable. Copy it between machines and it works.
Synthetic embeddings are deterministic (same text = same vector), so builds
are reproducible across machines.
</details>

<details>
<summary><b>How do I update the graph when I add new notes?</b></summary>
Just run `graphrag build` again. It only processes new and modified files
(checked via SHA256 hash). Deleted files are auto-pruned.
</details>

<details>
<summary><b>Does it work with multiple users?</b></summary>
The SQLite database supports concurrent readers. For write access (build),
only one process at a time.
</details>

---

## ๐Ÿค Contributing

Contributions are welcome! Here's how to get started:

```bash
# Clone and build
git clone https://github.com/atareao/graphrag
cd graphrag
cargo build

# Run tests
cargo test

# Check lint
cargo clippy -- -D warnings

# Format
cargo fmt --check
```

### Development tips

- Use `RUST_LOG=debug graphrag build` to see detailed build logs
- The demo data seed is at `src/seed/demo_data.rs` โ€” great starting point
- All CLI commands are in `src/main.rs` โ€” easy to add new ones
- SQLite schema is in `src/db/schema.rs`

---

## ๐Ÿ“š Further reading

- [Microsoft GraphRAG paper]https://arxiv.org/abs/2404.16130 โ€” the original research
- [SQLite FTS5 documentation]https://www.sqlite.org/fts5.html โ€” full-text search engine
- [Leiden algorithm]https://arxiv.org/abs/1810.08473 โ€” community detection used by GraphRAG
- [Ollama]https://ollama.ai/ โ€” local LLM server

---

## ๐Ÿ“„ License

MIT โ€” see [LICENSE](LICENSE).

---

<div align="center">
  <sub>Built with ๐Ÿฆ€ Rust โ€ข SQLite โ€ข Ollama</sub>
</div>