Introduction

This guide extends the R2R Quickstart by demonstrating how to run R2R with a Client-Server architecture. The R2R server can be set up to handle requests, while the client communicates with the server to perform various operations. The R2R server API can be viewed here.

Setting Up the Server

If you are running with Docker, you may skip the server setup step below.

To start the R2R server, ensure you have all necessary dependencies installed as described in the installation guide. Then, use the following command:

python -m r2r.examples.quickstart serve

This command starts the R2R server on the default host 0.0.0.0 and port 8000. You should see output similar to:

r2r.core.providers.vector_db_provider - INFO - Initializing VectorDBProvider with config extra_fields={} provider='pgvector' collection_name='demo_vecs'. - 2024-06-19 16:02:34,612
r2r.core.providers.embedding_provider - INFO - Initializing EmbeddingProvider with config extra_fields={'text_splitter': {'type': 'recursive_character', 'chunk_size': 512, 'chunk_overlap': 20}} provider='openai' base_model='text-embedding-3-small' base_dimension=512 rerank_model=None rerank_dimension=None rerank_transformer_type=None batch_size=128. - 2024-06-19 16:02:35,512
r2r.core.providers.llm_provider - INFO - Initializing LLM provider with config: extra_fields={} provider='litellm' - 2024-06-19 16:02:36,009
INFO:     Started server process [55001]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

Using the Client

R2R includes both a Python client and a TypeScript client. All quickstart commands can be run with the Python client using the --client_server_mode parameter.

Ensure the server is active at http://0.0.0.0:8000 before running client commands. Run client commands in a new terminal.

Example Commands

To ingest documents using the client:

python -m r2r.examples.quickstart ingest_files --client_server_mode --no-media=true

This command sends the ingestion request to the server running at http://localhost:8000.

To perform a search using the client:

python -m r2r.examples.quickstart search --query="Who was Aristotle?" --client_server_mode

This command sends the search query to the server and retrieves the results.

To run a RAG completion:

python -m r2r.examples.quickstart rag --query="What was Uber's profit in 2020?" --client_server_mode

This command sends the RAG query to the server and retrieves the generated response.

To stream RAG results:

python -m r2r.examples.quickstart rag --query="What was Lyft's profit in 2020?" --stream=true --client_server_mode

This command streams the RAG query results from the server.

Summary

The Client-Server model extends the basic R2R quickstart to support more scalable and modular deployments. The server handles requests and performs heavy computations, while clients communicate with the server to perform ingestion, search, RAG, and other operations. This architecture allows for distributed processing and improved resource management in larger applications.

For detailed setup and basic functionality, refer back to the R2R Quickstart. For more advanced usage and customization options, join the R2R Discord community.