From Podman AI Lab to OpenShift AI

Learn how to rapidly prototype AI applications from your local environment with Podman AI Lab, add knowledge and capabilities to a large language model (LLM) using retrieval augmented generation (RAG), and use the open source technologies on Red Hat OpenShift AI to deploy, serve, and integrate generative AI into your application.

Red Hat OpenShift AI product trialRed Hat OpenShift trial

We’ve provided you with a Jupyter notebook to ingest data into your Elasticsearch database. You’ll walk through setting up an OpenShift AI project with the necessary environment variables to access the Elasticsearch vector database from the provided Jupyter notebook.

In order to get the full benefit from taking this lesson, you need to:

  • Install the OpenShift CLI.
  • Have the appropriate access on your OpenShift cluster to install the OpenShift AI and Elasticsearch operators.
  • Have the appropriate access on your OpenShift cluster to create projects.

In this lesson, you will:

  • Set up OpenShift AI and Elasticsearch vector database.
  • Run a notebook in OpenShift AI that ingests PDFs and URLs into a vector database.

OpenShift AI automated install

Optional: If you already have an OpenShift AI instance with a data science cluster, you can skip this section.

Follow the product documentation to install OpenShift AI or follow the instructions below:

  1. Clone podman-ai-lab-to-rhoai.
  2. Log in to your OpenShift cluster in a terminal with the API token. You can get your API token from the OpenShift web console in the top right corner of the page under admin. Click Copy login command (Figure 1).

    OpenShift web console -> user dropdown -> Copy login command highlighted.
    Figure 1: OpenShift API Copy login command.

    Your OpenShift CLI command should look similar to the one below:

    oc login --token=<YOUR_OPENSHIFT_API_TOKEN> --server=https://<YOUR_OPENSHIFT_API_URL>:6443
  3. We'll first deploy the OpenShift AI operator:

    oc apply -k ./components/openshift-ai/operator/overlays/fast
  4. Now we'll create a data science cluster. Make sure the operator is fully deployed before creating the data science cluster:

    watch oc get pods -n redhat-ods-operator
    NAME					            READY		STATUS
    Rhods-operator-5f7cf677cd-wp8vd 	1/1		    RUNNING
  5. Once the pod has a Running status and is ready, you can run the below command:

    oc apply -k ./components/openshift-ai/instance/overlays/fast

Elasticsearch automated install

Optional: If you already have an Elasticsearch instance, you can skip this section.

Follow the product documentation to install Elasticsearch or follow the instructions below:

  1. Clone podman-ai-lab-to-rhoai.
  2. We'll now deploy the Elasticsearch operator. This will be our vector database:

    oc apply -k ./components/elasticsearch/base/
  3. Now we can create an Elasticsearch cluster instance. Make sure the Elasticsearch operator pod is in a Running state and ready:

    watch oc get pods -n elastic-vectordb
    NAME						        READY		STATUS
    Elastic-operator-5848f6968d-97qjj	1/1		    RUNNING
    
    oc apply -f ./components/elasticsearch/cluster/instance.yaml

Ingest data into the Elasticsearch vector database

Now that the Elasticsearch operator has been deployed and an instance has been created, we can ingest some data and query the vector database.

  1. Go to your OpenShift AI Dashboard. You can get the URL either from the below oc command or the OpenShift web console:

    oc get routes -n redhat-ods-applications

    OR

    Select the redhat-ods-applications project, then NetworkingRoutes then open the URL under Location (Figure 2).

    OpenShift web console -> Networking -> Routes highlighted -> Project and Location highlighted.
    Figure 2: RHOAI dashboard.
  2. Log in to the dashboard, and select Data Science Projects. Select Create data science project (Figure 3).

    OpenShift AI web console -> Data Science Projects -> Create data science project highlighted.
    Figure 3: RHOAI Create Project.
  3. Name the project, podman-ai-lab-rag-project, and click the Create button (Figure 4).

    OpenShift AI -> Create data science project page -> Name highlighted.
    Figure 4: RHOAI Name project.
  4. We'll now create a workbench where we can upload a Jupyter notebook to ingest data into the Elasticsearch vector database. We'll then test it out by querying for some data. Select Create a workbench (Figure 5).

    OpenShift AI -> Data Science Project -> Create a workbench button highlighted.
    Figure 5: RHOAI Create a workbench button.
  • Name the workbench, elastic-vectordb-workbench. Select a Standard Data Science notebook and a Medium size (Figure 6).

    OpenShift AI workbench setup screen -> Name, Image selection, and Container size highlighted.
    Figure 6: RHOAI set up workbench.

    You'll also want to set two environment variables so we can connect to Elasticsearch from the notebook. See below:

    • CONNECTION_STRING: Copy the CLUSTER-IP and PORT from this oc command:
      • oc get service elasticsearch-sample-es-http -n elastic-vectordb
      • Add the CONNECTION_STRING key/value as a ConfigMap environment variable.
         
    • PASSWORD: Create a secret environment variable with the Elasticsearch secret value:
      • oc get secret elasticsearch-sample-es-elastic-user -n elastic-vectordb -o jsonpath="{.data['elastic']}" | base64 -d > elastic_pass.txt
      • Add the PASSWORD key/value as a Secret environment variable. The password is in the elastic_pass.txt file that was created by the above oc command (Figure 7).

        OpenShift AI workbench environment variables -> ConfigMap key/value and Secret Key/value highlighted.
        Figure 7: RHOAI environment variables.

Note: You can delete the elastic_pass.txt file that you got the password from after you add it to the environment variable.

  1. Click the Create Workbench button. Your workbench should start in a few minutes.
  2. Open your workbench after it has started and log in.

Note: If you have insufficient resources to start a medium container size then stop the workbench and change the workbench to start as a small container size.

  1. Upload or import the ./notebooks/Langchain-ElasticSearchVector-ingest.ipynb notebook to your workbench (Figure 8).

    OpenShift AI Jupyter notebook. Notebook name and Upload icon highlighted.
    Figure 8: RHOAI workbench notebook.
  2. Run the first 3 cells (Shift + Enter in each cell to run). Make sure you can connect to your Elasticsearch cluster (Figure 9).

    OpenShift AI Jupyter notebook. Verify Elasticsearch connection cell with "Connected to Elasticsearch!" highlighted.
    Figure 9: Notebook execution: first section.
  3. Continue to run through each cell while reading through what is occurring in each one. The "Create the index and ingest the documents" cell is where all of the websites and PDFs are stored with embeddings into the Elasticsearch vector database (Figure 10).

    OpenShift AI Jupyter notebook. Create the index and ingest the documents the cell displayed.
    Figure 10: Notebook execution: second section.

    This cell will take a while to run. Good time for a coffee break.

  4. After all of the data is stored in our vector database, we can directly query it. Run the last 2 cells to make sure the data was stored successfully and that we get back the results we expect (Figure 11).

    OpenShift AI Jupyter notebook. Query output of the last cell showing a score and response on enabling GPUs with OpenShift AI.
    Figure 11: Notebook execution: third section.

You now have OpenShift AI and Elasticsearch deployed. Data has been ingested into the Elasticsearch vector database and you were able to query data from the Jupyter notebook in OpenShift AI. Head over to the next lesson to deploy an LLM on OpenShift AI and update the chat recipe to connect the LLM and vector database to create an RAG chatbot!

Previous resource
High-level architecture and Podman AI Lab
Next resource
Putting the RAG chatbot together