Skip to content

Complex Network RAG - CLI Reference

Command-line interface for Complex Network RAG topology-aware retrieval system.

Installation

pip install -e .

This installs the network-rag command.

Command: network-rag

Usage: network-rag [OPTIONS] COMMAND [ARGS]...

Global Options: - -d, --db PATH - Database file path (default: rag.db) - -v, --verbose - Verbose output - --help - Show help message


Database Management Commands

network-rag db init

Initialize a new RAG database.

Options: - -e, --embedder TEXT - Embedding provider: tfidf or ollama (default: tfidf) - -m, --model TEXT - Model name for embedding provider - --force - Overwrite existing database

Examples:

# Initialize with TF-IDF embeddings
network-rag --db mydata.db db init

# Initialize with Ollama embeddings
network-rag --db mydata.db db init --embedder ollama --model nomic-embed-text

# Force overwrite existing database
network-rag --db mydata.db db init --force

network-rag db info

Show database information (size, node count, metadata fields).

Example:

network-rag --db mydata.db db info

Output:

Database: mydata.db
  Size: 52.00 KB
  Nodes: 150
  Embeddings: 150
  Metadata fields: topic, type, author

network-rag db list

List nodes in the database.

Options: - -n, --limit INT - Number of nodes to show (default: 10) - -f, --filter TEXT - Filter by metadata (key=value), can be used multiple times

Examples:

# List first 10 nodes
network-rag --db mydata.db db list

# List first 20 nodes
network-rag --db mydata.db db list --limit 20

# Filter by metadata
network-rag --db mydata.db db list --filter type=article --filter topic=ml


Document Ingestion Commands

network-rag add

Add a single document to the database.

Arguments: - CONTENT - Document text content (required)

Options: - --id TEXT - Node ID (auto-generated if not provided) - -m, --meta TEXT - Metadata key=value pairs (can be used multiple times) - -e, --embedder TEXT - Embedding provider (default: tfidf)

Examples:

# Add document with auto-generated ID
network-rag --db mydata.db add "Machine learning is a subset of AI"

# Add document with custom ID and metadata
network-rag --db mydata.db add "Deep learning uses neural networks" \
    --id doc123 \
    --meta type=concept \
    --meta topic=ml \
    --meta author="John Doe"

network-rag import

Import documents from JSON/JSONL file.

Arguments: - FILE - Path to input file (required)

Options: - -f, --format - File format: json or jsonl (required) - --id-field TEXT - Field to use as node ID (default: id) - --content-field TEXT - Field to use as content (default: content) - -e, --embedder TEXT - Embedding provider (default: tfidf) - --batch-size INT - Batch size for imports (default: 100)

Examples:

# Import from JSONL file
network-rag --db mydata.db import documents.jsonl --format jsonl

# Import from JSON array with custom fields
network-rag --db mydata.db import papers.json \
    --format json \
    --id-field paper_id \
    --content-field abstract

Input file format (JSONL):

{"id": "doc1", "content": "First document text", "type": "article"}
{"id": "doc2", "content": "Second document text", "type": "blog"}

Input file format (JSON array):

[
  {"id": "doc1", "content": "First document", "type": "article"},
  {"id": "doc2", "content": "Second document", "type": "blog"}
]


Network Analysis Commands

network-rag build

Build similarity network from embeddings.

Options: - --min-similarity FLOAT - Minimum similarity threshold (default: 0.7) - -e, --embedder TEXT - Embedding provider (default: tfidf)

Example:

network-rag --db mydata.db build --min-similarity 0.8

network-rag communities

Detect communities in the network using Louvain algorithm.

Options: - -e, --embedder TEXT - Embedding provider (default: tfidf) - --min-similarity FLOAT - Minimum similarity threshold (default: 0.7)

Example:

network-rag --db mydata.db communities

Output:

Detecting communities...
Built network: 150 nodes, 450 edges (120 strong, threshold=0.70)

✓ Detected 5 communities:

Community 0: 45 nodes
Community 1: 32 nodes
Community 2: 28 nodes
Community 3: 25 nodes
Community 4: 20 nodes

With verbose output:

network-rag --db mydata.db --verbose communities

Search for similar documents.

Arguments: - QUERY - Search query text (required)

Options: - -k, --top-k INT - Number of results (default: 10) - --strategy TEXT - Search strategy: similarity, community, or hybrid (default: similarity) - -e, --embedder TEXT - Embedding provider (default: tfidf)

Examples:

# Basic similarity search
network-rag --db mydata.db search "machine learning algorithms"

# Get top 5 results
network-rag --db mydata.db search "neural networks" --top-k 5

# Use hybrid search strategy
network-rag --db mydata.db search "deep learning" --strategy hybrid

Output:

Searching for: machine learning algorithms

1. doc42 (score: 0.892)
   Machine learning algorithms use statistical methods...
   Metadata: type=article, topic=ml

2. doc17 (score: 0.845)
   Supervised learning algorithms learn from labeled data...
   Metadata: type=tutorial, topic=ml


Enrichment Commands

network-rag enrich

Enrich a single node with extracted metadata.

Arguments: - NODE-ID - Node identifier (required)

Options: - -p, --provider TEXT - Enrichment provider (default: tfidf) - -f, --fields TEXT - Fields to extract (can be used multiple times) - -e, --embedder TEXT - Embedding provider (default: tfidf)

Available fields: - keywords - Extract important keywords - summary - Generate summary (requires LLM) - category - Classify document

Examples:

# Extract keywords
network-rag --db mydata.db enrich doc123 --fields keywords

# Extract multiple fields
network-rag --db mydata.db enrich doc123 \
    --fields keywords \
    --fields summary \
    --provider ollama:llama3.2

Output:

Enriching node doc123...

✓ Enrichment complete:

keywords: machine learning, neural networks, deep learning, algorithms, AI

network-rag enrich-all

Enrich all nodes (or filtered subset) with metadata.

Options: - -p, --provider TEXT - Enrichment provider (default: tfidf) - -f, --fields TEXT - Fields to extract (can be used multiple times) - --filter TEXT - Filter by metadata (key=value), can be used multiple times - -e, --embedder TEXT - Embedding provider (default: tfidf) - -w, --workers INT - Number of parallel workers (default: 1)

Examples:

# Enrich all nodes with keywords
network-rag --db mydata.db enrich-all --fields keywords

# Enrich only articles
network-rag --db mydata.db enrich-all \
    --fields keywords \
    --filter type=article

# Parallel enrichment with LLM
network-rag --db mydata.db enrich-all \
    --fields summary \
    --provider ollama:llama3.2 \
    --workers 4


Utility Commands

network-rag version

Show version information.

Example:

network-rag version


Common Workflows

1. Create and populate a new database

# Initialize database
network-rag --db knowledge.db db init

# Add individual documents
network-rag --db knowledge.db add "Document 1 text" --meta type=note
network-rag --db knowledge.db add "Document 2 text" --meta type=note

# Or import from file
network-rag --db knowledge.db import documents.jsonl --format jsonl

# Check database info
network-rag --db knowledge.db db info

2. Build network and analyze communities

# Build similarity network
network-rag --db knowledge.db build --min-similarity 0.7

# Detect communities
network-rag --db knowledge.db communities

# Search with community-aware retrieval
network-rag --db knowledge.db search "my query" --strategy community

3. Enrich documents with metadata

# Enrich all with TF-IDF keywords
network-rag --db knowledge.db enrich-all --fields keywords

# Enrich specific documents with LLM
network-rag --db knowledge.db enrich doc123 \
    --fields keywords \
    --fields summary \
    --provider ollama:llama3.2

4. Query and explore

# Search for relevant documents
network-rag --db knowledge.db search "machine learning" -k 10

# List all documents with specific metadata
network-rag --db knowledge.db db list \
    --filter type=article \
    --filter topic=ml \
    --limit 20

Tips

  1. Database Location: Use --db to specify different databases for different projects
  2. Embedder Choice: tfidf is fast and free; ollama requires running Ollama server but provides semantic understanding
  3. Search Strategies:
  4. similarity: Pure cosine similarity (fast, simple)
  5. community: Community-aware retrieval (better context)
  6. hybrid: Combines multiple signals (most comprehensive)
  7. Enrichment Providers:
  8. tfidf: Fast, free, good for keywords and classification
  9. ollama:model: Requires Ollama, good for summaries and semantic tasks
  10. openai:model: Requires API key, highest quality but costs money

Troubleshooting

Error: Database does not exist

# Initialize the database first
network-rag --db mydata.db db init

Error: Failed to connect to Ollama

# Make sure Ollama is running
ollama serve

# Or use TF-IDF instead
network-rag --db mydata.db add "text" --embedder tfidf

Error: No results found

# Check if documents exist
network-rag --db mydata.db db list

# Try lower similarity threshold
network-rag --db mydata.db search "query" --strategy similarity