r2r railway deployment
Deploying R2R on Railway
Section titled “Deploying R2R on Railway”This guide shows how to deploy R2R (the knowledge base backend) on Railway alongside your Supen application.
Architecture
Section titled “Architecture”┌─────────────────┐ ┌─────────────────┐│ Supen (Next.js)│────────>│ R2R Service ││ Railway │ HTTP │ Railway │└─────────────────┘ └─────────────────┘ │ v ┌─────────────────┐ │ PostgreSQL │ │ (Railway DB) │ └─────────────────┘Step 1: Deploy PostgreSQL with pgvector
Section titled “Step 1: Deploy PostgreSQL with pgvector”- In Railway dashboard, click ”+ New” → “Database” → “PostgreSQL”
- Name it
r2r-postgres - After it’s created, click on it and go to “Settings”
- Note down the connection details (you’ll need these)
Step 2: Deploy R2R Service
Section titled “Step 2: Deploy R2R Service”Option A: Using Railway Template (Easiest)
Section titled “Option A: Using Railway Template (Easiest)”- Go to Railway dashboard
- Click ”+ New” → “Empty Service”
- Click on the new service → “Settings”
- Under “Source”, select “Docker Image”
- Enter:
ragtoriches/r2r:latest - Under “Deploy”, click “Deploy”
Option B: Using Docker Image Directly
Section titled “Option B: Using Docker Image Directly”- Create a new service in Railway
- Configure it with these settings:
Environment Variables:
POSTGRES_USER=postgresPOSTGRES_PASSWORD=${{Postgres.POSTGRES_PASSWORD}}POSTGRES_DBNAME=${{Postgres.PGDATABASE}}POSTGRES_HOST=${{Postgres.PGHOST}}POSTGRES_PORT=${{Postgres.PGPORT}}OPENAI_API_KEY=<your-openai-key>R2R_PROJECT_NAME=supenNetworking:
- Railway will automatically expose port
7272 - Note the Railway-generated URL (e.g.,
r2r-production.up.railway.app)
Step 3: Configure Supen to Use R2R
Section titled “Step 3: Configure Supen to Use R2R”In your Supen Railway service, add these environment variables:
R2R_API_URL=https://r2r-production.up.railway.appR2R_API_KEY= # Optional, leave empty if not using authStep 4: Verify Deployment
Section titled “Step 4: Verify Deployment”Test the R2R health endpoint:
curl https://r2r-production.up.railway.app/v3/healthYou should get:
{ "status": "ok", "version": "3.x.x"}Cost Estimation
Section titled “Cost Estimation”Railway Pricing:
- PostgreSQL: ~$5-10/month (Hobby plan, shared)
- R2R Service: ~$5-10/month (depends on usage)
- Total: ~$10-20/month
Alternative: Use SciPhi Cloud (Hosted R2R)
Instead of deploying R2R yourself, you can use SciPhi’s hosted version:
- Sign up at https://app.sciphi.ai (free tier available)
- Get your API key
- Set in Supen:
R2R_API_URL=https://api.sciphi.aiR2R_API_KEY=<your-sciphi-api-key>Cost: $0/month (free tier) → Pay as you grow
Recommended Approach
Section titled “Recommended Approach”For development and small-scale production:
- ✅ Use SciPhi Cloud (free tier, zero infrastructure)
For larger deployments with privacy requirements:
- ✅ Deploy R2R on Railway (full control, dedicated instance)
Local Development
Section titled “Local Development”For local development, you can still use Docker:
# Option 1: Docker Compose (if you want local R2R)docker compose up r2r r2r-postgres
# Option 2: Point to Railway/SciPhi (no local R2R)# Just set R2R_API_URL in your .env.localR2R_API_URL=https://r2r-production.up.railway.appTroubleshooting
Section titled “Troubleshooting”R2R won’t start
Section titled “R2R won’t start”- Check PostgreSQL is running and reachable
- Verify POSTGRES_* environment variables are correct
- Check Railway logs for R2R service
Connection refused from Supen
Section titled “Connection refused from Supen”- Ensure R2R service is running (check Railway dashboard)
- Verify R2R_API_URL is correct (include https://)
- Check if R2R health endpoint responds
Slow document ingestion
Section titled “Slow document ingestion”- Check R2R service has enough memory (upgrade plan if needed)
- Consider using SciPhi Cloud which auto-scales