How to Integrate RAG

This guide will walk you through the steps to integrate RAG (Retrieval-Augmented Generation) into your product. We’ll cover everything from creating a JWT token to configuring and using the RAG

integration.


1. Prerequisites

Before starting the integration process, make sure you have the following:

  • RAG Access Key: Provided by gtwy.ai to sign your JWT token.

  • User ID: The identifier associated with your user within the system.

  • Organization ID (org_id): The unique identifier for your organization within the platform.

If you don’t have access to the required credentials, reach out to your project admin or request them from your platform administrator.


2. Create a JWT Token

The JWT token is necessary for authenticating requests to the RAG API. Here’s how you can create it:

2.1 Gather Required Information

You’ll need the following values to generate the JWT token:

  • org_id: Your organization’s unique identifier.

  • user_id: The User ID linked with the token.

  • rag_access_key: The secret key provided by gtwy.ai, used for signing the JWT token.

2.2 Generate the JWT Token

The JWT token needs to be signed using the HS256 algorithm. Below is an example of the JSON payload format:

{   
  "org_id": "your_org_id_here",   
  "user_id": "your_user_id_here" 
}

3. Integration

Here's a more specific version of the script integration, including instructions on how to embed the RAG script with the correct token and open the modal:

<script  
     id="rag-main-script"   
     embedToken="YOUR_ACTUAL_EMBED_TOKEN"   
     src="https://chatbot-embed.viasocket.com/rag-prod.js">
</script> 

Steps:

  1. Replace YOUR_ACTUAL_EMBED_TOKEN with the token provided to you by the RAG service.

  2. Once this script is included in your HTML, the RAG functionality will be available.

Opening the RAG Modal:

To open the RAG modal at any point in your app, use the following JavaScript function:

window.openRag(); 

You can call this function when a user clicks a button or triggers a specific action in your app.

Example:

If you want to open the modal when a button is clicked, use the following HTML and JavaScript:

<!-- Button to open the RAG modal --> 
<button onclick="window.openRag()">Open RAG Modal</button>