This guide demonstrates how to leverage R2R’s powerful analytics and logging features. These capabilities allow you to monitor system performance, track usage patterns, and gain valuable insights into your RAG application’s behavior.
The features described in this cookbook are typically restricted to superusers. Ensure you have the necessary permissions before attempting to access these features.
For more information on user roles and permissions, including how to set up and manage superuser accounts, please refer to our User Auth Cookbook.
Before diving into the authentication features, ensure you have R2R installed and configured as described in the installation guide. For this guide, we’ll use the default configuration. Further, r2r serve must be called to serve R2R in either your local environment or local Docker engine.
These logs provide detailed information about each operation, including search results, queries, latencies, and LLM responses.To fetch the logs directly from an instantiated R2R object:
Copy
Ask AI
app = R2R()# Perform some searches / RAG completions# ...# Get the latest logslogs = app.logs()print(logs)
Advanced analytics features are still in an experimental state - please reach out to the R2R team if you are interested in configuring / using these additional features.
R2R’s analytics system is flexible and allows for custom analysis. You can specify different filters and analysis types to focus on specific aspects of your application’s performance.
To get meaningful analytics, you need a substantial amount of data. Here’s a script to preload your database with random searches:
Copy
Ask AI
import randomfrom r2r import R2R, GenerationConfigapp = R2R()# List of sample queriesqueries = [ "What is artificial intelligence?", "Explain machine learning.", "How does natural language processing work?", "What are neural networks?", "Describe deep learning.", # Add more queries as needed]# Perform random searchesfor _ in range(1000): query = random.choice(queries) app.rag(query, GenerationConfig(model="openai/gpt-4o-mini"))print("Preloading complete. You can now run analytics on this data.")
After running this script, you’ll have a rich dataset to analyze using the analytics features described above.
R2R’s logging and analytics features provide powerful tools for understanding and optimizing your RAG application. By leveraging these capabilities, you can:
Monitor system performance in real-time
Analyze trends in search and RAG operations
Identify potential bottlenecks or areas for improvement
Track user behavior and usage patterns
Make data-driven decisions to enhance your application’s performance and user experience
For detailed setup and basic functionality, refer back to the R2R Quickstart. For more advanced usage and customization options, join the R2R Discord community.