llama-index-cli

0.5.7 · deprecated · verified Fri Apr 10

llama-index-cli was a command-line interface tool for LlamaIndex, primarily designed to facilitate Retrieval-Augmented Generation (RAG) with local files without writing Python code. It allowed users to ingest documents and perform Q&A or chat within the terminal. The package is currently at version 0.5.7, but it has been officially deprecated and is no longer maintained as of April 2, 2026.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `llamaindex-cli` tool to ingest a local file and query it using Retrieval-Augmented Generation (RAG). It requires an OpenAI API key by default. Note that `llama-index-cli` is deprecated; for new projects, consider using `create-llama` or directly integrating with the `llama-index` Python library.

import os
import subprocess

# NOTE: llama-index-cli is deprecated. Use the main llama-index library
# or the 'create-llama' CLI for new projects.

# 1. Set your OpenAI API key (required by default for embeddings/LLM)
# Replace 'YOUR_OPENAI_API_KEY' with your actual key or set it as an env var.
os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY', 'YOUR_OPENAI_API_KEY')

# Create a dummy file for demonstration
with open('example.txt', 'w') as f:
    f.write('LlamaIndex is a data framework for LLM applications. It helps connect custom data sources with LLMs.')

print("Ingesting 'example.txt' and asking a question via llamaindex-cli...")

# 2. Ingest a file and ask a question
try:
    result = subprocess.run(
        ['llamaindex-cli', 'rag', '--files', 'example.txt', '--question', 'What is LlamaIndex?'],
        capture_output=True, text=True, check=True
    )
    print("--- CLI Output ---")
    print(result.stdout)
    if result.stderr:
        print("--- CLI Errors (if any) ---")
        print(result.stderr)
except FileNotFoundError:
    print("Error: 'llamaindex-cli' command not found. Ensure the package is installed and in your PATH.")
except subprocess.CalledProcessError as e:
    print(f"Error running command: {e}")
    print(f"Stdout: {e.stdout}")
    print(f"Stderr: {e.stderr}")

# Clean up the dummy file
os.remove('example.txt')

view raw JSON →