Hello R2R—JavaScript
R2R gives developers configurable vector search and RAG right out of the box, as well as direct method calls instead of the client-server architecture seen throughout the docs:r2r-js/examples/hello_r2r.js
r2r-js Client
Installing
To get started, install the R2R JavaScript client with npm:Creating the Client
First, we create the R2R client and specify the base URL where the R2R server is running:Log into the server
Sign into the server to authenticate the session. We’ll use the default superuser credentials:Ingesting Files
Specify the files that we’ll ingest:Performing RAG
We’ll make a RAG request,Connecting to a Web App
R2R can be easily integrated into web applications. We’ll create a simple Next.js app that uses R2R for query answering. We’ve created a template repository with this code. Alternatively, you can add the code below to your own Next.js project.
Setting up an API Route
First, we’ll create an API route to handle R2R queries. Create a file namedr2r-query.ts
in the pages/api
directory:
r2r-query.ts
r2r-query.ts
Frontend: React Component
Next, create a React component to interact with the API. Here’s an exampleindex.tsx
file:
index.tsx
index.tsx
Template Repository
For a complete working example, you can check out our template repository. This repository contains a simple Next.js app with R2R integration, providing a starting point for your own R2R-powered web applications. For more advanced examples, check out the source code for the R2R Dashboard. R2R Web App Template Repository To use this template:- Clone the repository
- Install dependencies with
pnpm install
- Make sure your R2R server is running
- Start the development server with
pnpm dev