Chapter 2: Setting Up Your Development Environment

This chapter guides you through setting up all necessary components for your RAG chatbot system. We'll cover installation, configuration, and best practices for each service in our stack.

Installing n8n

The most cost-effective way to run n8n is through a budget-friendly VPS setup. This method, detailed in this comprehensive guide, can save you thousands compared to commercial automation platforms.

Cost Breakdown

  1. Server (Required): $35.49/year

  2. Professional Installation (Recommended): $30 one-time fee

    • Expert setup and configuration
    • Ensures proper security settings
  3. Disaster Recovery (Optional): $6/month

    • BackBlaze backup integration
    • Daily backup automation available

Total first-year cost: $65.49 (or $137.49 with disaster recovery) Ongoing annual cost: $35.49 (or $107.49 with disaster recovery)

Alternative Installation Methods

While the VPS setup offers the best value, here are other installation options:

Docker Installation

Cost-effective VPS setup script for n8n installation with Docker and security configurations
# Pull the n8n image
docker pull n8nio/n8n

# Run n8n container
docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  n8nio/n8n

NPM Installation

# Install n8n globally
npm install n8n -g

# Start n8n
n8n start

Cloud Options

Configuration Best Practices

Create an .env file in your n8n root directory:

# Basic Configuration
N8N_HOST=your-domain.com
N8N_PORT=5678
N8N_PROTOCOL=https
N8N_USER_FOLDER=/home/node/.n8n

# Security Settings
N8N_BASIC_AUTH_ACTIVE=true
N8N_BASIC_AUTH_USER=your-username
N8N_BASIC_AUTH_PASSWORD=your-secure-password

# Execution Settings
N8N_WORKFLOW_TIMEOUT=3600
N8N_SAVE_EXECUTION_PROGRESS=true

Setting up Azure OpenAI

Account Creation and Access

  1. Azure Subscription Setup

    • Navigate to Azure Portal (portal.azure.com)
    • Create or select a subscription
    • Request access to Azure OpenAI service
  2. Resource Creation

    Steps:
    1. Create new resource → Azure OpenAI
    2. Select subscription and resource group
    3. Choose region with available capacity
    4. Select pricing tier
    

Model Deployment

Deploy necessary models for our RAG system:

  1. Text Embedding Model

    Model: text-embedding-3-large
    Deployment name: text-embedding-3-large
    Version: Latest
    
  2. Chat Completion Model

    Model: gpt-4
    Deployment name: gpt-4
    Version: Latest
    

API Configuration

Save these values for later use in n8n:

Required Information:
- API Key
- API Base URL (endpoint)
- API Version
- Deployment names for each model

Configuring Pinecone

Account Setup

  1. Create a Pinecone account at https://www.pinecone.io/
  2. Select the starter tier (free with Azure credits)

Index Creation

Create an index with these specifications:

{
  "name": "bizstack",
  "dimension": 3072,  // For Azure OpenAI text-embedding-3-large
  "metric": "cosine",
  "pods": 1,
  "replicas": 1,
  "pod_type": "s1.x1"
}

API Access

Save these credentials:

- API Key
- Environment
- Project ID

Environment Setup and Security

Credentials Management in n8n

Access the n8n credentials page:

  1. Navigate to Settings → Credentials
  2. Add new credentials for each service:

Azure OpenAI Credentials

Name: Azure OpenAI API
API Key: [Your API Key]
API Base URL: [Your Endpoint]
API Version: 2024-02-15-preview

Pinecone Credentials

Name: Pinecone API
API Key: [Your API Key]
Environment: [Your Environment]

Security Best Practices

  1. Network Security

    # Nginx configuration example
    server {
       listen 443 ssl;
       server_name n8n.yourdomain.com;
    
       ssl_certificate /path/to/cert.pem;
       ssl_certificate_key /path/to/key.pem;
    
       location / {
           proxy_pass http://localhost:5678;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
       }
    }
    
  2. Access Control

    • Enable basic authentication
    • Set up IP whitelist if needed
    • Use secure passwords
    • Enable HTTPS
  3. Environment Variables

    • Use .env files
    • Never commit credentials
    • Rotate API keys regularly

Cost Considerations and Optimization

Azure OpenAI Costs

Monitor and optimize:

  1. Embedding Costs

    • Track token usage
    • Batch requests when possible
    • Cache embeddings
  2. Chat Completion Costs

    • Monitor context window size
    • Optimize prompt length
    • Use appropriate model tiers

Pinecone Optimization

  1. Storage Costs

    • Monitor vector count
    • Use namespaces effectively
    • Clean up unused vectors
  2. Query Costs

    • Optimize search parameters
    • Use metadata filtering
    • Monitor query volume

n8n Resource Usage

  1. CPU and Memory

    # Monitor resource usage
    docker stats n8n
    
  2. Storage

    • Monitor execution data
    • Clean up old workflows
    • Optimize binary data handling

Testing Your Setup

Connectivity Test Workflow

Create a simple n8n workflow to test all connections:

1. Manual Trigger Node
2. HTTP Request Node (Test Azure OpenAI)
3. Code Node (Test Pinecone)
4. HTTP Response Node

Health Check Implementation

// Health check code node
const testResults = {
  azureOpenAI: false,
  pinecone: false,
  n8n: true
};

try {
  // Test Azure OpenAI
  const openAIResponse = await $node.executeWorkflow('test-openai');
  testResults.azureOpenAI = openAIResponse.success;

  // Test Pinecone
  const pineconeResponse = await $node.executeWorkflow('test-pinecone');
  testResults.pinecone = pineconeResponse.success;
} catch (error) {
  console.error('Health check failed:', error);
}

return testResults;

Troubleshooting Common Issues

Azure OpenAI

  1. Rate limiting
  2. Model availability
  3. Token limits

Pinecone

  1. Connection timeouts
  2. Index creation delays
  3. Quota limits

n8n

  1. Memory issues
  2. Webhook configuration
  3. Database connections

Next Steps

With your environment set up, you're ready to start building the RAG chatbot. In the next chapter, we'll focus on data collection and processing, implementing the foundation of our system.

Key Takeaways:


Next Chapter: Building the Foundation - Data Collection