### Hello R2R Code Example Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt A simple 'Hello R2R' code example demonstrating the basic usage of the R2R SDK. This snippet helps users get started with interacting with R2R programmatically. ```python from r2r import Client client = Client() response = client.chat("What is R2R?") print(response) ``` -------------------------------- ### Initialize and Use R2R JavaScript Client Source: https://github.com/sciphi-ai/r2r/blob/main/js/README.md Demonstrates importing the R2R client, initializing it with the R2R server URL, and performing a health check. The client is designed to interact with a running R2R instance. ```javascript const { r2rClient } = require('r2r-js'); const client = new r2rClient('http://localhost:7272'); const healthResponse = await client.health(); // {"status":"ok"} ``` -------------------------------- ### Install R2R JavaScript SDK using npm Source: https://github.com/sciphi-ai/r2r/blob/main/js/README.md This snippet shows how to install the R2R JavaScript SDK using the npm package manager. Ensure Node.js and npm are installed on your system. ```bash npm install r2r-js ``` -------------------------------- ### JavaScript Example: Hello R2R Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt A basic JavaScript example demonstrating how to interact with R2R using the r2r-js client. This code snippet is intended to show a minimal setup for getting started with R2R in a JavaScript environment. ```javascript import { R2RClient } from "r2r-js"; async function main() { const client = new R2RClient({ api_url: "http://localhost:8000" }); // Replace with your R2R API URL try { const response = await client.hello_r2r(); console.log("R2R Response:", response); } catch (error) { console.error("Error interacting with R2R:", error); } } main(); ``` -------------------------------- ### R2R Installation and Server Start Source: https://github.com/sciphi-ai/r2r/blob/main/py/README.md Provides commands for installing the R2R Python package and starting the R2R server in light or full mode. Requires an OpenAI API key and optionally Docker for full mode. ```bash # Quick install and run in light mode pip install r2r export OPENAI_API_KEY=sk-... python -m r2r.serve # Or run in full mode with Docker # git clone git@github.com:SciPhi-AI/R2R.git && cd R2R # export R2R_CONFIG_NAME=full OPENAI_API_KEY=sk-... # docker compose -f compose.full.yaml --profile postgres up -d ``` -------------------------------- ### Install R2R SDKs (Python & JavaScript) Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md Installs the R2R SDKs for both Python and JavaScript environments. For Python, it uses pip, and for JavaScript, it uses npm. Ensure you have the respective package managers installed. ```bash pip install r2r ``` ```bash npm i r2r-js ``` -------------------------------- ### Full Example: R2R JavaScript hello_r2r.js Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt A complete example demonstrating the typical workflow of the R2R JavaScript client, including logging in, ingesting a file, and performing a RAG query. This script serves as a good starting point for understanding the client's capabilities. ```javascript const { r2rClient } = require("r2r-js"); const client = new r2rClient("http://localhost:7272"); async function main() { const files = [ { path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" }, ]; const EMAIL = "admin@example.com"; const PASSWORD = "change_me_immediately"; console.log("Logging in..."); await client.users.login(EMAIL, PASSWORD); console.log("Ingesting file..."); const documentResult = await client.documents.create({ file: { path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" }, metadata: { title: "raskolnikov.txt" }, }); console.log("Document result:", JSON.stringify(documentResult, null, 2)); console.log("Performing RAG..."); const ragResponse = await client.rag({ query: "What does the file talk about?", rag_generation_config: { model: "openai/gpt-4.1", temperature: 0.0, stream: false, }, }); console.log("Search Results:"); ragResponse.results.search_results.chunk_search_results.forEach( (result, index) => { console.log(`\nResult ${index + 1}:`); console.log(`Text: ${result.metadata.text.substring(0, 100)}...`); console.log(`Score: ${result.score}`); }, ); console.log("\nCompletion:"); console.log(ragResponse.results.completion.choices[0].message.content); } main(); ``` -------------------------------- ### Get User Details Example (cURL) Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt An example of how to fetch user details using cURL. This demonstrates the GET request to the user endpoint, including the necessary Authorization header. ```bash curl -X GET "https://api.example.com/v3/users/user_id" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Install and Serve R2R Source: https://github.com/sciphi-ai/r2r/blob/main/docs/introduction/guides/rag.md Commands to install the R2R library and start a local R2R instance using Docker. This is a prerequisite for using RAG features. ```bash pip install r2r r2r serve --docker ``` -------------------------------- ### Initialize the Client Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md Initialize the R2R client using your API key. The client can be configured for remote access. ```APIDOC ## Initialize the Client ### Description Initialize the R2R client. It can be configured to connect to a remote instance or use a local setup. ### Method N/A (Client Initialization) ### Endpoint N/A (Client Initialization) ### Parameters None ### Request Example ```python # Python from r2r import R2RClient # Assumes R2R_API_KEY is set as an environment variable client = R2RClient() # For a remote instance: # client = R2RClient(base_url="http://your-remote-r2r-instance.com") # JavaScript const { r2rClient } = require('r2r-js'); // Assumes R2R_API_KEY is set as an environment variable const client = new r2rClient(); // For a remote instance: // const client = new r2rClient({ baseURL: "http://your-remote-r2r-instance.com" }); ``` ### Response N/A (Client Initialization) ``` -------------------------------- ### Example cURL for Listing Users Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt An example cURL command for listing users associated with a collection. It shows a GET request with a limit query parameter and the required authorization header. ```bash curl -X GET "https://api.example.com/v3/collections/collection_id/users?limit=10" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### R2R JavaScript Client: Full Example Source: https://github.com/sciphi-ai/r2r/blob/main/docs/cookbooks/web-dev.md Demonstrates a complete workflow using the R2R JavaScript client, including login, file ingestion, and performing a RAG query. Requires a running R2R server and the 'r2r-js' package. ```javascript const { r2rClient } = require("r2r-js"); const client = new r2rClient("http://localhost:7272"); async function main() { const files = [ { path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" }, ]; const EMAIL = "admin@example.com"; const PASSWORD = "change_me_immediately"; console.log("Logging in..."); await client.users.login(EMAIL, PASSWORD); console.log("Ingesting file..."); const documentResult = await client.documents.create({ file: { path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" }, metadata: { title: "raskolnikov.txt" }, }); console.log("Document result:", JSON.stringify(documentResult, null, 2)); console.log("Performing RAG..."); const ragResponse = await client.rag({ query: "What does the file talk about?", rag_generation_config: { model: "openai/gpt-4o", temperature: 0.0, stream: false, }, }); console.log("Search Results:"); ragResponse.results.search_results.chunk_search_results.forEach( (result, index) => { console.log(`\nResult ${index + 1}:`); console.log(`Text: ${result.metadata.text.substring(0, 100)}...`); console.log(`Score: ${result.score}`); }, ); console.log("\nCompletion:"); console.log(ragResponse.results.completion.choices[0].message.content); } main(); ``` -------------------------------- ### POST /v3/documents Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md Ingest files into R2R. The server processes, chunks, and summarizes the document. ```APIDOC ## Ingesting Files ### Description Ingest files into the R2R system. The server handles processing, chunking, and generating a summary for the document. ### Method POST ### Endpoint /v3/documents ### Parameters #### Query Parameters - **file_path** (string) - Required - The local path to the file to be ingested. - **ingestion_mode** (string) - Optional - Specifies the ingestion mode ('hi-res' or default). ### Request Example ```python # Python # To ingest a sample document with high-resolution processing: client.documents.create_sample(hi_res=True) # To ingest your own document: client.documents.create(file_path="/path/to/your/document.pdf") # JavaScript // To ingest a sample document with high-resolution processing: client.documents.createSample({ ingestionMode: "hi-res" }) // To ingest your own document: client.documents.create({ filePath: "/path/to/your/document.pdf" }) ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message that the document is being processed. - **task_id** (string) - The ID of the ingestion task (if applicable). - **document_id** (string) - The unique identifier for the ingested document. #### Response Example ```json { "message": "Document created and ingested successfully.", "task_id": null, "document_id": "e43864f5-a36f-548e-aacd-6f8d48b30c7f" } ``` ``` -------------------------------- ### Example cURL for Listing Documents Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt An example cURL command to list documents within a collection. This demonstrates a GET request with a query parameter for limiting the number of results and an authorization header. ```bash curl -X GET "https://api.example.com/v3/collections/collection_id/documents?limit=10" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Example Prompts Configuration Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example configuration for managing prompts used in R2R. This allows users to define and customize prompts for various AI tasks, influencing model behavior. ```toml [prompts] qa_prompt = "Answer the following question based on the context: {context}\nQuestion: {question}" ``` -------------------------------- ### Initialize R2R Client and Setup Collection Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt This Python code demonstrates how to initialize the R2R client, connect to the R2R service, and set up a collection for data ingestion and knowledge extraction. It assumes the R2R service is running locally. ```python from r2r import R2RClient client = R2RClient("http://localhost:7272") # Setup collection and extract knowledge collection_id = "your-collection-id" client.collections.extract(collection_id) client.graphs.pull(collection_id) ``` -------------------------------- ### GET /v3/documents Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md Retrieve a list of ingested documents and their statuses. ```APIDOC ## Getting File Status ### Description Retrieve a list of all ingested documents along with their metadata, status, and other relevant information. ### Method GET ### Endpoint /v3/documents ### Parameters None ### Request Example ```python # Python client.documents.list() # JavaScript client.documents.list() # cURL curl -X GET http://localhost:7272/v3/documents \ -H "Content-Type: application/json" ``` ### Response #### Success Response (200) A list of DocumentResponse objects, each containing: - **id** (string) - Unique document identifier. - **collection_ids** (array) - IDs of collections the document belongs to. - **owner_id** (string) - ID of the document owner. - **document_type** (string) - Type of the document (e.g., 'pdf'). - **metadata** (object) - Additional metadata about the document. - **version** (string) - Document version. - **size_in_bytes** (integer) - Size of the document in bytes. - **ingestion_status** (string) - Current status of ingestion (e.g., 'success'). - **extraction_status** (string) - Status of graph extraction (e.g., 'pending'). - **created_at** (string) - Timestamp when the document was created. - **updated_at** (string) - Timestamp when the document was last updated. - **ingestion_attempt_number** (integer) - Number of ingestion attempts. - **summary** (string) - Summary of the document content. - **summary_embedding** (string) - Embedding vector for the summary. - **total_tokens** (integer) - Total number of tokens in the document. #### Response Example ```json [ { "id": "e43864f5-a36f-548e-aacd-6f8d48b30c7f", "collection_ids": ["122fdf6a-e116-546b-a8f6-e4cb2e2c0a09"], "owner_id": "2acb499e-8428-543b-bd85-0d9098718220", "document_type": "pdf", "metadata": {"title": "DeepSeek_R1.pdf", "version": "v0"}, "version": "v0", "size_in_bytes": 1768572, "ingestion_status": "success", "extraction_status": "pending", "created_at": "2025-02-08T03:31:39.126759Z", "updated_at": "2025-02-08T03:31:39.160114Z", "ingestion_attempt_number": null, "summary": "The document contains a comprehensive overview of DeepSeek-R1...", "summary_embedding": null, "total_tokens": 29673 }, ... ] ``` ``` -------------------------------- ### Manage R2R Environments with Project Names Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example commands demonstrating how to manage different R2R environments (development, staging, production) by setting the R2R_PROJECT_NAME environment variable and using it with the `r2r serve` command. This allows for isolation and distinct configurations. ```bash # Development export R2R_PROJECT_NAME=r2r_dev r2r serve --docker --project-name r2r-dev # Staging export R2R_PROJECT_NAME=r2r_staging r2r serve --docker --project-name r2r-staging # Production export R2R_PROJECT_NAME=r2r_prod r2r serve --docker --project-name r2r-prod ``` -------------------------------- ### Example cURL for Getting Entity Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt An example cURL command to retrieve a specific entity from a graph using its collection and entity IDs. Includes the GET request, URL, and authorization header. ```bash curl -X GET "https://api.example.com/v3/graphs/collection_id/entities/entity_id" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Example: User Management in Collections Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Illustrates examples for managing users within collections, including adding, removing, listing users, and retrieving collections for a specific user. ```text # Example for Adding a User to a Collection # ... details omitted ... ``` ```text # Example for Removing a User from a Collection # ... details omitted ... ``` ```text # Example for Listing Users in a Collection # ... details omitted ... ``` ```text # Example for Getting Collections for a User # ... details omitted ... ``` -------------------------------- ### R2R JavaScript Client Authentication Source: https://github.com/sciphi-ai/r2r/blob/main/js/README.md Shows how to log in to the R2R service using email and password. This is an optional step that restricts subsequent commands to user-specific document scopes. Registration and email verification methods are also commented out. ```javascript // client.register("me@email.com", "my_password"), // client.verify_email("me@email.com", "my_verification_code") client.login("me@email.com", "my_password") ``` -------------------------------- ### Example Configuration: LiteLLM Providers for Embedding Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Shows an example configuration for specifying LiteLLM providers to be used for embedding tasks within the R2R system. ```text # Example Configuration for LiteLLM Providers # ... configuration details ... ``` -------------------------------- ### Example cURL for Getting a Relationship (Bash) Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt An example cURL command to demonstrate how to retrieve a specific relationship by its ID. It includes the GET method, the full API endpoint with collection and relationship IDs, and an authorization header. ```bash curl -X GET "https://api.example.com/v3/graphs/collection_id/relationships/relationship_id" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Python Example: User Authentication and Management Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Demonstrates Python examples for various user authentication and management tasks, including token refresh, user-specific search, password management, profile updates, account deletion, and logging out. ```python # Python Example for Token Refresh # ... code ... ``` ```python # Python Example for User-Specific Search # ... code ... ``` ```python # Python Example for Password Management # ... code ... ``` ```python # Python Example for User Profile Management # ... code ... ``` ```python # Python Example for Account Deletion # ... code ... ``` ```python # Python Example for User Logout # ... code ... ``` -------------------------------- ### Get Community cURL Example Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt An example cURL command for retrieving a specific community using the GET /v3/graphs/:collection_id/communities/:community_id endpoint. It illustrates how to specify the collection ID and community ID in the URL and includes the necessary authorization header. ```bash curl -X GET "https://api.example.com/v3/graphs/collection_id/communities/community_id" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Start R2R with Docker Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Instructions for starting the R2R service using Docker Compose. This is a convenient way to deploy and run R2R locally for development and testing purposes. It ensures all necessary services are running. ```bash docker compose up -d ``` -------------------------------- ### POST /v3/retrieval/search Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md Execute a search query against the ingested documents. ```APIDOC ## Executing a Search ### Description Perform a search query against the R2R system to find relevant documents. Supports basic similarity search and advanced methods like hybrid or graph search. ### Method POST ### Endpoint /v3/retrieval/search ### Parameters #### Request Body - **query** (string) - Required - The search query string. ### Request Example ```python # Python client.retrieval.search( query="What is DeepSeek R1?" ) # JavaScript client.retrieval.search({ query: "What is DeepSeek R1?" }) # cURL curl -X POST http://localhost:7272/v3/retrieval/search \ -H "Content-Type: application/json" \ -d '{ "query": "What is DeepSeek R1?" }' ``` ### Response #### Success Response (200) An AggregateSearchResult object containing results from different search types: - **chunk_search_results** (array) - Results from chunk-level similarity search. - **graph_search_results** (array) - Results from graph-based search. - **web_search_results** (array) - Results from web search (if enabled). - **context_document_results** (array) - Results related to context documents. Each result item typically includes score, text, and source information. #### Response Example ```json { "chunk_search_results": [ { "score": 0.643, "text": "Document Title: DeepSeek_R1.pdf\n Text: could achieve an accuracy of over 70%.\n DeepSeek-R1 also delivers impressive results on IF-Eval..." }, ... ], "graph_search_results": [], "web_search_results": [], "context_document_results": [] } ``` ``` -------------------------------- ### GraphRAG Prerequisites Python Example Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Illustrates the Python code required to set up prerequisites for GraphRAG, potentially involving initializing necessary components or configurations. ```python from r2r.graphrag import GraphRAG graphrag = GraphRAG() # Example: Initialize graph database connection graphrag.initialize_graph_db() print("GraphRAG prerequisites initialized.") ``` -------------------------------- ### Get Conversation Details cURL Example Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example cURL command to retrieve details for a specific conversation ID. Requires an Authorization header with a Bearer token. ```bash curl -X GET "https://api.example.com/v3/conversations/conversation_id" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Example Postgres Configuration Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example configuration for connecting R2R to a PostgreSQL database. This includes details on database credentials and connection settings, crucial for data persistence. ```toml [postgres] username = "user" password = "password" host = "localhost" port = 5432 database = "r2r" ``` -------------------------------- ### R2R JavaScript Client: Installation Source: https://github.com/sciphi-ai/r2r/blob/main/docs/cookbooks/web-dev.md Installs the R2R JavaScript client using npm. This is the first step to integrating R2R into a Node.js project. ```zsh npm install r2r-js ``` -------------------------------- ### Example cURL for Listing Entities Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt An example cURL command to demonstrate how to list entities in a graph with a specified limit. This includes the GET request, URL, and authorization header. ```bash curl -X GET "https://api.example.com/v3/graphs/collection_id/entities?limit=10" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### POST /v3/retrieval/rag Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md Generate a Retrieval-Augmented Generation (RAG) response based on a query. ```APIDOC ## RAG (Retrieval-Augmented Generation) ### Description Generate a response using Retrieval-Augmented Generation. This process retrieves relevant information from documents and uses it to inform the generated answer. ### Method POST ### Endpoint /v3/retrieval/rag ### Parameters #### Request Body - **query** (string) - Required - The question or prompt for the RAG system. ### Request Example ```python # Python client.retrieval.rag( query="What is DeepSeek R1?" ) # JavaScript client.retrieval.rag({ query: "What is DeepSeek R1?" }) ``` ### Response #### Success Response (200) - **response** (string) - The generated response based on retrieved context. #### Response Example (Response structure may vary based on RAG implementation and LLM used. Example below is illustrative.) ```json { "response": "DeepSeek-R1 is a large language model that achieves high accuracy on various benchmarks, including IF-Eval, and delivers impressive results." } ``` ``` -------------------------------- ### R2R Web Dev Template Usage (Bash) Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Instructions for cloning and setting up the R2R Web Development Template Repository. This involves cloning the repository, installing dependencies using pnpm, and running the development server. ```bash git clone https://github.com/SciPhi-AI/r2r-webdev-template.git cd r2r-webdev-template pnpm install pnpm dev ``` -------------------------------- ### Example: Pagination and Filtering Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Contains examples demonstrating pagination and filtering capabilities within the R2R system. ```text # Examples for Pagination and Filtering # ... details omitted ... ``` -------------------------------- ### cURL Example for Getting Document Entities Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt This cURL command shows how to fetch entities from a document using a GET request. It includes the API endpoint with a placeholder for the document ID and an authorization header. ```bash curl -X GET "https://api.example.com/v3/documents/document_id/entities" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Interact with R2R Agent (Python) Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Python example demonstrating how to initialize the R2R client and make a simple query to the agent. It also shows how to use the conversation ID for follow-up questions. ```python from r2r import R2RClient # Initialize the client client = R2RClient("http://localhost:7272") # Make a simple query first_reply = client.retrieval.agent( message={"role": "user", "content": "Who was Aristotle?"}, search_settings={"limit": 5, "filters": {}}, ) # Save the conversation ID for continued interaction conversation_id = first_reply["results"]["conversation_id"] # Make a follow-up query using the conversation context second_reply = client.retrieval.agent( message={"role": "user", "content": "What were his contributions to philosophy?"}, search_settings={"limit": 5, "filters": {}}, conversation_id=conversation_id, ) ``` -------------------------------- ### cURL Example for Getting Document Relationships Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt This cURL command demonstrates how to fetch relationships from a document using a GET request. It specifies the API endpoint with a document ID placeholder and includes an authorization header. ```bash curl -X GET "https://api.example.com/v3/documents/document_id/relationships" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Example Auth & Users Configuration Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example configuration for authentication and user management in R2R. This allows setting up API keys and user roles for secure access to R2R services. ```toml [auth] api_key = "your_secret_api_key" ``` -------------------------------- ### Example Graphs Configuration Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example configuration for knowledge graph integration in R2R. This section outlines how to connect and utilize knowledge graphs for enhanced information retrieval. ```toml [graphs] enabled = true ``` -------------------------------- ### Download Ollama Models and Start Server Source: https://github.com/sciphi-ai/r2r/blob/main/docs/cookbooks/local.md This snippet demonstrates how to pull specific LLM and embedding models using Ollama and then start the Ollama server. Ensure Ollama is installed before running these commands. These commands initiate the download of 'llama3.1' and 'mxbai-embed-large' and start the server accessible at http://localhost:11434. ```zsh ollama pull llama3.1 ollama pull mxbai-embed-large ollama serve ``` -------------------------------- ### Example Configuration: r2r.toml for Embedding Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Illustrates a TOML configuration file example for the R2R system, specifically focusing on embedding settings. ```toml # Example: r2r.toml for Embedding Configuration # [embedding] # ... settings ... ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Copies the example environment file and instructs to edit it with specific configurations. This file holds all necessary settings for the deployment. ```bash cp .env.example .env # Edit the .env file with your specific configurations nano .env ``` -------------------------------- ### List All Prompts (cURL) Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example cURL command to list all available prompts. Requires an Authorization header with a Bearer token. This command demonstrates how to interact with the GET /v3/prompts endpoint. ```bash curl -X GET "https://api.example.com/v3/prompts" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Retrieve Document with cURL Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Example of how to retrieve a document's metadata using cURL. This request targets the GET /v3/documents/:id endpoint and requires the document's unique ID. ```bash curl -X GET "https://api.example.com/v3/documents/document_id" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Start R2R with Docker Source: https://github.com/sciphi-ai/r2r/blob/main/llms.txt Launches the Full R2R application using Docker. This command pulls necessary images and starts R2R, Hatchet, and Postgres+pgvector services. Assumes a 'full.toml' configuration file is present. ```bash r2r serve --docker --config-path=full.toml ``` -------------------------------- ### RAG API Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md The RAG API endpoint allows you to perform retrieval augmented generation. You can provide a query and receive a generated answer based on retrieved information. It supports both standard and streaming responses. ```APIDOC ## POST /v3/retrieval/rag ### Description Performs retrieval augmented generation based on a given query. ### Method POST ### Endpoint /v3/retrieval/rag ### Parameters #### Query Parameters None #### Request Body - **query** (string) - Required - The user's query. - **search_settings** (object) - Optional - Configuration for search. - **limit** (integer) - Optional - The maximum number of search results to return. - **rag_generation_config** (object) - Optional - Configuration for RAG generation. - **stream** (boolean) - Optional - Whether to stream the response. ### Request Example ```json { "query": "What is DeepSeek R1?" } ``` ### Response #### Success Response (200) - **generated_answer** (string) - The generated answer to the query. - **search_results** (object) - The results of the search operation. - **citations** (array) - A list of citations used in the generation. - **metadata** (object) - Additional metadata about the response. #### Response Example (Non-streaming) ```plaintext RAGResponse( generated_answer='DeepSeek-R1 is a model that demonstrates impressive performance across various tasks, leveraging reinforcement learning (RL) and supervised fine-tuning (SFT) to enhance its capabilities...', search_results=AggregateSearchResult(...), citations=[Citation(id='cit_3a35e39', object='citation', ...)], metadata={...} ) ``` #### Response Example (Streaming - partial message) ```plaintext Partial message: {'content': [MessageDelta(type='text', text={'value': 'Deep', 'annotations': []})]} ``` ``` -------------------------------- ### R2R SDK Installation Source: https://github.com/sciphi-ai/r2r/blob/main/py/README.md Commands to install the R2R SDK for both Python and JavaScript environments, preparing for client-side interaction with the R2R system. ```bash # Install SDK pip install r2r # Python # or npm i r2r-js # JavaScript ``` -------------------------------- ### Generate RAG Response (Python & JavaScript) Source: https://github.com/sciphi-ai/r2r/blob/main/docs/documentation/README.md Generates a response using Retrieval-Augmented Generation (RAG). This function takes a query and retrieves relevant information augmented with a generative model to produce a coherent answer. ```python client.retrieval.rag( query="What is DeepSeek R1?", ) ``` ```javascript client.retrieval.rag({ query: "What is DeepSeek R1?", }) ```