Skip to content

en 02 03 cli interactive guide and playground

Rael Corrales edited this page Nov 26, 2026 · 2 revisions

CLI Guide: Diagnostics, REPL, and Scaffolding

The framework provides a unified command-line tool suite under ai-rag (and the rag-mcp standalone binary).

This CLI validates your environment, lets you interactively test models and embeddings in your terminal, and scaffolds production-ready microservices without writing boilerplate.


1. System Health Check: ai-rag doctor

Before debugging unexpected connection errors, run:

ai-rag doctor

What doctor Verifies Internally:

  1. Python Version: Confirms Python runtime is $\ge 3.11$.
  2. SQLite FTS5 Extension: Checks that the local SQLite engine supports Full-Text Search (required for BM25 hybrid retrieval).
  3. Configuration Loading: Validates .env formatting and syntax.
  4. API Key Presence: Verifies credentials for Gemini, OpenAI, Anthropic, etc.
  5. Filesystem Permissions: Ensures write permissions for SQLite .db storage.
  6. Local Model Connectivity: If OLLAMA_BASE_URL is set, verifies that the Ollama daemon is reachable.
Checking AI RAG Common Framework Environment:
  [PASS] Python Version: 3.11.9 (64-bit)
  [PASS] SQLite FTS5 Full-Text Engine: Available
  [PASS] Settings File: .env loaded successfully
  [PASS] Provider 'gemini': API key configured (gemini-2.5-flash)
  [INFO] Provider 'openai': Not configured (optional)
  [PASS] Storage permissions: Write access OK (./data)
============================================================
Status: HEALTHY - Environment is ready for production.

2. Interactive Terminal Playground: ai-rag repl

The REPL (Read-Eval-Print Loop) is an interactive terminal session where you can query models, ingest documents on the fly, and inspect live token spend without writing Python scripts.

Launch the REPL with:

ai-rag repl

Available REPL Commands:

Command Action
/help Displays available commands.
/provider <name> Switches active provider on the fly (gemini, openai, anthropic, ollama).
/model <name> Switches active model (e.g., /model gpt-4o-mini).
/ingest <path> Ingests a text or markdown file into the temporary vector store.
/query <question> Executes a hybrid RAG query against ingested documents.
/cost Displays accumulated tokens and dollar spend for the current session.
/clear Clears terminal screen and conversation buffer.
/exit or /quit Exits the interactive session.

Example REPL Session:

ai-rag repl (v0.19.10) - Type /help for options or /exit to quit.
Active Provider: gemini (gemini-2.5-flash)

> /ingest ./docs/architecture_manual.md
Ingesting 'architecture_manual.md'... (12 chunks indexed in SQLiteVectorStore)

> /query What is the HTTP client timeout policy?
Searching hybrid index (BM25 + Dense)...
[RAG Answer]:
According to the architecture manual (section 3.2), the timeout policy enforces
a strict 30.0-second limit for full completions and 10.0 seconds for embeddings,
after which the client fails over to the next candidate in the pool.

> /cost
Current Session:
- Prompt tokens: 452
- Completion tokens: 78
- Estimated spend: $0.000057 USD

3. Microservice Scaffolding: ai-rag init

Generate a standardized, production-ready microservice project structure:

ai-rag init my-ai-service

Generated Project Structure:

my-ai-service/
├── app/
│   ├── __init__.py
│   ├── main.py              # FastAPI app pre-configured with /query, /metrics, /healthz
│   ├── config.py            # Typed Settings schema
│   └── services/
│       └── rag.py           # RAGEngine service with SQLiteVectorStore
├── tests/
│   ├── conftest.py
│   └── test_rag.py          # Asynchronous unit tests with pytest
├── .env.example             # Environment variable template
├── .gitignore               # Security-hardened exclusions
├── Dockerfile               # Ultra-lightweight container (< 100MB)
├── pyproject.toml           # Clean package dependencies
└── README.md                # Service bootstrap instructions

Run the new microservice immediately:

cd my-ai-service
pip install -e .
uvicorn app.main:app --reload

4. Standalone MCP Server: rag-mcp

Expose your local knowledge base to tools like Claude Desktop or Cursor via the CLI:

rag-mcp --db-path ./knowledge.db --transport stdio

English Documentation | Documentación en Español


English Documentation (EN)


Documentación en Español (ES)

Clone this wiki locally