Document RAG Using CLI

Description

Use command-line tools to build Document RAG workflows

Difficulty

Beginner

Duration

15 min

You will need
  • TrustGraph deployed (Quick Start)
  • Familiarity with Document RAG concepts
Goal

Use CLI tools to load documents, create Document RAG flows, and query using vector similarity search.

This guide covers the same Document RAG workflow as the Document RAG guide, but using command-line tools instead of the Workbench.

New to Document RAG? Read the Document RAG guide first to understand the concepts and limitations.

This guide demonstrates:

  • Loading documents via CLI
  • Creating Document RAG flows
  • Querying with vector search

Step-by-Step Guide

Step 1: Load Your Document

Download and load the example document:

wget -O phantom-cargo.md https://raw.githubusercontent.com/trustgraph-ai/example-data/refs/heads/main/tracking/operation-phantom-cargo.md

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

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 Document RAG flow:

tg-start-flow -n document-rag -i doc-rag -d "Document RAG"

Step 4: Submit the Document for Processing

Submit the document for processing:

tg-start-library-processing \
    --flow-id doc-rag \
    --document-id https://trustgraph.ai/doc/phantom-cargo \
    --collection intelligence \
    --processing-id urn:processing-01

Step 5: Monitoring (Optional)

Processing is fast for Document RAG. For monitoring details, see the Document RAG guide monitoring section.

Step 6: Query with Document RAG

Query using vector similarity search:

tg-invoke-document-rag \
    -f doc-rag -C intelligence \
    -q 'What is the PHANTOM CARGO report about?'

Expected output:

The PHANTOM CARGO report is about an operation that detected unusual shipping
patterns involving a Dubai-based freight company, Meridian Logistics LLC...

Next Steps