diff --git a/ai-vector-search-apex-adb/apex-app/apex-app.md b/ai-vector-search-apex-adb/apex-app/apex-app.md index 53164bb0..3bd75a88 100644 --- a/ai-vector-search-apex-adb/apex-app/apex-app.md +++ b/ai-vector-search-apex-adb/apex-app/apex-app.md @@ -4,14 +4,15 @@ Set up the APEX application to interact with Oracle Cloud Infrastructure (OCI) data sources. This lab will walk you through the process of setting up web credentials, configuring REST data sources, and updating application definitions. +Estimated Time: 10 minutes + ## Objectives By following this guide, you will: -- Insert OCI credentials. -- Set up REST data sources to connect with OCI. -- Update application definitions and substitutions for proper configuration. - +* Insert OCI credentials. +* Set up REST data sources to connect with OCI. +* Update application definitions and substitutions for proper configuration. ### Task 1: Insert OCI Credentials in APEX @@ -21,10 +22,10 @@ By following this guide, you will: ![alt text](images/editwebcredentials.png) ![alt text](images/editociaccess.png) 3. Replace the following with the credentials saved earlier: - - **OCI User ID** - - **OCI Private Key** (remove the -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- lines) - - **OCI Tenancy ID** - - **OCI Public Key Fingerprint** + * **OCI User ID** + * **OCI Private Key** (remove the -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- lines) + * **OCI Tenancy ID** + * **OCI Public Key Fingerprint** 4. Click apply changes. ![alt text](images/editociaccessconfig.png) @@ -39,7 +40,7 @@ Here we will be doing some repetitive work but it will be pretty easy. So we wil 3. Edit each REST data source (`Bucket V3`, `list_buckets`, `list_objects_in_bucket`) as follows: ![alt text](images/editrestdatasources.png) -#### For `Bucket V3`: +#### For `Bucket V3` 1. Open the `Bucket V3` REST data source, and click the pencil icon to edit the remote server. ![alt text](images/editremoteserver.png) @@ -52,14 +53,14 @@ Here we will be doing some repetitive work but it will be pretty easy. So we wil 7. Repeat the same steps for the other two sources `list_buckets` and `list_objects_in_bucket`. 8. Save changes. -#### For `list_buckets`: +#### For `list_buckets` 1. Edit the `list_buckets` REST data source. 2. Click on the parameters section and update the `compartmentid` with your PROD compartment ID. ![alt text](images/listbucketsparameters.png) 3. Save changes. -#### For `list_objects_in_bucket`: +#### For `list_objects_in_bucket` 1. Edit the `list_objects_in_bucket` REST data source. 2. Click on the parameters section and update the `bucket_name` value to reflect the name of the bucket you created earlier. @@ -83,5 +84,6 @@ By completing these steps, you have successfully set up your APEX application, c You may now [proceed to the next lab](#next). ## Acknowledgements + * **Authors** - Blake Hendricks, Milton Wan -* **Last Updated By/Date** - July 2024 \ No newline at end of file +* **Last Updated By/Date** - July 2024 diff --git a/ai-vector-search-apex-adb/apex/apex.md b/ai-vector-search-apex-adb/apex/apex.md index da36c0bd..6b64a586 100644 --- a/ai-vector-search-apex-adb/apex/apex.md +++ b/ai-vector-search-apex-adb/apex/apex.md @@ -4,14 +4,16 @@ In this lab we will setup an Oracle APEX (Application Express) service with Oracle Autonomous Database for web application development. APEX provides a powerful and user-friendly platform to build scalable, secure, and highly functional web applications. This guide will walk you through the process of setting up an APEX service, creating a workspace, and preparing for application deployment. +Estimated Time: 10 minutes + ## Objectives By following this guide, you will: -- Set up an Oracle APEX service on your ADB instance. -- Create a new APEX workspace and schema. -- Login to your APEX instance. -- Import and configure a pre-built application in APEX. +* Set up an Oracle APEX service on your ADB instance. +* Create a new APEX workspace and schema. +* Login to your APEX instance. +* Import and configure a pre-built application in APEX. ### Task 1: Set Up Oracle APEX Service @@ -30,7 +32,6 @@ By following this guide, you will: 8. Enter your desired values for the workspace name, username, and password. Click **Create Workspace**. ![alt text](images/dbactionscredentials.png) - ### Task 2: Log In to Your APEX Instance 1. Head back to the Autonomous Database you created. @@ -39,9 +40,9 @@ By following this guide, you will: 3. Click **Launch APEX**. ![alt text](images/dbactionlaunchapex.png) 4. Enter the credentials you created with your workspace: - - **Workspace Name**: Enter your workspace name. - - **Username**: Your user you created for the workspace. - - **Password**: The password you created in the workspace for that user. + * **Workspace Name**: Enter your workspace name. + * **Username**: Your user you created for the workspace. + * **Password**: The password you created in the workspace for that user. 5. Click on **App Builder** located on the left of the dashboard. ![alt text](images/dbactionsappbuilder.png) 6. Select **Import** and upload the [SQL file](images/f100.sql) we obtained to access the pre-configured application. @@ -55,5 +56,6 @@ In this lab you created the Oracle APEX service and created a workspace. We impo You may now [proceed to the next lab](#next). ## Acknowledgements + * **Authors** - Blake Hendricks, Milton Wan * **Last Updated By/Date** - July 2024 \ No newline at end of file diff --git a/ai-vector-search-apex-adb/apex/images/databaseactions.png b/ai-vector-search-apex-adb/apex/images/databaseactions.png index 0124de46..fc4537d0 100644 Binary files a/ai-vector-search-apex-adb/apex/images/databaseactions.png and b/ai-vector-search-apex-adb/apex/images/databaseactions.png differ diff --git a/ai-vector-search-apex-adb/apex/images/dbaccessapexinstance.png b/ai-vector-search-apex-adb/apex/images/dbaccessapexinstance.png index 4ef56478..95cc6272 100644 Binary files a/ai-vector-search-apex-adb/apex/images/dbaccessapexinstance.png and b/ai-vector-search-apex-adb/apex/images/dbaccessapexinstance.png differ diff --git a/ai-vector-search-apex-adb/ask/ask.md b/ai-vector-search-apex-adb/ask/ask.md index 54f4b4c9..9457ff66 100644 --- a/ai-vector-search-apex-adb/ask/ask.md +++ b/ai-vector-search-apex-adb/ask/ask.md @@ -4,17 +4,18 @@ In this lab, we will load a document and ask a question about it. This process involves launching the application, uploading a document to object storage, selecting the document, previewing it, asking a question, displaying the results, and viewing the PL/SQL call that generates the response. There is no need to run any of the PLSQL in this lab. It will be executed by APEX. +Estimated Time: 10 minutes + ## Objectives By following this guide, you will: -- Launch the application and sign in. -- Load a document to Oracle Object Storage. -- Select and preview the document. -- Ask a question about the document. -- Display the results of the question. -- View the PL/SQL call in the APEX Page Designer. - +* Launch the application and sign in. +* Load a document to Oracle Object Storage. +* Select and preview the document. +* Ask a question about the document. +* Display the results of the question. +* View the PL/SQL call in the APEX Page Designer. ## Task 1: Launch Application @@ -23,18 +24,20 @@ By following this guide, you will: ![Run Application](images/run.png) 2. Sign into the application with your credentials. - ## Task 2: Load Document to Object Store 1. Click on the blue "Upload File" button. +![alt text](images/apex1.png) 2. Select the file you want to upload from your computer. + This will upload it to the object storage. +![alt text](images/apex2.png) Let's take a look at what PLSQL procedure is storing the document into our object storage. -Open the Apex Page Designer and select Page 12. +Open the Apex Page Designer and select Page 12. -As soon as we load our document this PLSQL procedure is called to put the document in the object storage. In this image we are using our credentials and putting our file to the object storage. +As soon as we load our document this PLSQL procedure is called to put the document in the object storage. In this image we are using our credentials and putting our file to the object storage. ![alt text](images/object.png) ``` sql @@ -65,10 +68,11 @@ END; Let's take a look at the PLSQL code for storing the file into the database table. -Click on Apex Processes Icon and select the Processes tab followed by Store in Local DB. On the right hand side you can view the window for the code. This is where the procedure stores the file to a table that you uploaded to object storage. +Click on Apex Processes Icon and select the Processes tab followed by Store in Local DB. On the right hand side you can view the window for the code. This is where the procedure stores the file to a table that you uploaded to object storage. We store the file in a table called "My_Books" within our database. As files are stored, a trigger converts the file to text, chunks the text, and creates vector embeddings for the chunks. ![alt text](images/admin.png) + ```sql INSERT INTO ADMIN.MY_BOOKS (FILE_NAME, file_type,FILE_CONTENT,FILE_SIZE) @@ -80,6 +84,7 @@ WHERE name = :P12_FILE; ## Task 3: Select Document from Drop-Down Menu 1. Select the item you just uploaded from the drop-down menu. +![alt text](images/apex3.png) 2. You can view the document you just uploaded by selecting the preview check box. @@ -88,6 +93,7 @@ WHERE name = :P12_FILE; 1. After selecting the document, you can go ahead and type a question about the document and hit return. After sending your question, you can view the results of the answer in the chat box. +![alt text](images/apex4.png) We can see the PL/SQL call in the APEX Page Designer on page 3. ![Page Designer](images/pagedesign.png) @@ -112,21 +118,24 @@ BEGIN END; ``` -### Explanation of PL/SQL code: +### Explanation of PL/SQL code DECLARE: This section is used to declare the variable result_clob, which will hold the response from the LLM. BEGIN: Marks the beginning of the executable part of the PL/SQL block. result_clob := admin.generate_text_response2(:P3_QUESTION,:P3_ID,7) calls the generate_text_response2 function. It passes three parameters: -1. :P3_QUESTION - The question entered by the user. + +1. :P3_QUESTION - The question entered by the user. 2. :P3_ID - The ID of the document selected by the user. 3. :7 - A static parameter to return the top 7 chunks. Finally assign the result of the function to the APEX page item :P3_ANSWER. If the question is null, the answer will also be null; otherwise, it assigns the result of the function call. -## Conclusion +## Summary + In this workshop we showcased an AI RAG application using Oracle APEX, Oracle Autonomous Database 23ai with AI Vector Search, and the Oracle Cloud Object Storage. These products and services are important building blocks for many AI solutions. ## Acknowledgements + * **Authors** - Blake Hendricks * **Last Updated By/Date** - July 2024 diff --git a/ai-vector-search-apex-adb/ask/images/apex1.png b/ai-vector-search-apex-adb/ask/images/apex1.png new file mode 100644 index 00000000..6efae3e1 Binary files /dev/null and b/ai-vector-search-apex-adb/ask/images/apex1.png differ diff --git a/ai-vector-search-apex-adb/ask/images/apex2.png b/ai-vector-search-apex-adb/ask/images/apex2.png new file mode 100644 index 00000000..9dc56a11 Binary files /dev/null and b/ai-vector-search-apex-adb/ask/images/apex2.png differ diff --git a/ai-vector-search-apex-adb/ask/images/apex3.png b/ai-vector-search-apex-adb/ask/images/apex3.png new file mode 100644 index 00000000..f222b907 Binary files /dev/null and b/ai-vector-search-apex-adb/ask/images/apex3.png differ diff --git a/ai-vector-search-apex-adb/ask/images/apex4.png b/ai-vector-search-apex-adb/ask/images/apex4.png new file mode 100644 index 00000000..848ee30d Binary files /dev/null and b/ai-vector-search-apex-adb/ask/images/apex4.png differ diff --git a/ai-vector-search-apex-adb/download/download.md b/ai-vector-search-apex-adb/download/download.md index 399b3875..1ebcd961 100644 --- a/ai-vector-search-apex-adb/download/download.md +++ b/ai-vector-search-apex-adb/download/download.md @@ -4,16 +4,18 @@ In this lab you will download the embedding model from Oracle Object Storage to Autonomous Database. The embedding model is used to vectorize the source data. Oracle provides data management with the Oracle Object Storage and Oracle Autonomous Database (ADB). One of the features available is the ability to download files directly from Oracle Object Storage into Oracle ADB using the DBMS\_CLOUD.GET\_OBJECTS procedure. +Estimated Time: 10 minutes + ## Objectives By following this guide, you will: -- Create a credential object in Oracle ADB for accessing Oracle Object Storage. -- Grant necessary privileges to use DBMS\_CLOUD procedures. -- Download the ONNX compliant embedding model from Oracle Object Storage into Oracle ADB using DBMS\_CLOUD.GET\_OBJECTS. -- Verify the downloaded model in Oracle ADB. -- Load the ONNX model into the database using DBMS\_VECTOR.LOAD\_ONNX\_MODEL. -- Create credential using DBMS\_VECTOR to access OCI GenAI service +* Create a credential object in Oracle ADB for accessing Oracle Object Storage. +* Grant necessary privileges to use DBMS\_CLOUD procedures. +* Download the ONNX compliant embedding model from Oracle Object Storage into Oracle ADB using DBMS\_CLOUD.GET\_OBJECTS. +* Verify the downloaded model in Oracle ADB. +* Load the ONNX model into the database using DBMS\_VECTOR.LOAD\_ONNX\_MODEL. +* Create credential using DBMS\_VECTOR to access OCI GenAI service ## Prerequisites @@ -22,11 +24,62 @@ Before we dive into the procedure, make sure you have the following: 1. **Oracle Cloud Account**: You need an active Oracle Cloud account with access to Oracle Object Storage and Oracle Autonomous Database. 2. **Object Storage Bucket**: Create a bucket in Oracle Object Storage and upload the files you want to download into Oracle ADB. 3. **Credentials**: Ensure you have the necessary credentials (access key and secret key) to access Oracle Object Storage. -4. **Oracle Autonomous Database 23ai**: Make sure you have an [Oracle Autonomous Database 23ai](https://medium.com/@bhenndricks/how-to-create-an-oracle-autonomous-database-c12d9a05096c) instance running. +4. **Oracle Autonomous Database 23ai**: Make sure you have an Oracle Autonomous Database 23ai + +## Task 1: Login to Oracle Cloud + +1. From your browser login into Oracle Cloud + +## Task 2: Provision ADW + + Provision the Autonomous Data Warehouse Databasewith the steps below. + +1. Select your assigned Region from the upper right of the OCI console. + +2. From the hamburger menu (top left side), select Autonomous Transaction Processing. +![alt text](images/createadw4.png) + +3. Select your Compartment. You may have to drill in (click “+”) to see your compartment. + +4. Select Workload Type Data Warehouse. + +5. Click Create Autonomous Database. + ![alt text](images/createadw1.png) + +6. Choose your compartment. + +7. Enter any unique name (maybe your name) for your display and database name. + The display name is used in the Console UI to identify your database. + ![alt text](images/createadw2.png) + +8. Ensure Warehouse workload type is selected. + +9. Select **Serverless** for deployment type. + +10. Choose database version 23ai. + +11. Configure the database with **2 cores and 1 TB storage**. + +12. Check Auto scaling. -## Task 1: Create Credential Object in Oracle ADB +13. Enter a password. The username is always ADMIN. (Note: remember your password) -1. First, create a credential object in your Oracle Autonomous Database that will store your Object Storage credentials. This is required for authenticating with Oracle Object Storage. +14. Select Allow secure access from everywhere for this workshop. + As a best practice when you deploy your own application, you should select network access to be from Virtual cloud network. + ![alt text](images/createadw3.png) + +15. Select BYOL license type. + +16. Click Create Autonomous Database. + ![](./images/provision-atp-7.png) + + Your console will show that ATP is provisioning. This will take about 2 or 3 minutes to complete. + + You can check the status of the provisioning in the Work Request. + +## Task 3: Create Credential Object in Oracle ADB + +1. First, create a credential object in your Oracle Autonomous Database that will store your Object Storage credentials. This is required for authenticating with Oracle Object Storage. Next head back to your ADB console, and select Database Actions and then SQL. Log in as ADMIN. This will open up an editor for us to perform statements. ![alt text](images/sqldev.png) @@ -46,7 +99,7 @@ END; ``` -## Task 2: Grant Necessary Privileges +## Task 4: Grant Necessary Privileges From ADMIN user, run the following to ensure your database user has the necessary privileges to use DBMS packages. We are using the user VECTOR when creating the schema objects. If you use a different user, be sure to use the correct schema user during table creation in the subsequent lab. @@ -60,16 +113,20 @@ GRANT EXECUTE ON DBMS_CLOUD TO VECTOR; GRANT EXECUTE ON DBMS_VECTOR TO VECTOR; GRANT EXECUTE ON DBMS_VECTOR_CHAIN TO VECTOR; GRANT CREATE ANY DIRECTORY TO VECTOR; +GRANT EXECUTE ON DBMS_CLOUD_AI TO VECTOR; ``` -## Task 3: Option 1 - Create the credential for ADB to access OCI GenAI Service +## Task 5: Option 1 - Create the credential for ADB to access OCI GenAI Service ### OCI GenAI Service + The OCI GenAI service provides access to several LLMs including Cohere and Llama. -API authentication is required. +API authentication is required. + +1. From ADB Database Actions SQL Worksheet or SQL Developer, login as VECTOR user and copy and run the SQL below and replace the following with your ocid and key information you got from the previous lab. -1. From ADB Database Actions SQL Worksheet, as ADMIN user enter and run the SQL below and replace the following with your ocid and key information you got from the previous lab. Important Note: Open your private key and copy the private key all onto a single line. +Important Note: Open your private key and copy the private key all onto a single line. ```sql @@ -89,7 +146,9 @@ end; / ``` + For example: + ``` declare jo json_object_t; @@ -107,11 +166,12 @@ end; / ``` -## Task 3: Option 2 - Create the credential for ADB to access OpenAI +## Task 6: Option 2 - Create the credential for ADB to access OpenAI ### OpenAI For OpenAI, run the following procedure: + ```sql @@ -128,9 +188,9 @@ end; ``` -## Task 4: Download ONNX embedding models Using DBMS\_CLOUD.GET\_OBJECTS +## Task 7: Download ONNX embedding models Using `DBMS\_CLOUD.GET\_OBJECTS` -Now log in as VECTOR or ``, use the DBMS\_CLOUD.GET\_OBJECTS procedure to download the ONNX embedding model files from the Oracle Object Storage bucket into Oracle ADB. You will download two different models. +Now log in as VECTOR or ``, use the `DBMS\_CLOUD.GET\_OBJECTS` procedure to download the ONNX embedding model files from the Oracle Object Storage bucket into Oracle ADB. You will download two different models. Run to create the staging directory. @@ -157,12 +217,10 @@ END; ``` URL to all-MiniLM-L6-v2.onnx is: -https://oraclepartnersas.objectstorage.us-ashburn-1.oci.customer-oci.com/p/CjS1gGPZaCZE2PoRWS5c6xmGNXK0v6ny6tNwoiVIOvqQrHux9NJ5oYo0dgLc6gOG/n/oraclepartnersas/b/onnx/o/all-MiniLM-L6-v2.onnx - + URL to tinybert.onnx is: -https://oraclepartnersas.objectstorage.us-ashburn-1.oci.customer-oci.com/p/m5o31C0ol_8B_OzCLOLvqc2rWYNqz0M7kZZpMZHEaOyX7GQkhEw8_UNKoKBtcQYC/n/oraclepartnersas/b/onnx/o/tinybert.onnx - + For example, to get tinybert.onnx and download it to ADB, the command will look like this: @@ -180,7 +238,7 @@ END; ``` -## Task 5: Verify the File in Oracle ADB +## Task 8: Verify the File in Oracle ADB After downloading the file, you can verify its existence in Oracle ADB by listing the contents of the directory. @@ -192,7 +250,7 @@ SELECT * FROM TABLE(DBMS_CLOUD.LIST_FILES('staging')); This query will show you the files present in the specified directory, ensuring that your file has been successfully downloaded. -## Task 6 Load the ONNX Files into the Database +## Task 9: Load the ONNX Files into the Database Once the ONNX files are downloaded and verified, you can load them into the database using DBMS\_VECTOR.LOAD\_ONNX\_MODEL. This step involves loading the models from the downloaded files and configuring them for use in Oracle ADB. @@ -216,6 +274,7 @@ END; / ``` + This code loads two ONNX models (tinybert.onnx and all-MiniLM-L6-v2.onnx) into the Oracle ADB, making them available as TINYBERT\_MODEL and ALL\_MINILM\_L6V2MODEL respectively. The json configuration specifies how the models should handle input and output data. By just changing the model from tinybert\_model to All\_MINILM\_L6V2MODEL, you will have different vectors for the same document. Each of the models are designed to search the vectors and get the best match according to their algorithms. Tinybert has 128 dimensions while all-MiniL2-v2 has 384 dimensions. Usually, the greater the number of dimensions, the higher the quality of the vector embeddings. A larger number of vector dimensions also tends to result in slower performance. You should choose an embedding model based on quality first and then consider the size and performance of the vector embedding model. You may choose to use larger vectors for use cases where accuracy is paramount and smaller vectors where performance is the most important factor. @@ -229,13 +288,13 @@ To verify the model exists in database run the following statement. ``` -## Conclusion +## Summary -In this lab we granted privileges to your database user to run the needed PLSQL procedures and functions. We created objects to authenticate to LLM services. We also downloaded embedding models from Oracle Object Storage using DBMS\_CLOUD.GET\_OBJECTS and loaded them into Oracle Autonomous Database with DBMS\_VECTOR.LOAD\_ONNX\_MODEL. +In this lab we granted privileges to your database user to run the needed PLSQL procedures and functions. We created objects to authenticate to LLM services. We also downloaded embedding models from Oracle Object Storage using DBMS\_CLOUD.GET\_OBJECTS and loaded them into Oracle Autonomous Database with DBMS\_VECTOR.LOAD\_ONNX\_MODEL. You may now [proceed to the next lab](#next). - ## Acknowledgements + * **Authors** - Blake Hendricks, Vijay Balebail, Milton Wan * **Last Updated By/Date** - July 2024 diff --git a/ai-vector-search-apex-adb/download/images/atp-diagram.png b/ai-vector-search-apex-adb/download/images/atp-diagram.png new file mode 100644 index 00000000..1f168661 Binary files /dev/null and b/ai-vector-search-apex-adb/download/images/atp-diagram.png differ diff --git a/ai-vector-search-apex-adb/download/images/createadw1.png b/ai-vector-search-apex-adb/download/images/createadw1.png new file mode 100644 index 00000000..3ec4af3f Binary files /dev/null and b/ai-vector-search-apex-adb/download/images/createadw1.png differ diff --git a/ai-vector-search-apex-adb/download/images/createadw2.png b/ai-vector-search-apex-adb/download/images/createadw2.png new file mode 100644 index 00000000..6a760999 Binary files /dev/null and b/ai-vector-search-apex-adb/download/images/createadw2.png differ diff --git a/ai-vector-search-apex-adb/download/images/createadw3.png b/ai-vector-search-apex-adb/download/images/createadw3.png new file mode 100644 index 00000000..a8787aea Binary files /dev/null and b/ai-vector-search-apex-adb/download/images/createadw3.png differ diff --git a/ai-vector-search-apex-adb/download/images/createadw4.png b/ai-vector-search-apex-adb/download/images/createadw4.png new file mode 100644 index 00000000..29a7d053 Binary files /dev/null and b/ai-vector-search-apex-adb/download/images/createadw4.png differ diff --git a/ai-vector-search-apex-adb/download/images/image.png b/ai-vector-search-apex-adb/download/images/image.png new file mode 100644 index 00000000..c4b73fe8 Binary files /dev/null and b/ai-vector-search-apex-adb/download/images/image.png differ diff --git a/ai-vector-search-apex-adb/download/images/open-terminal.png b/ai-vector-search-apex-adb/download/images/open-terminal.png deleted file mode 100644 index 725b4664..00000000 Binary files a/ai-vector-search-apex-adb/download/images/open-terminal.png and /dev/null differ diff --git a/ai-vector-search-apex-adb/introduction/introduction.md b/ai-vector-search-apex-adb/introduction/introduction.md index 26b576ae..1ee16ae8 100644 --- a/ai-vector-search-apex-adb/introduction/introduction.md +++ b/ai-vector-search-apex-adb/introduction/introduction.md @@ -1,12 +1,15 @@ # Introduction -## Lab Overview +## About this Workshop The scope of this workshop is to create a Generative AI RAG application using Oracle APEX with AI Vector Search in Oracle Autonomous Database. The workshop uses Oracle Object Storage as the knowledge base repository to store documents. Customers can use the Oracle Object Storage to securely store confidential business information. +Estimated Time: 60 minutes + ## Objectives By the end of this lab, users will be able to: + * Set up APEX to access the Oracle Object Storage * Set up Autonomous Database to access the Oracle Object Storage for importing the embedding model * Import and configure APEX and run the RAG sample application @@ -16,12 +19,11 @@ By the end of this lab, users will be able to: ### Prerequisites -- An Oracle LiveLabs Account -- An Oracle Cloud Account +* An Oracle Cloud Account ## Application Description -The APEX application developed in this workshop is a Retrieval Augmented Generation (RAG) app utilizing the ONNX framework and AI Vector capabilities in Oracle Autonomous Database 23ai. This app enables the secure storage of documents in Oracle Object Storage, where they can be vectorized in Autonomous Database and used for the RAG application. Users can ask questions about any uploaded document, facilitating secure data insight and responses on customer documents stored in the Oracle Object Storage. +In this Oracle Live Labs workshop, participants will develop an advanced APEX application that integrates the Retrieval Augmented Generation (RAG) model with Oracle's cutting-edge AI and database technologies. Utilizing the ONNX framework and AI Vector capabilities within Oracle Autonomous Database 23AI, this application revolutionizes document management by enabling secure storage, vectorization, and advanced querying of documents stored in Oracle Cloud Object Storage. Users will interact with the application to ask complex questions, receiving precise, context-aware responses based on the vectorized contents of the documents they want to interact with. This workshop provides a deep dive into Oracle’s AI-driven capabilities, equipping participants with the skills to build next-generation applications that merge AI with enterprise data management for enhanced efficiency, security, and insight. ![alt text](images/ai-vector-search-apex-adb.png) @@ -33,9 +35,9 @@ The APEX application developed in this workshop is a Retrieval Augmented Generat ## Benefits -- **AI Vector Management**: Streamlined process for storing, vectorizing, and querying documents. -- **Increased Efficiency**: Faster data retrieval and insights without manual intervention. -- **Secure Storage**: Documents are stored securely within Oracle's robust cloud infrastructure. +* **AI Vector Management**: Streamlined process for storing, vectorizing, and querying documents. +* **Increased Efficiency**: Faster data retrieval and insights without manual intervention. +* **Secure Storage**: Documents are stored securely within Oracle's robust cloud infrastructure. This lab provides a hands-on experience with Oracle's cutting-edge cloud technologies, enabling users to easily build and deploy advanced AI data-driven applications. @@ -50,5 +52,6 @@ See below for more information on Oracle Database 23ai and Oracle AI Vector Sear You may now [proceed to the next lab](#next). ## Acknowledgements + * **Authors** - Blake Hendricks, Vijay Balebail, Milton Wan -* **Last Updated By/Date** - July 2024 \ No newline at end of file +* **Last Updated By/Date** - July 2024 diff --git a/ai-vector-search-apex-adb/setup/images/15-identity-compartments.png b/ai-vector-search-apex-adb/setup/images/15-identity-compartments.png new file mode 100644 index 00000000..cc7928cc Binary files /dev/null and b/ai-vector-search-apex-adb/setup/images/15-identity-compartments.png differ diff --git a/ai-vector-search-apex-adb/setup/images/16-create-compartment.png b/ai-vector-search-apex-adb/setup/images/16-create-compartment.png new file mode 100644 index 00000000..9742efff Binary files /dev/null and b/ai-vector-search-apex-adb/setup/images/16-create-compartment.png differ diff --git a/ai-vector-search-apex-adb/setup/images/17-create-compartment2.png b/ai-vector-search-apex-adb/setup/images/17-create-compartment2.png new file mode 100644 index 00000000..601da8c7 Binary files /dev/null and b/ai-vector-search-apex-adb/setup/images/17-create-compartment2.png differ diff --git a/ai-vector-search-apex-adb/setup/images/compartmentsave.png b/ai-vector-search-apex-adb/setup/images/compartmentsave.png index 48910970..b016c86a 100644 Binary files a/ai-vector-search-apex-adb/setup/images/compartmentsave.png and b/ai-vector-search-apex-adb/setup/images/compartmentsave.png differ diff --git a/ai-vector-search-apex-adb/setup/images/copytenancyid.png b/ai-vector-search-apex-adb/setup/images/copytenancyid.png index bb49e649..0b1da7f0 100644 Binary files a/ai-vector-search-apex-adb/setup/images/copytenancyid.png and b/ai-vector-search-apex-adb/setup/images/copytenancyid.png differ diff --git a/ai-vector-search-apex-adb/setup/images/createbucket.png b/ai-vector-search-apex-adb/setup/images/createbucket.png index a5ac2ac6..d5ae87c3 100644 Binary files a/ai-vector-search-apex-adb/setup/images/createbucket.png and b/ai-vector-search-apex-adb/setup/images/createbucket.png differ diff --git a/ai-vector-search-apex-adb/setup/images/createpolicy.png b/ai-vector-search-apex-adb/setup/images/createpolicy.png index 8fcc9096..eec7953e 100644 Binary files a/ai-vector-search-apex-adb/setup/images/createpolicy.png and b/ai-vector-search-apex-adb/setup/images/createpolicy.png differ diff --git a/ai-vector-search-apex-adb/setup/images/setup-dev-environment.md b/ai-vector-search-apex-adb/setup/images/setup-dev-environment.md new file mode 100644 index 00000000..bdb42f98 --- /dev/null +++ b/ai-vector-search-apex-adb/setup/images/setup-dev-environment.md @@ -0,0 +1,432 @@ +# Setup Dev Environment + +## Introduction + +In this lab, you will configure your development environment and collect information that will be used later throughout this workshop. + +Estimated Time: ~25 minutes + +### Objectives + +* Launch Cloud Shell +* Download the workshop code and scripts from GitHub +* Set up an OCI Compartment and install a two nodes OKE cluster +* Create the ATP database, the user schema and a database table +* Create an OCI Registry and Auth key +* Access OKE from the Cloud Shell + +### Prerequisites + +- This lab requires an [Oracle Cloud account](https://www.oracle.com/cloud/free/). You may use your own cloud account, a cloud account that you obtained through a trial, a Free Tier account, or a LiveLabs account. + +## Task 1: Launch the Cloud Shell and Clone mtdrworkshop GitHub repository + +1. Launch Cloud Shell + + The Cloud Shell is a small virtual machine running a Bash shell which you access through the OCI Console. It comes with a pre-authenticate CLI pre-installed and configured so you can immediately start working in your tenancy without having to spend time on installation and configuration! + + Click the Cloud Shell icon in the top-right corner of the Console. + ![](images/7-open-cloud-shell.png " ") + +2. Clone the GitHub repo and move up the `mtdrworkshop` directory. + + ``` + + git clone https://github.com/vijaybalebail/OKE_setup.git + + ``` + + ``` + + cd ~/OKE_setup; mv mtdrworkshop .. + + ``` + + You should now see `mtdrworkshop` in your root directory + +3. Change to `mtdrworkshop` directory. + + ``` + + cd ~/mtdrworkshop + + ``` + +4. Set the execution mode for all Shell scripts. + + ``` + chmod +x *.sh */*.sh + ``` + + > **NOTE:** THE CLOUD SHELL WILL DISCONNECT AFTER A CERTAIN PERIOD OF INACTIVITY. IF YOU ARE DISCONNECTED OR LOGGED OFF AND RETURN TO CLOUD SHELL, MAKE SURE YOU ARE IN THE ~/mtdrworkshop DIRECTORY. + +## Task 2: Create an OCI compartment and an OKE cluster in that compartment + + 1. Open up the hamburger menu in the top-left corner of the Console and select **Identity & Security > Compartments**. + + ![](images/15-identity-compartments.png " ") + + 2. Click **Create Compartment** with the following parameters then click **Create Compartment**: + + - Compartment name: `mtdrworkshop` + - Description: `My ToDo React workshop compartment` + + ![](./images/16-create-compartment.png " ") + + ![](images/17-create-compartment2.png " ") + + 3. Once the compartment is created, click the name of the compartment and then click **Copy** to copy the OCID. + + ![](images/19-compartment-name-ocid.png " ") + + ![](images/20-compartment-ocid.png " ") + + 4. Go back into your cloud shell and verify you are in the `~/mtdrworkshop` directory. + + 5. Run `./setCompartmentId.sh ` where your `` and `` values are set as arguments. + + To find your region id, check cloud web url in the browser & look for string "region=xx-xxxx-xx". + + For example: + ``` + `./setCompartmentId.sh ocid1.compartment.oc1..aaaaaaaaxbvaatfz6yourcomparmentidhere5dnzgcbivfwvsho77myfnqq us-ashburn-1` + ``` + This will set the environment variables that will allow other scripts to pick the information. + + 6. To create an OKE cluster, return to the OCI console and open up the hamburger button in the top-left corner of the Console and go to **Developer Services > Kubernetes Clusters**. + + ![](images/27-dev-services-oke.png " ") + + 7. Make sure you are in the newly created compartment and click **Create Cluster**. + (Please use the default schema in the unlikely situation that the newly created compartment is not quickly visible on the left pickler) + ![](images/28-create-oke.png " ") + + 8. Choose **Quick Create** as it will create the new cluster along with the new network resources such as Virtual Cloud Network (VCN), Internet Gateway (IG), NAT Gateway (NAT), Regional Subnet for worker nodes, and a Regional Subnet for load balancers. Click **Launch Workflow**. + + ![](images/29-create-oke-wizard.png " ") + + 9. Change the name of the cluster to `mtdrworkshopcluster`, accept all the other defaults, and click **Next** to review the cluster settings. + + + 10. Once reviewed click **Create Cluster**, and you will see the resource creation progress. + + ![](images/31-create-oke-wizard3.png " ") + + 11. Close the creation window once you can. + + ![](images/32-close-cluster-create.png " ") + + 12. Once launched it should usually take around 5-10 minutes for the cluster to be fully provisioned and the Cluster Status should show Active. + + ![](images/33-click-cluster-name.png " ") + + ![](images/34-copy-cluster-id.png " ") + + There is no need to wait for the cluster to be fully provisioned at this point as we will verify cluster creation and create a kube config in order to access it in a later step. + + +## Task 3: Create the ATP database + +1. Open up the hamburger menu in the top-left corner of the Console and select **Oracle Databse > Autonomous Transaction Processing**. + + ![](images/menu-autonomous.png " ") + +2. Click on **Create Autonomous Database**. + + ![](images/create-autonomous.png " ") + +3. Set **Compartment, Database Name and Display Name**. + + - Set the workload type to "Transaction Processing". + - Accept the default Deployment Type "Shared Infrastructure". + + ![](images/ATP-config-1.png " ") + +4. Set **ADMIN password, Network Access Type and License Type** + + - Set the database ADMIN password (12 to 30 characters, at least one uppercase letter, one lowercase letter, and one number) and confirm. + Please note the ADMIN password; it will be required later. + - Set the Network Access type to "Allow secure access from specific IPs an VCNs". + - Set the license type to "Bring Your Own License (BYOL)" (does not matter for this workshop) + - Click on "Create Autonomous Database" + + ![](images/ADB-setup.png " ") + + The database creation will take a few minutes. + +5. Populate mtdrworkshopdbid.txt with the database OCID + + - Create the "~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt" file. + + ``` + touch ~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt + ``` + + ![](images/42-copy-atp-ocids2.png " ") + + - Copy the OCID of the newly created database from the Cloud console and + add it into `~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt` file. + + + + ``` + For example + echo ocid1.autonomousdatabase.oc1.xxx.xxxx > ~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt + ``` + + +6. Generate the Wallet for your ATP Connectivity + + - Still in Cloud Shell, make sure you are in the + "~/mtdrworkshop/setup-dev-environment" directory. + + - Copy the following command and replace $OCID by the + copied OCID. + + ``` + + cd ~/mtdrworkshop/setup-dev-environment + OCID=$( cat ~/mtdrworkshop/workingdir/mtdrworkshopdbid.txt ) + ./generateWallet.sh $OCID + + ``` + - Execute generateWallet.sh ocid1.autonomousdatabase.oc1.phx.abyhqlj.... + + You will be requested to enter a password for wallet encryption, this is separate for the ADMIN password but you could reuse the statement. + A wallet.zip file will be created in the current directory. + + + +7. Create TODOUSER using sql utility in Cloud shell + + - Stay in mtdrwokshop/setup-dev-environment directory and launch + sql with /nolog option + + ![](images/SQLCl-Cloud-Shell.png " ") + + - Point the tool at your wallet.zip file + SQL> set cloudconfig wallet.zip + + SQL> show tns + ![](images/Show-tns.png " ") + + - Connect to mtdrdb_tp service, as database ADMIN user (remember the + password given to ADMIN above) + + SQL> connect ADMIN@mtdrdb_tp + + - Create TODOUSER (replace by a strong password). + + ``` + CREATE USER todouser IDENTIFIED BY DEFAULT TABLESPACE data QUOTA UNLIMITED ON data; + ``` + - Grant some privileges to TODOUSER by executing the following command + + ``` + grant create session, create view, create sequence, create procedure, create table, create trigger, create type, create materialized view to todouser; + ``` + + - Verify you can connect as TODOUSER with the password you provided. + ``` + SQL> connect todouser@mtdrdb_tp + ``` + + + +## Task 4: Create an OCI Registry and Auth key + +You are now going to create an Oracle Cloud Infrastructure Registry and an Auth key. The Oracle Cloud Infrastructure Registry is an Oracle-managed registry that enables you to simplify your development-to-production workflow by storing, sharing, and managing development artifacts such as Docker images. + +1. Open up the hamburger menu in the top-left corner of the console and go to **Developer Services > Container Registry**. + + ![](images/21-dev-services-registry.png " ") + +2. Take note of the namespace (for example, `axkcsk2aiatb` shown in the image below). + + ![](images/22-create-repo.png " ") + +3. Click **Create Repository** , specify the following details for your new repository, and click **Create Repository**. + - Repository Name: /mtdrworkshop + - Access: Public + +4. Go to Cloud Shell and run `./addOCIRInfo.sh` with the namespace and repository name as arguments + + ``` + ./addOCIRInfo.sh + ``` + For example `./addOCIRInfo.sh axkcsk2aiatb mtdrworkshop.user1/mtdrworkshop` + +5. You will now create the Auth token by going back to the User Settings page. Click the Profile icon in the top-right corner of the Console and select **User Settings**. + + ![](images/23-user-settings.png " ") + +6. Click on **Auth Tokens** and select **Generate Token**. + + ![](images/24-gen-auth-token.png " ") + +7. In the description type `mtdrworkshoptoken` and click **Generate Token**. + + ![](images/25-gen-auth-token2.png " ") + +8. Copy the token value. + + ![](images/26-save-auth-token.png " ") + +9. Go to Cloud Shell, at the workshop root directory and run the dockerLogin.sh scripts + ``` + . ./dockerLogin.sh USERNAME AUTH_TOKEN + ``` + + - is the username used to log in (typically your email address). If your username is federated from Oracle Identity Cloud Service, you need to add the oracleidentitycloudservice/ prefix to your username. + + Example oracleidentitycloudservice/firstname.lastname@something.com + Note: Please run the script with . ./dockerLogin.sh. This will help to export the username and AUTH token which is useful in the next step. + + "" - paste the generated token value and enclose the value in quotes. + + + ``` + For example + . ./dockerLogin.sh user.foo@bar.com "8nO[BKNU5iwasdf2xeefU;yl" + ``` + + Once successfully logged into Container Docker Registry, you should see the "Login Succeeded" in the cloud shell. + + We can list the existing docker images. Since this is the first time logging into Registry, no images will be shown. + + ``` + docker images + ``` + +## Task 5: Access OKE from the Cloud Shell + + 1. Create the mtdrworkshop/workingdir/mtdrworkshopclusterid.txt file + + ``` + touch ~/mtdrworkshop/workingdir/mtdrworkshopclusterid.txt + ``` + + 2. Navigate to **Developer Services > Kubernetes Clusters** + + 3. Copy the mdtrworkshopcluster id and paste into the newly created file + ![](images/mtdrworkshop-cluster-id.png " ") + + ``` + For example + echo ocid1.cluster.oc1.yyy.xxxxx > ~/mtdrworkshop/workingdir/mtdrworkshopclusterid.txt + ``` + + 4. Run `./verifyOKEAndCreateKubeConfig.sh` + + ``` + ./verifyOKEAndCreateKubeConfig.sh + ``` + + Notice `/.kube/config` is created for the OKE cluster. + + ![](images/verifyOKEOutput.png " ") + + +## Task 6: Create a imagePullSecret for the Tutorial + + To enable Kubernetes to pull an image from Oracle Cloud Infrastructure Registry when deploying an application, you need to create a Kubernetes secret. The secret includes all the login details you would provide if you were manually logging in to Oracle Cloud Infrastructure Registry using the docker login command, including your auth token. + + ``` + + echo MTDRWORKSHOP_OCIR_NAMESPACE = $MTDRWORKSHOP_OCIR_NAMESPACE + echo MTDRWORKSHOP_REGION = $MTDRWORKSHOP_REGION + echo MTDRWORKSHOP_OCIR_USER = $MTDRWORKSHOP_OCIR_USER + echo MTDRWORKSHOP_OCIR_AUTHKEY = $MTDRWORKSHOP_OCIR_AUTHKEY + + kubectl create secret docker-registry todolistpullsecret3 --docker-server=$MTDRWORKSHOP_REGION --docker-username='$MTDRWORKSHOP_OCIR_NAMESPACE/$MTDRWORKSHOP_OCIR_USER' --docker-password=$MTDRWORKSHOP_OCIR_AUTHKEY + + ``` + + + +## Task 7: Access OKE from the Cloud Shell + +1. Create the mtdrworkshop/workingdir/mtdrworkshopclusterid.txt file + + ``` + touch ~/mtdrworkshop/workingdir/mtdrworkshopclusterid.txt + ``` + +2. Navigate to **Developer Services > Kubernetes Clusters** + +3. Copy the mdtrworkshopcluster id and paste into the newly created file + ![](images/mtdrworkshop-cluster-id.png " ") + + ``` + For example + echo ocid1.cluster.oc1.yyy.xxxxx > ~/mtdrworkshop/workingdir/mtdrworkshopclusterid.txt + ``` + +4. Run `./verifyOKEAndCreateKubeConfig.sh` + + ``` + ./verifyOKEAndCreateKubeConfig.sh + ``` + + Notice `/.kube/config` is created for the OKE cluster. + + ![](images/verifyOKEOutput.png " ") + +## Task 8: Configuring Network Security Rules + +1. The network security rules control the inbound (Ingres) and the outbound (Egress) traffic. As we will be configuring the API Gateway in Part II, we will not set tight security rules at the Kubernetes cluster level. +2. Navigate to **Developer Services > Kubernetes Clusters** + - Click on the **mtdrworkshopcluster** + +3. Click on VCN Name + ![](images/VCN-name.png " ") +4. Click on the VCN named starting with oke-svclbsubnet-quick-mtdrworkshpcluster + ![](images/oke-svclbsubnet.png " ") + +5. Click on the existing security list + ![](images/Add-security-lists.png " ") + +6. Add an Ingress Rule + Set the Destination CIDR as indicated (leave other fields as is) then Click `Add Ingress Rules` + ![](images/Ingress-rule.png " ") + +7. Click on Egress Rules and add an Egress Rule + Set Stateless and Destination CIDR as indicated in the image (leave other fields as-is) then Click `Add Egress Rules` + ![](images/Egress-rule.png " ") + + Note: Skipping this step will have issues while testing API gateways. + +Congratulations, you have completed lab 1; you may now proceed to the next lab. + +## Acknowledgements + +* **Author** - - Vijay Balebail, Director Product Management. +* **Contributors** - Satyabrata Mishra, Rajeev Rumale +* **Last Updated By/Date** - Kamryn Vinson, November 2021 diff --git a/ai-vector-search-apex-adb/setup/setup.md b/ai-vector-search-apex-adb/setup/setup.md index a03d1b26..58452e52 100644 --- a/ai-vector-search-apex-adb/setup/setup.md +++ b/ai-vector-search-apex-adb/setup/setup.md @@ -6,51 +6,58 @@ Welcome to Lab 1. This workshop demonstrates how to set up Oracle Cloud Infrastr In the Identity Setup section, you will learn how to create compartments, manage policies, and set up users with the necessary permissions to interact with OCI resources. Following this, the Bucket Setup section will walk you through the process of creating and configuring a storage bucket, essential for managing data and objects in your cloud environment. -**Estimated Time:** 10 minutes +Estimated Time: 10 minutes ## Objectives By completing this lab, you will achieve the following objectives: -- **Create and configure a new compartment** for managing resources in OCI. - - This involves setting up a logical grouping for your resources to enhance management and organization. +* **Create and configure a new compartment** for managing resources in OCI. + * This involves setting up a logical grouping for your resources to enhance management and organization. -- **Establish policies** to control access and permissions within the compartment. - - You will define and implement policies to manage who can access and perform actions on your OCI resources. +* **Establish policies** to control access and permissions within the compartment. + * You will define and implement policies to manage who can access and perform actions on your OCI resources. -- **Set up a user specifically for API key management and interaction.** - - This step ensures that there is a dedicated user with appropriate permissions for managing and using API keys securely. +* **Set up a user specifically for API key management and interaction.** + * This step ensures that there is a dedicated user with appropriate permissions for managing and using API keys securely. -- **Configure API keys for secure access and operations.** - - You will generate and set up API keys to enable secure programmatic access to your OCI resources. +* **Configure API keys for secure access and operations.** + * You will generate and set up API keys to enable secure programmatic access to your OCI resources. -- **Obtain necessary OCIDs** for compartments, users, and tenancies. - - OCIDs (Oracle Cloud Identifiers) are essential for uniquely identifying your resources in OCI. +* **Obtain necessary OCIDs** for compartments, users, and tenancies. + * OCIDs (Oracle Cloud Identifiers) are essential for uniquely identifying your resources in OCI. -- **Create and configure a storage bucket in OCI.** - - This section guides you through setting up a storage bucket, a crucial component for storing and managing data in your cloud environment. +* **Create and configure a storage bucket in OCI.** + * This section guides you through setting up a storage bucket, a crucial component for storing and managing data in your cloud environment. -- **Generate a Pre-Authenticated Request (PAR) for secure bucket access.** - - You will create a PAR to enable secure and temporary access to your storage bucket without requiring further authentication. +* **Generate a Pre-Authenticated Request (PAR) for secure bucket access.** + * You will create a PAR to enable secure and temporary access to your storage bucket without requiring further authentication. ### Task 1: Create an OCI Compartment 1. Click the hamburger icon (≡) at the top left corner of the page. + 2. Click Identity & Security. Hover over Identity and click the Compartment submenu item. +![alt text](images/15-identity-compartments.png) + 3. Click Create Compartment. +![alt text](images/16-create-compartment.png) + 4. Enter the following information in the corresponding fields or use your own names: - - **Name**: PROD - - **Description**: Compartment for PROD assets + * **Name**: PROD + * **Description**: Compartment for PROD assets + ![alt text](images/17-create-compartment2.png) + 5. Click Create to complete the process. 6. Save the compartment OCID for later use. ![compartment save](/images/compartmentsave.png) -The members of the ProdObjectManagers group will require the ability to list the buckets in the compartment and manage any objects in these buckets. + The members of the ProdObjectManagers group will require the ability to list the buckets in the compartment and manage any objects in these buckets. -9. Add the following statements to allow the respective policy actions: - - Allow group ProdObjectManagers to read buckets in compartment PROD - - Allow group ProdObjectManagers to manage objects in compartment PROD -10. Click Create to complete the process. +7. Add the following statements to allow the respective policy actions: + * Allow group ProdObjectManagers to read buckets in compartment PROD + * Allow group ProdObjectManagers to manage objects in compartment PROD +8. Click Create to complete the process. ![Policies](/images/policyconfiguration.png) ### Task 2: Create policy to enable access to OCI GenAI @@ -72,11 +79,11 @@ Description: Public Gen AI Policy Compartment: select your own compartment -``` - -Policy: allow user to manage generative-ai-family in compartment \ - -``` + ``` + + Policy: allow user to manage generative-ai-family in compartment \ + + ``` 3. Click Create. @@ -84,7 +91,7 @@ Policy: allow user to manage generative-ai-family in compartment \ CREATE TABLE IF NOT EXISTS "VECTOR"."MY_BOOKS" ( @@ -41,10 +43,10 @@ In this lab, you will: 4. Create a table named *VECTOR\_STORE* in the VECTOR schema. This is used to store the corresponding text chunks and embeddings in a column of vector datatype. Copy the code snippet and click **Run**. - ``` + ``` CREATE TABLE IF NOT EXISTS VECTOR.VECTOR_STORE - ( "DOC_ID" NUMBER(*,0) NOT NULL ENABLE, + ( "DOC_ID" NUMBER(*,0) NOT NULL ENABLE, "EMBED_ID" NUMBER, "EMBED_DATA" VARCHAR2(4000 BYTE), "EMBED_VECTOR" VECTOR, @@ -53,7 +55,7 @@ In this lab, you will: ``` -## Task 2: Create database procedure and trigger +## Task 2: Create database procedure and trigger In this task you will: @@ -61,7 +63,7 @@ Create a procedure `insert_my_table_row` to insert the PDF, Word, or TXT file in Create a trigger `trg_mybooks_vector_store_compound` to create embedding for the PDF and store it in the VECTOR\_STORE table. -1. From the Database Actions SQL Worksheet create and run the procedure `insert_my_table_row` +1. From the Database Actions SQL Worksheet create and run the procedure `insert_my_table_row` ``` @@ -98,7 +100,7 @@ Create a trigger `trg_mybooks_vector_store_compound` to create embedding for the ``` -2. Create the trigger `trg_mybooks_vector_store_compound` +2. Create the trigger `trg_mybooks_vector_store_compound` ``` @@ -153,13 +155,14 @@ Create a trigger `trg_mybooks_vector_store_compound` to create embedding for the The LLM involves processing both the user question and relevant text excerpts to generate responses tailored specifically to the provided context. It's essential to note that the nature of the response is contingent upon the question and the LLM utilized. -LLM prompt engineering enables you to craft input queries or instructions to create more accurate and desirable outputs. The PLSQL uses a SQL CURSOR and CLOBs to generate the LLM prompt based on facts from the similarity search from Oracle Database 23ai. +LLM prompt engineering enables you to craft input queries or instructions to create more accurate and desirable outputs. The PLSQL uses a SQL CURSOR and CLOBs to generate the LLM prompt based on facts from the similarity search from Oracle Database 23ai. -In the code below we are embedding the user question, performing a vector search in the database for the relevant text chunks using a vector distance function. We pass the doc\_id to select the chunks related to a PDF document we loaded. This improves the accuracy of the LLM response for the question by restricting the result within the content of PDF. We then send the text chunks to LLM to provide the response. +In the code below we are embedding the user question, performing a vector search in the database for the relevant text chunks using a vector distance function. We pass the doc\_id to select the chunks related to a PDF document we loaded. This improves the accuracy of the LLM response for the question by restricting the result within the content of PDF. We then send the text chunks to LLM to provide the response. Compile the function `generate_text_response2` below. It is called from APEX. ### OpenAI + For connecting and authenticating to OpenAI you must have created the login credentials with an OpenAI API key using DBMS\_VECTOR.CREATE\_CREDENTIAL in the previous lab. Note: If you receive an HTTP response error ensure you have enough credits to use OpenAI. ```sql @@ -246,13 +249,14 @@ END; The LLM involves processing both the user question and relevant text excerpts to generate responses tailored specifically to the provided context. It's essential to note that the nature of the response is contingent upon the question and the LLM utilized. -LLM prompt engineering enables you to craft input queries or instructions to create more accurate and desirable outputs. The PLSQL uses a SQL CURSOR and CLOBs to generate the LLM prompt based on facts from the similarity search from Oracle Database 23ai. +LLM prompt engineering enables you to craft input queries or instructions to create more accurate and desirable outputs. The PLSQL uses a SQL CURSOR and CLOBs to generate the LLM prompt based on facts from the similarity search from Oracle Database 23ai. -In the code below we are embedding the user question, performing a vector search in the database for the relevant text chunks using a vector distance function. We pass the doc\_id to select the chunks related to a PDF document we loaded. This improves the accuracy of the LLM response for the question by restricting the result within the content of PDF. We then send the text chunks to LLM to provide the response. +In the code below we are embedding the user question, performing a vector search in the database for the relevant text chunks using a vector distance function. We pass the doc\_id to select the chunks related to a PDF document we loaded. This improves the accuracy of the LLM response for the question by restricting the result within the content of PDF. We then send the text chunks to LLM to provide the response. Compile the function `generate_text_response2` below. It is called from APEX. -### OCI GenAI +### OCI GenAI + For connecting and authenticating to OCI GenAI you must have created the login credentials using DBMS\_VECTOR.CREATE\_CREDENTIAL in the previous lab. ```sql @@ -313,7 +317,7 @@ BEGIN { "provider":"ocigenai", "credential_name": "GENAI_CRED", - "url": "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/chat", + "url": "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/generateText", "model": "cohere.command", "inferenceRequest": { "maxTokens": 2000, @@ -359,7 +363,7 @@ In this lab we learned how a RAG solution using PLSQL works. The table below li Embedding the user question - VECTOR_EMBEDDING(tinybert_model USING user_question as data) + VECTOR_EMBEDDING(tinybert_model USING user_question as data) @@ -372,16 +376,15 @@ In this lab we learned how a RAG solution using PLSQL works. The table below li - Pass the result chunks and the user question to the LLM + Pass the result chunks and the user question to the LLM DBMS_VECTOR_CHAIN.UTL_TO_GENERATE_TEXT(messages, json(params_genai)) - + - • In the next LAB, the APEX code will be calling the package functions here. • This means that these packages could then easily be called from any programming language, eg., @@ -393,10 +396,13 @@ In this lab we learned how a RAG solution using PLSQL works. The table below li * OCI, OCCI, ODBC, Pro*C or Pro*COBOL * Go, Rust, PHP, Ruby etc +## Summary -You may now [proceed to the next lab](#next). +You now know how to create the database vector tables with sql worksheet in ADB using OCI console. +You may now [proceed to the next lab](#next). ## Acknowledgements + * **Authors** - Vijay Balebail, Milton Wan, Blake Hendricks * **Last Updated By/Date** - Milton Wan, July 2024 diff --git a/ai-vector-search-apex-adb/workshops/freetier/manifest.json b/ai-vector-search-apex-adb/workshops/freetier/manifest.json index bde23771..19478067 100644 --- a/ai-vector-search-apex-adb/workshops/freetier/manifest.json +++ b/ai-vector-search-apex-adb/workshops/freetier/manifest.json @@ -24,20 +24,21 @@ "filename": "../../download/download.md" }, { - "title": "Lab 3: Setup APEX Service", + "title": "Lab 3: Create the Vector tables", + "description": "Create the vector table and compile the RAG procedures and functions.", + "filename": "../../tables/tables.md" + }, + { + "title": "Lab 4: Setup APEX Service", "description": "Set up the APEX service and import the pre-created RAG application.", "filename": "../../apex/apex.md" }, { - "title": "Lab 4: Edit APEX Application", + "title": "Lab 5: Edit APEX Application", "description": "Configure the application to access the object storage.", "filename": "../../apex-app/apex-app.md" }, - { - "title": "Lab 5: Create the Vector tables", - "description": "Create the vector table and compile the RAG procedures and functions.", - "filename": "../../tables/tables.md" - }, + { "title": "Lab 6: Run the RAG application", "description": "Run the RAG application.",