RAG CLI¶
The RAG CLI is a comprehensive command-line interface for interacting with the RAG Modulo system. It provides a complete set of tools for managing collections, documents, search operations, user authentication, LLM providers, and pipelines through a streamlined command-line experience.
Status: The CLI is fully functional as of the latest updates. All major features including authentication, collection management, document upload, and search operations are working correctly.
Overview¶
RAG CLI enables developers and administrators to:
- Authenticate with IBM OIDC providers and manage tokens
- Manage Collections - create, list, update, and configure document collections
- Upload Documents - add and process documents for retrieval
- Execute Searches - perform semantic search, hybrid search, and RAG queries
- Administer Users - manage user accounts and permissions
- Configure Providers - manage LLM providers and their settings
- Manage Pipelines - create and configure search pipelines
- System Health - check system status and run diagnostics
- Configuration - manage CLI profiles and settings
Quick Start¶
Prerequisites¶
- RAG Modulo backend running (default:
http://localhost:8000) - Valid IBM OIDC credentials (for production) or mock authentication enabled (for development)
- Python 3.8+ environment
Installation¶
# Install from source
git clone https://github.com/manavgup/rag_modulo.git
cd rag_modulo/backend
poetry install
# Activate environment
poetry shell
First Steps¶
-
Check CLI availability:
-
Authenticate (Production):
Or for development/testing:
-
Create a collection:
-
Upload a document:
-
Search your collection:
Note: The CLI automatically retrieves user context and pipeline configuration from the authentication session.
Specialized CLIs¶
For focused workflows, use the specialized CLI tools:
rag-search¶
Direct search interface for quick queries without the overhead of the full CLI:
# Direct search
rag-search "What is AI?" --collection abc123
# Semantic search
rag-search "Explain quantum computing" --collection abc123 --semantic
# Hybrid search
rag-search "Find similar docs" --collection abc123 --hybrid
rag-admin¶
Administrative operations for user and system management:
# User management
rag-admin users list --role admin
rag-admin users create user@example.com --name "John Doe" --role admin
# System health
rag-admin health check --api --database --vector-db
# Configuration
rag-admin config validate --api-url http://localhost:8000
- Verify connection:
Basic Workflow¶
# Create a collection
./rag-cli collections create "My Documents" --description "Personal knowledge base"
# Upload documents
./rag-cli documents upload COLLECTION_ID ./my-document.pdf --title "Important Document"
# Search your collection
./rag-cli search query COLLECTION_ID "What are the key findings?"
Architecture¶
Component Structure¶
The CLI follows a modular architecture with clear separation of concerns:
rag_modulo/cli/
โโโ main.py # Entry point and argument parsing
โโโ client.py # HTTP API client with retry logic
โโโ auth.py # Authentication manager
โโโ config.py # Configuration and profile management
โโโ output.py # Output formatting (table, json, csv, yaml)
โโโ exceptions.py # Custom exception types
โโโ commands/ # Command modules
โโโ base.py # Base command class
โโโ auth.py # Authentication commands
โโโ collections.py # Collection management
โโโ documents.py # Document operations
โโโ search.py # Search functionality (FIXED)
โโโ users.py # User management
โโโ providers.py # LLM provider management
โโโ pipelines.py # Pipeline configuration
โโโ health.py # System health checks
โโโ config.py # Configuration commands
Data Flow¶
The CLI communicates with the RAG Modulo backend through RESTful APIs:
โโโโโโโโโโโโโโโ HTTP/REST โโโโโโโโโโโโโโโโโโโ
โ RAG CLI โ โโโโโโโโโโโโโโ> โ Backend API โ
โ โ โ (FastAPI) โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โ Local Storage โ Services
โ (auth tokens) โ
โผ โผ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ ~/.rag/ โ โ PostgreSQL โ
โ config.json โ โ Milvus โ
โโโโโโโโโโโโโโโ โ Document Store โ
โโโโโโโโโโโโโโโโโโโ
Authentication Flow¶
The CLI now properly handles user context for all operations:
- Authentication: User authenticates via OIDC or mock auth
- User Context: CLI retrieves user info from
/api/auth/me - Pipeline Resolution: Fetches user's default pipeline if needed
- Request Execution: Includes full context in API calls
Key Features¶
Authentication¶
- IBM OIDC Integration: Seamless authentication with IBM identity providers
- Token Management: Automatic token refresh and secure local storage
- Multi-Profile Support: Configure multiple environments (dev, staging, prod)
Collection Management¶
- Create Collections: Define document repositories with custom settings
- Vector Database Support: Choose from Milvus, ChromaDB, and other backends
- Privacy Controls: Public and private collection management
Document Processing¶
- Multi-Format Support: PDF, DOCX, TXT, and more
- Chunking Strategies: Configurable text segmentation
- Metadata Management: Rich document tagging and categorization
Search & Retrieval¶
- Semantic Search: Vector-based similarity search
- RAG Queries: Generate answers using retrieved context
- Result Filtering: Fine-tune results with relevance controls
Configuration¶
The CLI uses a configuration file located at ~/.rag/config.json:
{
"profiles": {
"default": {
"api_url": "http://localhost:8000",
"timeout": 30,
"auth": {
"provider": "ibm",
"client_id": "your-client-id"
}
}
},
"active_profile": "default"
}
Implementation Status¶
โ Fully Implemented Features¶
- Authentication System: OIDC login, token management, profile support
- User Management: Create, list, update, delete users
- Collection Management: Full CRUD operations, sharing, status tracking
- Document Management: Upload, batch upload, reprocess, export
- Search Operations: Query, explain, batch, semantic, hybrid search
- Provider Management: List, configure, test LLM providers
- Pipeline Management: Create, update, delete, test pipelines
- System Health: Health checks, monitoring, diagnostics
- Configuration: Profile management, settings, import/export
โ Not Yet Implemented¶
- Team Management: Team creation, member management, role assignment
- No
teams.pycommand module exists yet - Team-related parameters in user commands are placeholders
Recent Fixes¶
The search functionality has been completely fixed to properly: - Retrieve user context from /api/auth/me - Fetch user's default pipeline automatically - Call the correct /api/search endpoint with proper schema - No hardcoded UUIDs or user IDs
Testing Coverage¶
The CLI has comprehensive test coverage across the testing pyramid:
Test Structure¶
tests/
โโโ atomic/
โ โโโ test_cli_core.py # Pure logic tests, no dependencies
โโโ unit/
โ โโโ test_cli_client.py # API client tests with mocks
โ โโโ test_cli_atomic.py # Command and config tests
โโโ integration/
โ โโโ test_cli_integration.py # Service integration tests
โโโ e2e/
โโโ test_cli_e2e.py # Complete workflow tests
Running Tests¶
# Run all CLI tests
pytest tests/ -k cli
# Run specific test levels
pytest tests/atomic/test_cli_core.py
pytest tests/unit/test_cli_client.py
pytest tests/integration/test_cli_integration.py
pytest tests/e2e/test_cli_e2e.py
# Run with coverage
pytest tests/ -k cli --cov=rag_solution.cli
Development Mode¶
For development and testing, use mock authentication:
# Enable mock authentication
export TESTING=true
export SKIP_AUTH=true
# Optional: Set specific mock token
# Note: MOCK_TOKEN no longer needed - backend provides bypass token automatically
# Run CLI commands without real authentication
rag-cli collections list
rag-cli search query <collection_id> "test query"
Mock Authentication Behavior¶
When mock authentication is enabled: 1. Automatically creates a mock user if not exists 2. Initializes default LLM provider and pipeline 3. Sets up required prompt templates 4. All commands work without real OIDC authentication
Common Workflows¶
Complete Document Processing Workflow¶
# 1. Setup and authenticate
rag-cli auth login
# 2. Create a collection
COLLECTION_ID=$(rag-cli collections create "Research Papers" \
--description "ML research papers" \
--output json | jq -r '.id')
# 3. Upload documents
rag-cli documents upload $COLLECTION_ID \
paper1.pdf paper2.pdf paper3.pdf
# 4. Monitor processing
rag-cli collections status $COLLECTION_ID --wait
# 5. Search the collection
rag-cli search query $COLLECTION_ID \
"What are the latest advances in transformer models?"
# 6. Get search explanation
rag-cli search explain $COLLECTION_ID \
"transformer architecture improvements" \
--show-retrieval --show-rewriting
Batch Operations¶
# Batch document upload
rag-cli documents batch-upload $COLLECTION_ID \
--directory ./documents/ \
--pattern "*.pdf"
# Batch search
rag-cli search batch $COLLECTION_ID \
--queries "query1" "query2" "query3" \
--output-file results.json
Troubleshooting¶
Search Not Working¶
If search returns errors about missing pipeline_id or user_id:
-
Ensure you're authenticated:
-
Check user has default pipeline:
-
For testing, use mock auth:
Collection Processing Stuck¶
If documents aren't being processed:
-
Check collection status:
-
Check system health:
-
View backend logs:
Next Steps¶
- Installation Guide - Detailed setup instructions
- Authentication - Configure IBM OIDC authentication
- Commands Reference - Complete command documentation
- Configuration - Advanced configuration options
- Troubleshooting - Common issues and solutions
Support¶
For issues and feature requests, please visit our GitHub repository.