Skip to content

Commit b89d477

Browse files
committed
changes per Manjunath
1 parent 567b3ab commit b89d477

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

ai-vector-search-and-rag/README.md

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Oracle Database 23ai - Oracle AI Vector Search & Retrieval Augmented Generation (RAG) with Oracle APEX
1+
# Leveraging Open Neural Network Exchangemodels to vectorize content in PDFs
22

3-
This is part 2 of the Oracle Database 23ai series of technical articles. While searching for large external language models to get answers to the questions will solve one type of problem, the requirements might also differ slightly from searching for Corporate internal knowledge repositories and datasets.
3+
While searching for large external language models to get answers to questions will solve one type of problem, the requirements might also differ slightly from searching for Corporate internal knowledge repositories and datasets.
44

5-
For example, consider that your company is working on internal research and has several internal PDFs that should be searched by the AI Search engine rather than going and looking for public LLM for questions that concern us. Also, the possibility of traditional RDBMS queries along with Gen AI queries will make it more powerful.
5+
Imagine an organization is working on internal research and has several internal PDFs that should be searched by an AI Search engine rather than going and looking for public LLMs for relevant questions. There's also the possibility of traditional RDBMS queries along with Gen AI queries to make it more powerful.
6+
7+
This solution will demonstrate how to use Open Neural Network Exchange (ONNX) concepts, create our own ONNX models, and use these models to read PDFs and vectorize content, ultimately developing an Oracle APEX Vector-based search engine that can query internal knowledge repositories (or sometimes also query external large language models).
68

7-
In this article, we will understand Open Neural Network Exchange (ONNX) concepts, create our own ONNX models, Use these models to read PDFs and vectorise content, and Develop an Oracle APEX Vector-based search engine that can query internal knowledge repositories or sometimes also query external large language models.
89

910
### About Retrieval augmented generation (RAG)
1011

@@ -17,8 +18,6 @@ The desire to get higher quality answers from LLMs is universal, spanning many i
1718
- Language to code synthesis
1819
- Answers to questions that require specialized, **domain-specific knowledge**
1920

20-
Please refer to the article in part 1 if you have not yet installed or configured Oracle Database 23ai, along with Oracle APEX and ORDS.
21-
2221
In this article, we will cover the following:
2322

2423
1. Open Neural Network Exchange (ONNX) - concepts
@@ -719,10 +718,10 @@ Create Search Parameters and Search Oracle Generative AI, Append both the search
719718

720719
[45]: images/1715409940189.png
721720

722-
You can [download this complete code from my GitHub repository][46]
721+
You can [download the complete code here.][46]
723722

724723

725-
[46]: https://github.com/madhusudhanrao-ppm/code-assets/blob/main/GenAI/RAG/RAG_WITH_GENAI_FUNCTION.sql
724+
[46]: assets/RAG_WITH_GENAI_FUNCTION.sql
726725

727726
### 13. Create Oracle APEX page for AI Vector Search
728727

@@ -834,25 +833,3 @@ Architecture diagram from the left side towards the right
834833
14. Innovation: Integrate with text to voice APIs
835834

836835
[![Short demo](http://img.youtube.com/vi/kMoBJpr4Gt8/0.jpg)](http://www.youtube.com/watch?v=kMoBJpr4Gt8 "Short Demo")
837-
838-
* * *
839-
840-
### 14. Innovate: Integrate with text to voice based APIs
841-
842-
Updated July 2024, You can easily make REST API calls (**If the service provider exposes APIs**) from AI response text to video generation APIs. Please read their terms and conditions of service providers. Most of these services will have a few minutes of free usage, and you need to subscribe to their various plans for commercial licenses.
843-
844-
Usually, these video generations take a few seconds to a minute, so you must pragmatically check the video creation status before displaying the video using the provider's generated video URL.
845-
846-
[![Demo](http://img.youtube.com/vi/LMRmnzwy4q8/0.jpg)](http://www.youtube.com/watch?v=LMRmnzwy4q8 "Demo")
847-
848-
### Click to Action:
849-
850-
[Oracle Database Free Get Started][56]
851-
852-
853-
[56]: https://www.oracle.com/in/database/free/get-started/
854-
855-
[Developer Resource Center][57]
856-
857-
858-
[57]: https://developer.oracle.com/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- Code Author Madhusudhan Rao
2+
-- Article Link https://www.linkedin.com/pulse/oracle-database-23ai-ai-vector-search-retrieval-augmented-rao-bqkcf
3+
create or replace Function rag_with_genai_function ( rag_input IN varchar2 )
4+
RETURN varchar2
5+
IS
6+
7+
query_vector CLOB;
8+
text_variable VARCHAR2(1000) := rag_input;
9+
l_doc_id VARCHAR2(100);
10+
input CLOB;
11+
params CLOB;
12+
output CLOB;
13+
long_text VARCHAR2(4000);
14+
cursor c1 is SELECT *
15+
FROM doc_chunks
16+
ORDER BY VECTOR_DISTANCE( EMBED_VECTOR, query_vector, EUCLIDEAN_SQUARED)
17+
FETCH FIRST 1 ROWS ONLY WITH TARGET ACCURACY 90;
18+
BEGIN
19+
20+
input := text_variable;
21+
params := '{
22+
"provider" : "ocigenai",
23+
"credential_name" : "OCI_CRED",
24+
"url" : "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/generateText",
25+
"model" : "cohere.command",
26+
"inferenceRequest": {
27+
"maxTokens": 300,
28+
"temperature": 1
29+
}
30+
}';
31+
32+
33+
SELECT vector_embedding(doc_model using text_variable as data) into query_vector;
34+
For row_1 In C1 Loop
35+
long_text := '<hr/> Internal PDF Search: <hr/>'||row_1.embed_data||' <hr/>';
36+
End Loop;
37+
output := DBMS_VECTOR_CHAIN.UTL_TO_GENERATE_TEXT(input, json(params));
38+
39+
long_text := long_text||' Generative AI Response:<hr/> '||output;
40+
41+
return (long_text);
42+
43+
END;
44+
/

0 commit comments

Comments
 (0)