|
| 1 | +# Code with AI Vector Search step-by-step |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +In this coding challenge, you’ll focus on **AI Vector Search**. Your mission is to implement a key update to change the way similarities are calculated, improving the accuracy of predictions. |
| 6 | + |
| 7 | +At SeerEquites, the data science team has been using Cosine similarity to assess similarities between customer profiles and predict loan risks. While effective in some contexts, the team recently realized that Cosine similarity wasn’t capturing the full picture of their customers financial profiles. |
| 8 | + |
| 9 | +**Why switch to Euclidean distance?** |
| 10 | + |
| 11 | +Cosine similarity is great when you care about the pattern or direction of someone’s data — not how big or small the numbers are. But in finance, the actual size of the numbers often matters a lot. |
| 12 | + |
| 13 | +Let’s say you’re comparing two customers based on their debt, income, and credit usage. These numbers matter significantly, and big differences can indicate very different levels of risk. |
| 14 | + |
| 15 | +Here’s an example: |
| 16 | + |
| 17 | +* Both customers have the same debt-to-income ratio of 2:1. |
| 18 | + |
| 19 | +* But one earns $20,000 a year, while the other earns $200,000. |
| 20 | + |
| 21 | +Cosine similarity would say these customers are quite similar, because their ratios follow the same pattern. But that’s misleading — the person earning $20,000 is much riskier. |
| 22 | + |
| 23 | +That’s where Euclidean distance comes in. Unlike Cosine similarity, Euclidean distance looks at the actual difference in the numbers. In this case, it would correctly flag that these customers are not similar in a meaningful way, since the scale of their incomes is vastly different. |
| 24 | + |
| 25 | +In finance, where decisions are often made based on key figures like income, debt, and credit usage, Euclidean distance is often a better tool. It takes the size of the numbers into account, which is crucial for making accurate risk predictions. |
| 26 | + |
| 27 | +In this lab, you’ll update the code to switch the similarity measure from Cosine to Euclidean. This change will improve the system’s ability to assess loan risks more accurately, providing more reliable insights for decision-making. |
| 28 | + |
| 29 | +This is your opportunity to sharpen your skills, explore the power of AI-driven search, and make a meaningful impact on a application. Let’s get started! |
| 30 | + |
| 31 | +Estimated Time: 30 minutes |
| 32 | + |
| 33 | +### Objectives |
| 34 | + |
| 35 | +In this lab, you will: |
| 36 | +* Enhance your understanding of AI Vector Search by applying it to a developer coding challenge. |
| 37 | +* Gain hands-on experience with integrating AI Vector Search and refining application features to meet specific development requirements. |
| 38 | + |
| 39 | +### Prerequisites |
| 40 | + |
| 41 | +This lab assumes you have: |
| 42 | +* An Oracle Cloud account |
| 43 | +* Successfully completed Lab 1: Run the Demo |
| 44 | +* Successfully completed Lab 3: Connect to Development Environment |
| 45 | + |
| 46 | +## Task 1: Challenge Requirements |
| 47 | + |
| 48 | +Based on the data scientists' evaluation, the company has decided to switch from using Cosine similarity to Euclidean distance. This change aims to enhance the system’s ability to assess loan risks more accurately, ultimately providing more reliable insights to support better decision-making. |
| 49 | + |
| 50 | +Follow the prompts below to update the code based on the new company standard. |
| 51 | + |
| 52 | +## Task 2: Launch the Application |
| 53 | + |
| 54 | +1. Select the **Launcher** tab and open the **terminal** |
| 55 | + |
| 56 | +  |
| 57 | + |
| 58 | +2. Copy the ./run.sh command and paste it into the terminal. |
| 59 | + |
| 60 | + ````bash |
| 61 | + $<copy> |
| 62 | + ./run.sh |
| 63 | + </copy> |
| 64 | + ```` |
| 65 | + |
| 66 | +3. Click the URL displayed in the terminal to launch the SeerEquities Loan Management application. |
| 67 | + |
| 68 | +  |
| 69 | + |
| 70 | +4. Enter in a username and click **Login**. |
| 71 | + |
| 72 | +  |
| 73 | + |
| 74 | +## Task 3: View the current AI chat bot return variables using Cosine |
| 75 | + |
| 76 | +1. On the Dashboard page, from the pending review list, select the Customer ID for **James Smith**. |
| 77 | + |
| 78 | +  |
| 79 | + |
| 80 | +2. This will display the customers loan application details. In approximately 15 seconds, the AI generated loan recommendations will be displayed. |
| 81 | + |
| 82 | +  |
| 83 | + |
| 84 | +3. Ask the following question to the AI Chat bot. |
| 85 | + |
| 86 | + ````text |
| 87 | + <copy> |
| 88 | + What about a 4th loan? |
| 89 | + </copy> |
| 90 | + ```` |
| 91 | + |
| 92 | + Note how the return variables are shown: |
| 93 | + |
| 94 | +  |
| 95 | + |
| 96 | +## Task 4: Modify the Customers.py File |
| 97 | + |
| 98 | +1. Click **Pages**. |
| 99 | + |
| 100 | +  |
| 101 | + |
| 102 | +2. Select the **Customers.py** file. |
| 103 | + |
| 104 | +  |
| 105 | + |
| 106 | +3. Update the Customers.py file to make the necessary changes in the code at lines 845 and 846 |
| 107 | + |
| 108 | +  |
| 109 | + |
| 110 | +4. Save the Customers.py file. |
| 111 | + |
| 112 | +  |
| 113 | + |
| 114 | +## Task 5: View results in the Loan application |
| 115 | + |
| 116 | +1. On the Dashboard page, from the pending review list, select the Customer ID for **James Smith**. |
| 117 | + |
| 118 | +  |
| 119 | + |
| 120 | +2. This will display the customers loan application details. In approximately 15 seconds, the AI generated loan recommendations will be displayed. |
| 121 | + |
| 122 | +  |
| 123 | + |
| 124 | +3. Ask the following question to the AI Chat bot. |
| 125 | + |
| 126 | + ````text |
| 127 | + <copy> |
| 128 | + What about a 4th loan? |
| 129 | + </copy> |
| 130 | +```` |
| 131 | +4. View the new prompt return from the AI chat bot |
| 132 | + |
| 133 | +  |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +**Congratulations, you have successfully completed the AI Vector Search Challenge!** By switching to Euclidean distance, SeerEquites ensures more precise loan risk evaluations and improves the overall effectiveness of their loan management system. |
| 138 | + |
| 139 | +## Learn More |
| 140 | + |
| 141 | +* [Oracle Database 23ai Documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/) |
| 142 | + |
| 143 | +## Acknowledgements |
| 144 | +* **Authors** - Linda Foinding, Francis Regalado |
| 145 | +* **Contributors** - Kamryn Vinson, Eddie Ambler, Kevin Lazarz |
| 146 | +* **Last Updated By/Date** - Kamryn Vinson, April 2025 |
0 commit comments