Solution: RAG with OSC and OpenAI - EyevinnOSC/community GitHub Wiki

Getting Started

Retrieval-augmented generation (RAG) is a technique that enables generative artificial intelligence (Gen AI) models to retrieve and incorporate new information.

Example of RAG built with OSC components and OpenAI

Figure 1: Example of RAG built with OSC components and OpenAI

This Solution Guide will help you create a RAG-setup using Open Source Cloud and OpenAI. To set all this in context, we will aim for creating an accompanying assistant for our Eyevinn Open Analytics. The assistant will be a help for other wanting to use our open EPAS specification.

Prerequisites

  • If you have not already done so, sign up for an OSC account.
  • Be on a paid subscription plan.
  • OSC command line tool installed. You need version v 0.14.2 or higher.
  • An account at OpenAI along with a project where you can create assistants.

Overview

We have to setup a project in OpenAI, connect it with a S3 Sync Vectorstore, that in turn is connected to an S3 bucket.

Note

Throughout this guide it is important that you keep track of your secrets and the values assigned to them. In this guide we will use the following Secret Names and Secret Values as can be seen in the table below.

Service Secret Name Secret Value Description Your secret name Your secret value
------------ myminio The name of the MinIO-instance. Note that this can't be a secret.
mysecretusername myuser The user name
mysecretpassword mypwd The password
minioalias mnalias The MinIO alias for our bucket
openaiapikey openaiapi The OpenAI API key for our account

Table 1: Secrets used in this guide

Feel free to fill out the name of your keys and the secret values in the table for easy access throughout this guide.

When we refer to these secret-keys or secret-values we will do it with a < >- notation.
Example:
<mysecretusername>- refers to your secret key that corresponds to mysecretusername in Table 1.
likewise
<myuser>- refers to your secret value that corresponds to myuserin Table 1.

Step 1: Create a MinIO server instance

We will setup an S3 compatible storage device through MinIO, on Open Source Cloud. We will need username, password, and a MinIO-instance name for this. Go to MinIO and click on the "Service Secrets"-tab, then click on the "New Secret"-button and a dialog will be shown where you can create a secret.

We create two secrets: mysecretusername and mysecretpassword.

Screenshot 2025-04-14 at 11 27 09

Figure 2: Create New Secret dialog

After you have created your secrets, click on the "My objstorages"-tab and then click on the button "Create objstorage +" and a new dialog called "Create minio" will be shown, Figure 3.

Fill in your name for the MinIO-instance, then click on the key-icon to the right of the rest of the fields and choose the correct secret for each field, according to Table 1.

Screenshot 2025-04-24 at 12 29 54

Figure 3: Create minio dialog

When you have filled in all the fields click the "Create" button to create your MinIO-instance and then find this instance in the list of MinIO-instances running.

433372315-8ec531ba-f21a-44cd-bd6b-a6ab95d5fd36

Figure 4: Copy the URL

Click on the copy symbol to copy the URL for your running instance because we are going to need it later.

Step 2: Create a bucket

We will now create a storage bucket in the storage service we created in step 1. We begin with downloading and installing the MinIO client using Homebrew.

% brew install minio/stable/mc

Let's start with creating an alias for the MinIO instance we created before. We will need the URL to the instance that we copied in Figure4, and also the username and password we created in step 1.

[!NOTE] It is the Secret Value we need to use, not the Service Secret Name.

% mc alias set <mnalias> <URL to the instance> <myuser> <mypwd>
Added 'mnalias' successfully.

Now we setup a folder called documents on the S3 bucket.

% mc mb <mnalias>/documents
Bucket created successfully 'mnalias/documents'

You can also list the content of your S3 storage with the command: mc ls /documents

Step 3: Setup a S3 Sync Vectorstore

Note

This is done on OpenAI

For this step we need an OpenAI API key and a Vector Store. If you login to OpenAI and navigate to your Playground you can click on the cogwheel to get to your settings. On the left-hand side you choose API keys and then you choose to "Create new secret key" . When you press the "Create Secret" Key a dialog comes up that lets you copy the secret key to store it somewhere safe.

You should also create a Vector Store. Click on the playground menu in the upper right hand corner and then click Assistants on the left hand side and then choose your assistant in the combo-box at the top. Under TOOLS click on the "+Files" button beside the cogwheel.

Screenshot 2025-04-15 at 14 35 35

Figure 5. Navigate to select vectore store

Then click the "Select vectore store" button in the lower left corner. Followed by the Vector stores -> link in the middle. Now you can create a Vector Store by clicking on the "+Create" button. Enter a unique and descriptive name for your vector store. And also copy and save the VectorStoreID, we need this for later.

In OSC navigate to S3 Sync Vectorstore and choose the Service Secrets tab. There are many parameters for the S3 Sync Vectorstore, and to use Service Secrets for all of them is the most secure way. In our example we will name our S3 Sync Vectorstore aisync.

Name of var value Description
Name aisync -
CmdLineArgs S3://documents/ vs_676c... S3://<the folder you created in your S3 bucket> <VectorStore Id>
OpenaiApiKey < OpenaiApiKey > -
Purpose You can leave this blank. Default is assistants
AwsRegion You can leave this blank. Our S3 is not on AWS
S3Endpoint https://eyevinnlab-< myminio >.minio-minio.auto.prod.osaas.io The url to the S3 endpoint
AwsAccessKeyId < myuser > The user name for the MinIO-instance
AwsSecretAccessKey < mypwd > The password for the MinIO-instance

Table 2: parameters for setting up the S3 Sync Vectorstore

Press Create

Now turn your attention to OpenAI and go to your playground and choose your assistant. Press the "+Files" button and enter your Vector Store Id and press select. When you come back to your assistant, do enable File Search.

Step 4: Trigger the Sync

The last step is to trigger the actual syncing of data. And to do this we will use the terminal and issue a command.

For this step we need the OSC command line tool.

You will also need you OSC Personal Access Token. This you can find by clicking on the Settings link, down on your left side. This will display your Account-page. To the right of the Account-tab is a tab called { } API, and when you click there you will see your Personal Access Token. Click the copy-symbol.

In the terminal type this:

% export OSC_ACCESS_TOKEN=<OSC Personal Access Token>

Now your OSC Personal Access Token is saved for this terminal-session.

Now we are going to create the event that triggers the sync.

%  npx @osaas/cli@latest create eyevinn-s3-sync-vectorstore <name of your sync job> \
    -o cmdLineArgs="<CmdLineArgs from Table 2>" \
    -o OpenaiApiKey=<OpenaiApiKey from Table 2> \
    -o S3Endpoint=<S3Endpoint from Table 2> \
    -o AwsAccessKeyId=<AwsAccessKeyId from Table 2> \
    -o AwsSecretAccessKey=<AwsSecretAccessKey from Table 2>

The job can only run once. So before you re-use the command above you have to delete the old job named and this is done with:

% npx @osaas/cli@latest remove eyevinn-s3-sync-vectorstore <name of your sync job>

Now you have setup a RAG with OSC and OpenAI.

Step 5: Enable it for the users

To make the data available you can connect an OpenAI assistant chatbot to your RAG, and thus enabling queries using natural language.

In OSC navigate to OpenAI Assistant and click Create assistant +. And you will get the following dialog:

Screenshot 2025-05-12 at 09 46 01

Figure 6. OpenAI Assistant parameters

Name is a unique name for your OpenAI Assistant instance.

OpenAiApiKey is your OpenAI API key from Table 2.

AssistantId is the unique ID of your Assistant on platform.openai.com.

Note

This is done on OpenAI

Login to OpenAI and navigate to your Playground. On the left-hand side you choose Assistants and choose your assistant in the combo. Now you will see the name of your chosen assistant in the textbox, and underneath you can find your AssistantId

Screenshot 2025-05-12 at 11 38 55

Figure 7. Get hold of assistantId

AppUrl - you can leave this for now.

Click Create and wait until the service is ready. Open the URL to your OpenAI Assistant in a browser to start using it.

Screenshot 2025-05-12 at 11 48 33

Figure 8. OpenAI Assistant WebUI

⚠️ **GitHub.com Fallback** ⚠️