Deploying R2R on Azure

Azure provides a robust and scalable platform for deploying R2R (RAG to Riches). This guide will walk you through the process of setting up R2R on an Azure Virtual Machine, making it accessible both locally and publicly.

Overview

Deploying R2R on Azure involves the following main steps:

  1. Creating an Azure Virtual Machine
  2. Installing necessary dependencies
  3. Setting up R2R
  4. Configuring port forwarding for local access
  5. Exposing ports for public access (optional)

This guide assumes you have an Azure account and the necessary permissions to create and manage Virtual Machines.

Creating an Azure Virtual Machine

  1. Log in to the Azure Portal.
  2. Click on “Create a resource” and search for “Virtual Machine”.
  3. Choose Ubuntu Server 22.04 LTS - x64 Gen2 as the operating system.
  4. Select a VM size with at least 16GB of RAM, 4-8 vCPU cores, and 500GB of disk for a small-mid sized organization (< 5000 users). The D4s_v3 series is a good starting point.
  5. Configure networking settings to allow inbound traffic on ports 22 (SSH), and optionally 7272 (R2R API).
  6. Review and create the VM.

Exposing Ports for Public Access (Optional)

To make R2R publicly accessible:

  1. Log in to the Azure Portal.

  2. Navigate to your VM > Networking > Network Security Group.

  3. Add a new inbound security rule:

    • Destination port ranges: 7272
    • Protocol: TCP
    • Action: Allow
    • Priority: 1000 (or lower than conflicting rules)
    • Name: Allow_7272
  4. Ensure R2R is configured to listen on all interfaces (0.0.0.0).

After starting your R2R application, users can access it at:

http://<your-vm-ip-address>:7272

Opening ports 7272 in our Azure cloud deployment

Installing Dependencies

SSH into your newly created VM with a command like ssh -i my_pem.pem azureuser@<your-vm-ip-address>:

System info at first connection to the remote instance

Now, run the following commands to install the necessary R2R dependencies:

# Update package list and install Python and pip
sudo apt update
sudo apt install python3-pip

# Install R2R
pip install r2r

# Add R2R to PATH
echo 'export PATH=$PATH:$HOME/.local/bin' >> ~/.bashrc
source ~/.bashrc

# Install Docker
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Add your user to the Docker group
sudo usermod -aG docker $USER
newgrp docker

# Verify Docker installation
docker run hello-world

Successful Docker hello-world output

Setting up R2R

  1. Serve your R2R backend
# Set required remote providers
export OPENAI_API_KEY=sk-...

# Optional - pass in a custom configuration here
r2r serve --docker

Printout for a successful deployment

  1. Double check the health of the system
 r2r health
Time taken: 0.01 seconds
{'results': {'response': 'ok'}}
  1. Test ingesting and searching a sample document from a remote environment
# From your local machine

r2r --base-url=http://<your-vm-ip-address>:7272 ingest-sample-file
sleep 10
r2r --base-url=http://<your-vm-ip-address>:7272 search --query='Who was aristotle?'

Time taken: 0.43 seconds
Sample file ingestion completed. Ingest files response:

[{'message': 'Ingestion task queued successfully.', 'task_id': '887f9f99-cc18-4c1e-8f61-facf1d212334', 'document_id': '9fbe403b-c11c-5aae-8ade-ef22980c3ad1'}]
Vector search results:
{'fragment_id': 'ecc754cd-380d-585f-84ac-021542ef3c1d', 'extraction_id': '92d78034-8447-5046-bf4d-e019932fbc20', 'document_id': '9fbe403b-c11c-5aae-8ade-ef22980c3ad1', 'user_id': '2acb499e-8428-543b-bd85-0d9098718220', 'collection_ids': [], 'score': 0.7822163571248282, 'text': 'Aristotle[A] (Greek: Ἀριστοτέλης Aristotélēs, pronounced [aristotélɛːs]; 384–322 BC) was an Ancient Greek philosopher and polymath. His writings cover a broad range of subjects spanning the natural sciences, philosophy, linguistics, economics, politics, psychology, and the arts. As the founder of the Peripatetic school of philosophy in the Lyceum in Athens, he began the wider Aristotelian tradition that followed, which set the groundwork for the development of modern science.', 'metadata': {'title': 'aristotle.txt', 'version': 'v0', 'chunk_order': 0, 'document_type': 'txt', 'unstructured_filetype': 'text/plain', 'unstructured_languages': ['eng'], 'partitioned_by_unstructured': True, 'associatedQuery': 'Who was aristotle?'}}
...

Configuring Port Forwarding for Local Access

To access R2R from your local machine, use SSH port forwarding:

ssh i my_pem.pem -L 7273:localhost:7273 -L 7274:localhost:7274 azureuser@<your-vm-ip-address>

Replace <your-vm-ip-address> with your Azure VM’s public IP address or DNS name. Note that in the R2R dashboard you will still need to use the remote VM address as requests are made from the client-side.

Security Considerations

  • Use HTTPS (port 443) with a valid SSL certificate for production.
  • Restrict source IP addresses in the security rule if possible.
  • Regularly update and patch your system and applications.
  • Monitor incoming traffic for suspicious activities.
  • Remove or disable the rule when not needed for testing.

Conclusion

You have now successfully deployed R2R on Azure. The application should be accessible locally through SSH tunneling and optionally publicly through direct access to the Azure VM. Remember to configure authentication and implement proper security measures before exposing your R2R instance to the public internet.

For more information on configuring and using R2R, refer to the configuration documentation.