Skip to content

Commit b76f95f

Browse files
Adding 23ai RAG Asset
1 parent b610d89 commit b76f95f

14 files changed

+2376
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing to this repository
2+
3+
We welcome your contributions! There are multiple ways to contribute.
4+
5+
## Opening issues
6+
7+
For bugs or enhancement requests, please file a GitHub issue unless it's
8+
security related. When filing a bug remember that the better written the bug is,
9+
the more likely it is to be fixed. If you think you've found a security
10+
vulnerability, do not raise a GitHub issue and follow the instructions in our
11+
[security policy](./SECURITY.md).
12+
13+
## Contributing code
14+
15+
We welcome your code contributions. Before submitting code via a pull request,
16+
you will need to have signed the [Oracle Contributor Agreement][OCA] (OCA) and
17+
your commits need to include the following line using the name and e-mail
18+
address you used to sign the OCA:
19+
20+
```text
21+
Signed-off-by: Your Name <[email protected]>
22+
```
23+
24+
This can be automatically added to pull requests by committing with `--sign-off`
25+
or `-s`, e.g.
26+
27+
```text
28+
git commit --signoff
29+
```
30+
31+
Only pull requests from committers that can be verified as having signed the OCA
32+
can be accepted.
33+
34+
## Pull request process
35+
36+
1. Ensure there is an issue created to track and discuss the fix or enhancement
37+
you intend to submit.
38+
1. Fork this repository.
39+
1. Create a branch in your fork to implement the changes. We recommend using
40+
the issue number as part of your branch name, e.g. `1234-fixes`.
41+
1. Ensure that any documentation is updated with the changes that are required
42+
by your change.
43+
1. Ensure that any samples are updated if the base image has been changed.
44+
1. Submit the pull request. *Do not leave the pull request blank*. Explain exactly
45+
what your changes are meant to do and provide simple steps on how to validate.
46+
your changes. Ensure that you reference the issue you created as well.
47+
1. We will assign the pull request to 2-3 people for review before it is merged.
48+
49+
## Code of conduct
50+
51+
Follow the [Golden Rule](https://en.wikipedia.org/wiki/Golden_Rule). If you'd
52+
like more specific guidelines, see the [Contributor Covenant Code of Conduct][COC].
53+
54+
[OCA]: https://oca.opensource.oracle.com
55+
[COC]: https://www.contributor-covenant.org/version/1/4/code-of-conduct/

Oracle-23ai-RAG-Chatbot/LICENSE.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2024 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.

Oracle-23ai-RAG-Chatbot/README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Integrate Oracle 23ai Vector DB with OCI GenAI using Llama-index
2+
3+
[![Python Version](https://img.shields.io/badge/python-3.11.x-blue.svg)](https://www.python.org/downloads/release/python-3110/)
4+
5+
## Introduction
6+
7+
Accessing the right answers from vast data repositories is a challenge many organizations face. A **Retrieval-Augmented Generation (RAG)** based system can revolutionize how users interact with their data by making information easily accessible and up-to-date. In this workshop, we’ll build a RAG-based chatbot using **Oracle Database 23ai** and **OCI Generative AI** services, allowing users to chat with their unstructured data like PDF, CSV, and TXT files. This approach combines advanced retrieval techniques with generative AI, creating a powerful solution for intelligent and dynamic data interaction.
8+
9+
10+
## What is RAG?
11+
12+
**Retrieval-Augmented Generation (RAG)** combines retrieval-based methods with generative AI to provide more accurate and contextually relevant responses by accessing and utilizing large datasets dynamically. [Learn more about RAG](https://www.oracle.com/artificial-intelligence/generative-ai/retrieval-augmented-generation-rag/).
13+
14+
## Prerequisites and Setup
15+
16+
Before you begin, ensure you have the following:
17+
18+
- **Oracle Cloud Account**
19+
[Sign up here](https://www.oracle.com/cloud/free/)
20+
21+
- **Oracle Database 23AI**
22+
[Learn more](https://www.oracle.com/database/23ai/)
23+
24+
- **Compute VM**
25+
This will serve as your web app. Ensure the Compute VM can communicate with the Oracle Database by setting up the appropriate network configurations.
26+
27+
- **OCI Generative AI Services**
28+
[Documentation](https://docs.oracle.com/en-us/iaas/Content/GenerativeAI/home.htm)
29+
30+
- **LlamaIndex**
31+
[Documentation](https://pypi.org/project/llama-index/)
32+
33+
- **Python Dependencies**
34+
Listed in the `requirements.txt` file in the repository.
35+
36+
## Setup
37+
38+
### 1. Clone the Repository in your web server (Compute VM)
39+
40+
```bash
41+
sudo dnf install git
42+
43+
git clone https://github.com/SaurabhSalunkhe/Oracle-23ai-RAG-Chatbot.git
44+
```
45+
46+
### 2. Update and Install Dependencies (Oracle Linux)
47+
```
48+
sudo yum update -y && sudo yum install -y git python3 && sudo yum groupinstall -y "Development Tools" && sudo yum install -y bzip2-devel openssl-devel libffi-devel zlib-devel wget libffi-devel openssl openssl-devel tk-devel xz-devel zlib-devel bzip2-devel readline-devel libuuid-devel ncurses-devel libaio
49+
50+
```
51+
52+
### 3. Install Python 3.11.x
53+
Ensure Python version 3.11.x is installed.
54+
55+
```
56+
mkdir -p $HOME/python
57+
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz
58+
tar -xvzf Python-3.11.0.tgz --strip-components=1 -C /home/$USER/python
59+
cd $HOME/python
60+
./configure --prefix=$HOME/python
61+
./configure --enable-optimizations
62+
make clean; make
63+
make altinstall
64+
65+
export PYTHONHOME=$HOME/python
66+
export PATH=$PYTHONHOME/bin:$PATH
67+
export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH
68+
69+
cd $HOME/python/bin
70+
ln -s python3.11 python3
71+
ln -s pip3.11 pip3
72+
73+
```
74+
75+
### 4. Create and Activate Virtual Environment
76+
```
77+
cd Oracle-23ai-RAG-Chatbot
78+
python3.11 -m venv venv
79+
source venv/bin/activate
80+
```
81+
82+
### 5. Install Python Dependencies
83+
84+
```
85+
pip install -r requirements.txt
86+
```
87+
88+
### 6. Configure OCI Authentication
89+
a. Create the .oci Directory
90+
91+
```
92+
mkdir -p /home/opc/.oci
93+
```
94+
95+
b. Generate OCI API Keys
96+
Follow the OCI SDK Configuration Guide to generate your API keys.
97+
https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm
98+
99+
https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#apisigningkey_topic_How_to_Generate_an_API_Signing_Key_Console
100+
101+
### 7. Set Up Oracle Database 23ai
102+
a. Run SQL Commands from create_tables.sql
103+
Create the User and Grant Privileges
104+
105+
```
106+
-- Create the user with a specified password
107+
CREATE USER ai_user IDENTIFIED BY "EXamplepassword#_123";
108+
109+
-- Grant DBA privileges for full administrative access
110+
GRANT DBA TO ai_user;
111+
112+
-- Grant specific roles and privileges needed for Oracle AI Vector Search
113+
GRANT DB_DEVELOPER_ROLE TO ai_user;
114+
GRANT CREATE MINING MODEL TO ai_user;
115+
```
116+
117+
As ai_user, Create Tables with Vector Data Types
118+
119+
120+
```
121+
CREATE TABLE BOOKS (
122+
ID NUMBER NOT NULL,
123+
NAME VARCHAR2(100) NOT NULL,
124+
PRIMARY KEY (ID)
125+
);
126+
127+
CREATE TABLE CHUNKS (
128+
ID VARCHAR2(64) NOT NULL,
129+
CHUNK CLOB,
130+
VEC VECTOR(1024, FLOAT64),
131+
PAGE_NUM VARCHAR2(10),
132+
BOOK_ID NUMBER,
133+
PRIMARY KEY (ID),
134+
CONSTRAINT fk_book
135+
FOREIGN KEY (BOOK_ID)
136+
REFERENCES BOOKS (ID)
137+
);
138+
```
139+
140+
8. Configure the Application
141+
a. Edit config.py
142+
Update the following parameters with your details:
143+
144+
```
145+
# DB connections (Below are example credentials. Substitute with your credentials)
146+
DB_USER = "ai_user"
147+
DB_PWD = "EXamplepassword#_123"
148+
DB_HOST_IP = "ip:1521"
149+
DB_SERVICE = "example_PDB1.sub07260203110.vcnss.oraclevcn.com"
150+
151+
# GenAI configurations
152+
COMPARTMENT_OCID = "ocid1.compartment.oc1..xxxxxxxxx"
153+
ENDPOINT = "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com"
154+
COHERE_API_KEY = "xxxxxxxxxxx" # Optional but recommended
155+
```
156+
157+
### 8. Run the Streamlit Application
158+
159+
```
160+
sudo systemctl stop firewalld
161+
streamlit run app.py
162+
```
163+
164+
### 9. To Run the App in the Background
165+
166+
```
167+
nohup streamlit run app.py &
168+
```
169+
170+
### 10. Access the Chatbot
171+
Open your browser and navigate to http://<Your_VM_IP>:8501.
172+
173+
You should see the chatbot interface as shown below:
174+
175+
![Chatbot UI](./screenshot.png)
176+
177+
## Contributing
178+
<!-- If your project has specific contribution requirements, update the
179+
CONTRIBUTING.md file to ensure those requirements are clearly explained. -->
180+
181+
This project welcomes contributions from the community. Before submitting a pull
182+
request, please [review our contribution guide](./CONTRIBUTING.md).
183+
184+
## Security
185+
186+
Please consult the [security guide](./SECURITY.md) for our responsible security
187+
vulnerability disclosure process.
188+
189+
## License
190+
Copyright (c) 2024 Oracle and/or its affiliates.
191+
192+
Licensed under the Universal Permissive License (UPL), Version 1.0.
193+
194+
See [LICENSE](LICENSE.txt) for more details.
195+
196+
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.

Oracle-23ai-RAG-Chatbot/SECURITY.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Reporting security vulnerabilities
2+
3+
Oracle values the independent security research community and believes that
4+
responsible disclosure of security vulnerabilities helps us ensure the security
5+
and privacy of all our users.
6+
7+
Please do NOT raise a GitHub Issue to report a security vulnerability. If you
8+
believe you have found a security vulnerability, please submit a report to
9+
[[email protected]][1] preferably with a proof of concept. Please review
10+
some additional information on [how to report security vulnerabilities to Oracle][2].
11+
We encourage people who contact Oracle Security to use email encryption using
12+
[our encryption key][3].
13+
14+
We ask that you do not use other channels or contact the project maintainers
15+
directly.
16+
17+
Non-vulnerability related security issues including ideas for new or improved
18+
security features are welcome on GitHub Issues.
19+
20+
## Security updates, alerts and bulletins
21+
22+
Security updates will be released on a regular cadence. Many of our projects
23+
will typically release security fixes in conjunction with the
24+
Oracle Critical Patch Update program. Additional
25+
information, including past advisories, is available on our [security alerts][4]
26+
page.
27+
28+
## Security-related information
29+
30+
We will provide security related information such as a threat model, considerations
31+
for secure use, or any known security issues in our documentation. Please note
32+
that labs and sample code are intended to demonstrate a concept and may not be
33+
sufficiently hardened for production use.
34+
35+
[1]: mailto:[email protected]
36+
[2]: https://www.oracle.com/corporate/security-practices/assurance/vulnerability/reporting.html
37+
[3]: https://www.oracle.com/security-alerts/encryptionkey.html
38+
[4]: https://www.oracle.com/security-alerts/

0 commit comments

Comments
 (0)