diff --git a/ai-vector-emmbeding-python/introduction/images/Transformers.png b/ai-vector-emmbeding-python/introduction/images/Transformers.png deleted file mode 100644 index 16193cb..0000000 Binary files a/ai-vector-emmbeding-python/introduction/images/Transformers.png and /dev/null differ diff --git a/ai-vector-emmbeding-python/lab1-tabs/images/image-SentenceTransformer-02B.png b/ai-vector-emmbeding-python/lab1-tabs/images/image-SentenceTransformer-02B.png deleted file mode 100644 index 800ea96..0000000 Binary files a/ai-vector-emmbeding-python/lab1-tabs/images/image-SentenceTransformer-02B.png and /dev/null differ diff --git a/ai-vector-emmbeding-python/lab1-tabs/similarity_search_Cohere.py b/ai-vector-emmbeding-python/lab1-tabs/similarity_search_Cohere.py deleted file mode 100644 index 72a18a5..0000000 --- a/ai-vector-emmbeding-python/lab1-tabs/similarity_search_Cohere.py +++ /dev/null @@ -1,168 +0,0 @@ -# ----------------------------------------------------------------------------- -# Copyright (c) 2023, Oracle and/or its affiliates. -# -# This software is dual-licensed to you under the Universal Permissive License -# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License -# 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose -# either license. -# -# If you elect to accept the software under the Apache License, Version 2.0, -# the following applies: -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ----------------------------------------------------------------------------- -# -# Basic Similarity Search using the Cohere embed-english-light-v3.0 model -# - -import os -import sys -import array - -import oracledb -import cohere -import time - -un = os.getenv("PYTHON_USERNAME") -pw = os.getenv("PYTHON_PASSWORD") -cs = os.getenv("PYTHON_CONNECTSTRING") - -# topK is how many rows to return -topK = 5 - -# Re-ranking is about potentially improving the order of the resultset -# Re-ranking is significantly slower than doing similarity search -# Re-ranking is optional -rerank = 1 - -sql = """select info - from my_data - order by vector_distance(v, :1, COSINE) - fetch APPROX first :2 rows only""" - -#embedding_model = "embed-english-light-v3.0" -embedding_model = "embed-english-v3.0" -#embedding_model = "embed-multilingual-light-v3.0" -#embedding_model = "embed-multilingual-v3.0" - -rerank_model = "rerank-english-v2.0" -#rerank_model = "rerank-multilingual-v2.0" - -print("Using embedding model " + embedding_model) -if rerank: - print("Using reranker " + rerank_model) -else: - print("Not using reranking") - -print("TopK = " + str(topK)) - -# Whether to generate int8 or float embeddings -use_int_8 = 0 -if use_int_8: - the_type = "int8" - print("Using INT8 embeddings") -else: - the_type = "float" - print("Using float embeddings") - -# Get your Cohere API Key from the environment -api_key = os.getenv("CO_API_KEY") -if api_key: - print('Using Cohere CO_API_KEY') -else: - print('\nYou need to set your Cohere API KEY\n') - print('https://cohere.com/pricing') - print('export CO_API_KEY=whatever_your_api_key_value_is\n') - exit(); - -co = cohere.Client(api_key) - -# Connect to Oracle Database 23.4 -with oracledb.connect(user=un, password=pw, dsn=cs) as connection: - db_version = tuple(int(s) for s in connection.version.split("."))[:2] - if db_version < (23, 4): - sys.exit("This example requires Oracle Database 23.4 or later") - print("Connected to Oracle Database") - - with connection.cursor() as cursor: - - while True: - # Get the input text to vectorize - text = input("\nEnter a phrase. Type quit to exit : ") - - if (text == "quit") or (text == "exit"): - break - - if text == "": - continue - - # Create the vector embedding [a JSON object] - sentence = [text] - - tic = time.perf_counter() - - # Create the vector embedding [a JSON object] - response = co.embed( - texts=sentence, - model=embedding_model, - input_type="search_query", - embedding_types=[the_type]).embeddings - - toc = time.perf_counter() - print(f"\nVectorize query took {toc - tic:0.3f} seconds") - - # Extract the vector from the JSON object - # and convert to array format - if use_int_8: - vec = array.array("b", response.int8[0]) - else: - vec = array.array("f", response.float[0]) - - docs = [] - - tic = time.perf_counter() - - # Do the Similarity Search - for (info,) in cursor.execute(sql, [vec, topK]): - - # Copy the resultset to a list of docs - docs.append(info) - - toc = time.perf_counter() - print(f"Similarity Search took {toc - tic:0.3f} seconds") - - if rerank == 0: - - # Just rely on the vector distance for the resultset order - print("\nWithout ReRanking") - print("=================") - for hit in docs: - print(hit) - - else: - - tic = time.perf_counter() - - # ReRank for better results - results = co.rerank(query=text, - documents=docs, - top_n=topK, - model=rerank_model) - - toc = time.perf_counter() - print(f"Rerank took {toc - tic:0.3f} seconds") - - print("\nReRanked results:") - print("=================") - for hit in results: - print(docs[hit.index]) diff --git a/ai-vector-emmbeding-python/lab1-tabs/vectorize_table_Cohere.py b/ai-vector-emmbeding-python/lab1-tabs/vectorize_table_Cohere.py deleted file mode 100644 index d575a94..0000000 --- a/ai-vector-emmbeding-python/lab1-tabs/vectorize_table_Cohere.py +++ /dev/null @@ -1,143 +0,0 @@ -While logged into your Operating System as the Oracle user, create a file called *vectorize_table_Cohere.py* and paste the following contents into the file. - - - ``` - - # ----------------------------------------------------------------------------- - # Copyright (c) 2023, Oracle and/or its affiliates. - # - # This software is dual-licensed to you under the Universal Permissive License - # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License - # 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose - # either license. - # - # If you elect to accept the software under the Apache License, Version 2.0, - # the following applies: - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # https://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - # ----------------------------------------------------------------------------- - # - # Add or update the vectors for all data values in a table - # Use the Cohere embed-english-light-v3.0 model to create the vectors - # - - # If you are using a FREE Cohere API Key you will need to add a time delay. - # Change the setting below to "1" if your key is a free key. - use_free_key = 0 - #use_free_key = 1 - - import os - import sys - import array - import time - - import oracledb - import cohere - - un = os.getenv("PYTHON_USERNAME") - pw = os.getenv("PYTHON_PASSWORD") - cs = os.getenv("PYTHON_CONNECTSTRING") - - query_sql = """select id, info - from my_data - order by 1""" - - update_sql = """update my_data set v = :1 - where id = :2""" - - # Get your Cohere API Key from the environment - api_key = os.getenv("CO_API_KEY") - if api_key: - print('Using Cohere CO_API_KEY') - else: - print('\nYou need to set your Cohere API KEY\n') - print('https://cohere.com/pricing') - print('export CO_API_KEY=whatever_your_api_key_value_is\n') - exit(); - - embedding_model = "embed-english-light-v3.0" - #embedding_model = "embed-english-v3.0" - #embedding_model = "embed-multilingual-light-v3.0" - #embedding_model = "embed-multilingual-v3.0" - - # Whether to generate int8 or float embeddings - use_int_8 = 0 - if use_int_8: - the_type = "int8" - print("Using INT8 embeddings") - else: - the_type = "float" - print("Using float embeddings") - - if use_free_key: - print("Using FREE Cohere API Key") - else: - print("Using PAID Cohere API Key") - - # Authenicate and authorize with cohere.com - co = cohere.Client(api_key) - - # Connect to Oracle Database 23.4 - with oracledb.connect(user=un, password=pw, dsn=cs) as connection: - db_version = tuple(int(s) for s in connection.version.split("."))[:2] - if db_version < (23, 4): - sys.exit("This example requires Oracle Database 23.4 or later") - print("\nConnected to Oracle Database\n") - - with connection.cursor() as cursor: - print("Vectorizing the following data:\n") - - # Loop over the rows and vectorize the VARCHAR2 data - - binds = [] - tic = time.perf_counter() - for id_val, info in cursor.execute(query_sql): - - # Convert to format that Cohere wants - data = [info] - - print(info) - - # Create the vector embedding [a JSON object] - response = co.embed( - texts=data, - model=embedding_model, - input_type="search_query", - embedding_types=[the_type]).embeddings - - # Extract the vector from the JSON object - # and convert to array format - if use_int_8: - vec = array.array("b", response.int8[0]) - else: - vec = array.array("f", response.float[0]) - - # Record the array and key - binds.append([vec, id_val]) - - # Sleep for half a second if the Cohere API Key is a free key - if use_free_key: - time.sleep(.485) - - - toc = time.perf_counter() - - # Do an update to add or replace the vector values - cursor.executemany( - update_sql, - binds, - ) - connection.commit() - - print(f"\nVectors took {toc - tic:0.3f} seconds") - print(f"\nAdded {len(binds)} vectors to the table using embedding model: " + embedding_model + "\n") diff --git a/langchain-rag-23ai/introduction/introduction.md b/langchain-rag-23ai/introduction/introduction.md index 5e780bd..1aedb42 100644 --- a/langchain-rag-23ai/introduction/introduction.md +++ b/langchain-rag-23ai/introduction/introduction.md @@ -1,4 +1,4 @@ -# 7 Easy Steps to Building a RAG application with Oracle AI Vector Search and LangChain +# AI Vector Search - 7 Easy Steps to Building a RAG application with Oracle AI Vector Search and LangChain ## About this Workshop diff --git a/langchain-rag-23ai/lab1/images/aidemofolder.png b/langchain-rag-23ai/lab1/images/aidemofolder.png new file mode 100644 index 0000000..82c6c0b Binary files /dev/null and b/langchain-rag-23ai/lab1/images/aidemofolder.png differ diff --git a/langchain-rag-23ai/lab1/images/browser.png b/langchain-rag-23ai/lab1/images/browser.png index 08eee82..19c0d33 100644 Binary files a/langchain-rag-23ai/lab1/images/browser.png and b/langchain-rag-23ai/lab1/images/browser.png differ diff --git a/langchain-rag-23ai/lab1/images/selectcell.png b/langchain-rag-23ai/lab1/images/selectcell.png new file mode 100644 index 0000000..1b1db3e Binary files /dev/null and b/langchain-rag-23ai/lab1/images/selectcell.png differ diff --git a/langchain-rag-23ai/lab1/images/selectcodecellrun.png b/langchain-rag-23ai/lab1/images/selectcodecellrun.png deleted file mode 100644 index a527cdc..0000000 Binary files a/langchain-rag-23ai/lab1/images/selectcodecellrun.png and /dev/null differ diff --git a/langchain-rag-23ai/lab1/rag1.md b/langchain-rag-23ai/lab1/rag1.md index db03029..58eb076 100644 --- a/langchain-rag-23ai/lab1/rag1.md +++ b/langchain-rag-23ai/lab1/rag1.md @@ -28,9 +28,11 @@ In this lab, you will: ## Task 1: Launch Jupyter Lab Notebook -1. From the Activities menu, open a terminal window +1. From the Activities menu, open a terminal window. -2. From the terminal OS prompt type: jupyter notebook. + ![Open terminal](images/browser.png) + +2. From the terminal OS prompt type the following: ``` $ cd /home/oracle/AIdemo @@ -40,13 +42,10 @@ In this lab, you will: ![Run Jupyter](images/runjupyter.png) -1. Open the saved notebook RAG_with_Oracle23ai_gold1.ipynb. You can double click the file or right-click and select **Open**. +1. Open the notebook **RAG_with_Oracle23ai_gold1.ipynb**. You can double click or right-click and select **Open**. - ![Open RAG notebook](images/openragwithoracle23ai.png) - - The window with the Python code for the RAG application should look like this. +![Open RAG notebook](images/openragwithoracle23ai.png) - ![RAG notebook opened](images/cellwithcode.png) If you want to enlarge the window and have larger fonts, you can zoom in with the browser. @@ -64,9 +63,11 @@ Let's import the libraries. 1. Select the code snippet and click **Run** in Jupyter. A blue line indicates the cell is selected. - ![Run code in Jupyter](images/selectcodecellrun.png) + ![Select code in Jupyter](images/selectcell.png) + + You may get a warning message as shown below. You can ignore this and click **Run** to proceed. - You may get a warning message as shown above. You can ignore this and click **Run** to proceed. + ![ignore warning](images/ignorewarning1.png) ```python # Import libraries and modules @@ -253,7 +254,8 @@ Note: Embedding models are used to vectorize data. To learn more about embedding **Choose an LLM to generate your response** -You have 3 choices in this lab. Choose only one, but you can go back and choose a different one to see its response. Just go back to the LLM cell and run it. Note: For OpenAI, you CANNOT run this in the LiveLabs environment. This sample code is for informational purposes so you can run this example in your own environment. +You have 3 choices in this lab. Choose only one, but you can go back and choose a different one to see its response. Just go back to the LLM cell and run it. +Note: For OpenAI, you **CANNOT** run this in the LiveLabs environment. This sample code is for informational purposes so you can run this example in your own environment. * Choice 1 - OCI GenAI LLM with meta.llama-2.70b-chat * Choice 2 - OpenAI ChatGPT 3.5 (CANNOT run in this LiveLabs environment) diff --git a/langchain-rag-23ai/lab2/images/streamlitocigenai.png b/langchain-rag-23ai/lab2/images/streamlitocigenai.png new file mode 100644 index 0000000..dd5ba9f Binary files /dev/null and b/langchain-rag-23ai/lab2/images/streamlitocigenai.png differ diff --git a/langchain-rag-23ai/lab2/rag2-streamlit.md b/langchain-rag-23ai/lab2/rag2-streamlit.md index 1b520cb..317e1a2 100644 --- a/langchain-rag-23ai/lab2/rag2-streamlit.md +++ b/langchain-rag-23ai/lab2/rag2-streamlit.md @@ -28,13 +28,14 @@ In this lab you will run the application with a UI using Streamlit, load a PDF d 3. Launch a browser from this same virtual environment, or open a tab with existing browser. To launch a browser click on the Activities menu and select Firefox or Chrome. -4. Enter localhost:8501 for the URL in the browser. +4. Enter **localhost:8501** for the URL in the browser. Your application will now be running. Simply follow the UI, load a PDF document, and ask a question of the document. The LLM will answer the question and respond with context from the document. This application follows the same 7 essential RAG steps from the previous lab. -![Streamlit UI](images/streamlit_rag_oracle23ai.png) +![Streamlit UI](images/streamlitocigenai.png) + +A few suggestions for the questions are listed below. You can copy and paste into the question field. -A few suggestions for the questions. For the Oracle Database 23ai documentation: - What are the new features in Oracle Database 23ai - Tell me more about Oracle AI Vector Search @@ -43,9 +44,17 @@ For the Oracle Fiscal Year 2024 Quarter 2 Financial Results document: - Summarize the Oracle 2024 Quarter 2 financial results - What did Larry say in the Oracle Fiscal Year 2024 Quarter 2 financial results -Now check out the RAG application code using the Streamlit UI from a terminal window. +LLMs are multi-lingual, for the Korean version of Oracle Fiscal Year 2024 Quarter 2 Financial Results document: +- Oracle 2024년 2분기 재무 결과 요약 +- Larry는 Oracle 회계연도 2024년 2분기 재무 결과에서 무엇을 말했나요? + +**Code for Streamlit application** + +Now check out the application code using the Streamlit UI. From a terminal window type: + ``` + $ cd /home/oracle/AIdemo $ more genai.py ``` diff --git a/langchain-rag-23ai/workshops/livelabs/manifest.json b/langchain-rag-23ai/workshops/livelabs/manifest.json index 666ab99..a983c0f 100644 --- a/langchain-rag-23ai/workshops/livelabs/manifest.json +++ b/langchain-rag-23ai/workshops/livelabs/manifest.json @@ -1,5 +1,5 @@ { - "workshoptitle": "7 Easy Steps to Building a RAG application with Oracle AI Vector Search and LangChain", + "workshoptitle": "AI Vector Search - 7 Easy Steps to Building a RAG application with Oracle AI Vector Search and LangChain", "help": "livelabs-help-db_us@oracle.com", "variables": ["../../variables/variables.json", "../../variables/variables-in-another-file.json"], @@ -15,11 +15,6 @@ "filename": "https://oracle-livelabs.github.io/common/labs/verify-compute/verify-compute-novnc.md" }, { - "title": "Pre-Lab: Lab Preparation", - "description": "Set the OCID in environment variable to access OCI GenAI service.", - "filename": "../../prepare-env/prep-env.md" - }, - { "title": "Lab 1: Build and Run the RAG Application with Oracle AI Vector Search and Langchain", "description": "Hands-on lab for building and running the RAG Application.", "filename": "../../lab1/rag1.md"