Graph RAG Using CLI
Use command-line tools to build Graph RAG workflows
Intermediate
20 min
- TrustGraph deployed (Quick Start)
- Familiarity with Graph RAG concepts
Use CLI tools to load documents, create Graph RAG flows, and query knowledge graphs.
This guide covers the same Graph RAG workflow as the Graph RAG guide, but using command-line tools instead of the Workbench.
New to Graph RAG? Read the Graph RAG guide first to understand the concepts, workflow, and see visual examples of the knowledge graph in action.
This guide demonstrates:
- Loading documents via CLI
- Creating collections and flows
- Submitting documents for processing
- Querying with Graph RAG
- Monitoring processing
Step-by-Step Guide
Step 1: Load Your Document
Download the example document:
wget -O phantom-cargo.md https://raw.githubusercontent.com/trustgraph-ai/example-data/refs/heads/main/tracking/operation-phantom-cargo.md
Load it into the TrustGraph library:
tg-add-library-document \
--name "PHANTOM CARGO" \
--description "Intelligence report: Operation PHANTOM CARGO" \
--tags 'maritime,intelligence,cargo,grey arms' \
--id https://trustgraph.ai/doc/phantom-cargo \
--kind text/plain \
phantom-cargo.md
Verify the document was added:
tg-show-library-documents
Step 2: Create a Collection
Create an ‘intelligence’ collection:
tg-set-collection -n Intelligence -d 'Intelligence analysis' intelligence
Step 3: Create the Flow
Create a Graph RAG flow:
tg-start-flow -n graph-rag -i graph-rag -d "Graph RAG"
Step 4: Submit the Document for Processing
Submit the document for processing:
tg-start-library-processing \
--flow-id graph-rag \
--document-id https://trustgraph.ai/doc/phantom-cargo \
--collection intelligence \
--processing-id urn:processing-02
Step 5: Monitoring (Optional)
Processing can take time for large documents. For details on monitoring flows using Grafana, see the Graph RAG guide monitoring section.
Step 6: Query with Graph RAG
Query the knowledge graph:
tg-invoke-graph-rag \
-f graph-rag -C intelligence \
-q 'What intelligence resources were using during the PHANTOM CARGO operation?'
Expected output:
The intelligence resources used during the PHANTOM CARGO operation were:
* SIGINT
* MASINT
* Electro-Optical HUMINT
* FININT
* AIS
* synthetic aperture radar (SAR)
* GPS coordinates
Explore visually: For graph exploration, vector search, and 3D visualization, see the visual tools in the Graph RAG guide.
Next Steps
Related CLI Commands
tg-add-library-document- Add documents to librarytg-set-collection- Create collectionstg-start-flow- Start processing flowstg-invoke-graph-rag- Query with Graph RAG
Other Guides
- Graph RAG (Workbench) - Visual walkthrough with graph exploration
- Ontology RAG - Use structured schemas for extraction
- Working with Context Cores - Package and share knowledge