Thanks to visit codestin.com
Credit goes to github.com

Skip to content

eagurin/r2r-cli

Repository files navigation

R2R CLI

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    # Управление частотой запросов

Installation

From PyPI (Recommended)

pip install r2r-cli

From Source

git clone https://github.com/r2r-ai/r2r-cli.git
cd r2r-cli
pip install -e .

Configuration

Before using the CLI, you need to set up your API key. You can do this in several ways:

  1. Environment variable:

    export R2R_API_KEY=your_api_key
  2. Configuration file: Create a file at ~/.r2r/config.yaml with the following content:

    api_key: your_api_key
  3. Command line option:

    r2r_cli --api-key=your_api_key [command]

Basic Usage

# 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_123456

Command Groups

The 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 operations
  • embeddings: 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)

Advanced Features

Embeddings

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"

Configuration Management

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"

Advanced Search

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.7

Batch Operations

Process 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_123456

Output Formats

Most commands support different output formats:

# Get JSON output
r2r_cli documents list --output json

# Get only IDs
r2r_cli documents list --output ids

Logging

Control 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 list

Shell Completion

Enable shell completion for easier command usage:

Bash

# Add to your .bashrc
source /path/to/r2r-completion.bash

Zsh

# Add to your .zshrc
source /path/to/r2r-completion.zsh

Troubleshooting

Common Errors

  • 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

Getting Help

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

Development

Setting Up Development Environment

# 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

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published