Command Line Interface for R2R - a powerful knowledge management platform.
r2r_cli/
├── pyproject.toml # Конфигурация проекта и зависимости
├── setup.py # Установка пакета
├── README.md # Документация
├── CHANGELOG.md # История изменений
├── LICENSE # Лицензия
├── .gitignore # Игнорируемые git файлы
├── tests/ # Модульные и интеграционные тесты
│ ├── __init__.py
│ ├── test_documents.py
│ ├── test_collections.py
│ ├── test_graphs.py
│ └── test_batch.py
├── r2r_cli/ # Основной пакет
│ ├── __init__.py # Версия и метаданные
│ ├── main.py # Точка входа CLI
│ ├── config.py # Загрузка и управление конфигурацией
│ ├── logger.py # Настройка логирования
│ ├── exceptions.py # Определение пользовательских исключений
│ ├── utils/ # Вспомогательные модули
│ │ ├── __init__.py
│ │ ├── formatters.py # Форматирование вывода (JSON, YAML, текст)
│ │ ├── validators.py # Валидация ввода
│ │ └── progress.py # Индикаторы прогресса
│ ├── api/ # Взаимодействие с API R2R
│ │ ├── __init__.py
│ │ ├── client.py # Клиент API
│ │ ├── documents.py # API документов
│ │ ├── collections.py # API коллекций
│ │ └── graphs.py # API графов
│ ├── commands/ # Команды CLI
│ │ ├── __init__.py
│ │ ├── base.py # Базовый класс команды
│ │ ├── documents.py # Команды для документов
│ │ ├── collections.py # Команды для коллекций
│ │ ├── graphs.py # Команды для графов
│ │ └── batch.py # Пакетные операции
│ └── batch/ # Системы пакетной обработки
│ ├── __init__.py
│ ├── processor.py # Обработчик пакетных операций
│ ├── retry.py # Логика повторных попыток
│ └── throttle.py # Управление частотой запросовpip install r2r-cligit clone https://github.com/r2r-ai/r2r-cli.git
cd r2r-cli
pip install -e .Before using the CLI, you need to set up your API key. You can do this in several ways:
-
Environment variable:
export R2R_API_KEY=your_api_key -
Configuration file: Create a file at
~/.r2r/config.yamlwith the following content:api_key: your_api_key
-
Command line option:
r2r_cli --api-key=your_api_key [command]
# Get help
r2r_cli --help
# Show configuration
r2r_cli info
# List documents
r2r_cli documents list
# Upload a document
r2r_cli documents upload path/to/file.pdf
# Search documents
r2r_cli documents search "query text"
# Create a collection
r2r_cli collections create "Collection Name"
# Add document to collection
r2r_cli collections add-document col_123456 doc_789012
# Pull knowledge graph
r2r_cli graphs pull col_123456The CLI is organized into the following command groups:
documents: Manage documents (upload, list, get, delete, search)collections: Manage collections (create, list, update, delete)graphs: Manage knowledge graphs (pull, reset, build communities)batch: Perform batch operationsembeddings: Work with embeddings (list models, create embeddings, compute similarity)config: Manage CLI configuration (list, get, set, unset, init)search: Search documents (query, find similar documents)
Work with vector embeddings:
# List available embedding models
r2r_cli embeddings list
# Create embeddings for text
r2r_cli embeddings create --text "Your text here" --model "model_name"
# Compute similarity between two texts
r2r_cli embeddings similarity --text1 "First text" --text2 "Second text"Manage CLI configuration:
# List current configuration
r2r_cli config list
# Get specific configuration value
r2r_cli config get api_key
# Set configuration value
r2r_cli config set base_url "https://api.example.com"
# Remove configuration value
r2r_cli config unset log_file
# Initialize configuration
r2r_cli config init --api-key "your_api_key"Perform advanced search operations:
# Search documents with a text query
r2r_cli search query "Your search query" --collection col_123456 --limit 20
# Find documents similar to a reference document
r2r_cli search similar doc_123456 --min-score 0.7Process multiple operations at once:
# Upload multiple documents
r2r_cli documents upload-batch "data/*.pdf" -c col_123456
# Process a batch from JSON file
r2r_cli batch process document_ids.json --operation delete
# Add multiple documents to a collection
r2r_cli batch process docs.json --operation add-to-collection --collection col_123456Most commands support different output formats:
# Get JSON output
r2r_cli documents list --output json
# Get only IDs
r2r_cli documents list --output idsControl log verbosity:
# Verbose mode
r2r_cli -v documents list
# Quiet mode (errors only)
r2r_cli -q documents list
# Write logs to file
r2r_cli --log-file=r2r.log documents listEnable shell completion for easier command usage:
# Add to your .bashrc
source /path/to/r2r-completion.bash# Add to your .zshrc
source /path/to/r2r-completion.zsh-
API Key Not Found: Set your API key using one of the configuration methods.
r2r_cli config set api_key "your_api_key"
-
Connection Error: Check your internet connection and API URL.
r2r_cli config get base_url
-
Resource Not Found: Verify that the resource exists.
r2r_cli documents list r2r_cli collections list
-
Permission Error: Ensure you have the necessary permissions.
# Check your API key r2r_cli config get api_key
For more detailed information about a specific command, use the --help option:
r2r_cli documents upload --help
r2r_cli collections add-document --help
r2r_cli embeddings similarity --help# Clone repository
git clone https://github.com/r2r-ai/r2r-cli.git
cd r2r-cli
# Install in development mode with development dependencies
pip install -e ".[dev]"
# Run tests
pytest- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.