Plan Your Deployment
You can use Oracle Cloud Infrastructure Generative AI Agents to build an intelligent search system that provides contextually relevant answers by searching your enterprise knowledge base.
The following implementations are described in this section:
- Bring your enterprise data into a service-managed knowledge base for the Generative AI Agents to ingest.
- Index your data in a customer-managed knowledge base.
- Build and deploy code for data ingestion and generate vector embeddings.
Generative AI Agents with Service-Managed Knowledge Base
The following deployment uses OCI Generative AI Agents to build an intelligent search system that uses a service-managed knowledge base and Oracle Cloud Infrastructure Object Storage.
This deployment uploads TXT and PDF files to Oracle Cloud Infrastructure Object Storage bucket where Generative AI Agents automatically ingest the data to create vectors stored in an integrated vector store.
The advantages of this deployment are that it is well-suited for customers who need a managed solution for unstructured data, provides quick and easy data ingestion, and has minimal coding and maintenance requirements. The Cohere service-managed embedding model, however, only allows up to 1000 text and PDF files per knowledge base.
genai-knowledge-base-oracle.zip
Use the following high-level steps to create this deployment:
- Provision an object storage bucket and upload files to the bucket.
Supported file types are PDF and TXT and each file must be no larger than 100MB. PDF files can include images, charts, and reference tables but each of these objects must not exceed 8MB. OCI Object Storage supports batch upload of files by using the console, Rest API, or software development kit (SDK).
- Create a knowledge base and an ingestion job.
Create a knowledge base in OCI Generative AI Agents and specify the object storage bucket that you provisioned as the data source. Select the Automatically start ingestion job option so that the OCI Generative AI Agents service generates a vector index by using the service-managed embedding model.
- Create the agent and endpoint.
Create an agent in OCI Generative AI Agents and connect it to the knowledge base provisioned in the previous step. Create an endpoint for the agent which will later be used to launch a chat with the agent. The endpoint is used to enable communication and data exchange between an agent and external systems. The endpoint is a required input parameter if you want to enable chat functionality by using AI Agents by using the API or SDK.
- Optionally, create a front-end integration.
OCI Generative AI Agents service provides a chat user interface which allows users to ask questions related to the data that the agent has access to. You can integrate the agent with your application by using the service Rest API or SDK and then by customizing the chat bot interface. Oracle offers low-code, no-code application development tools such as Oracle APEX Application Development and Oracle Digital Assistant.
Generative AI Agents with OCI OpenSearch
The following deployment uses Oracle Cloud Infrastructure Search with OpenSearch data as a customer-managed knowledge base for Generative AI Agents to use.
Oracle Cloud Infrastructure Search with OpenSearch is a managed service that can search and analyze data housed in large-volume data stores. In this deployment, OpenSearch is the vector database used to store enterprise documents, create indexes, and search and retrieve data by using hybrid search. The search results are then ranked by OCI Generative AI Agents by using a managed reranking model and then sent to the Cohere large language model (LLM) to generate a contextual response.
The advantages of this deployment are that it supports a broader range of file types, such as JSON, XML, and Blogs, is compatible with a wide range of open-source embedding models, and can use auto-truncation for more specific search results. This deployment requires that you build and manage the data ingestion and indexing pipelines and requires that files are chunked to less than 512 tokens each and ingested and indexed in OpenSearch.
Use the following high-level steps to create this deployment:
- Provision the Oracle Cloud
Infrastructure Search stack and ingest data.
Provision virtual cloud networks (VCN), an Oracle Cloud Infrastructure Search cluster, and a virtual machine (VM) instance.
See the Explore More section for a link to a tutorial that shows how to create the stack.
- Create an OCI Vault secret.
OCI Generative AI Agents requires you to create a secret so that Oracle Cloud Infrastructure Search can store user names and passwords in OCI Vault.
- Configure the OCI Generative AI Agents knowledge base and agent.
Create a knowledge base by choosing the Oracle Cloud Infrastructure Search cluster as the data source and by specifying which indexes to use. Create an OCI Generative AI RAG agent using this knowledge base.
OCI Generative AI Agents with Oracle Database 23ai
This deployment uses Oracle Autonomous Database 23ai with Vector Search to manage both structured and unstructured data.
When users query enterprise data, AI vector search runs similarity searches to find the most relevant facts to pass to OCI Generative AI Agents. These agents then run reranking models and use the Cohere large language model (LLM) to generate contextual responses.
The advantages of this deployment are that it supports both structured and unstructured data, including media data, images, and videos and that it is compatible with third-party embedding models to provide targeted search results. This deployment requires you to build and deploy code for data ingestion, to generate vector embeddings, and to create vector indexes.
genai-vector-search-oracle.zip
Use the following high-level steps to create this deployment:
- Create an Oracle Database 23ai instance:
- From the OCI service console navigation menu, click Oracle Database and then select Autonomous Data Warehouse.
- Click Create Autonomous Database.
- Name the database and select 23ai as the database version. Provide other parameters or accept the defaults and click Create Autonomous Database.
- Create a vault for storing database credentials and then create a
key:
- From the OCI service console navigation menu, click Identity and Security and then select Vault.
- Click Create Vault.
- Name the vault. Provide other parameters or accept the defaults and click Create Vault.
- In the newly created vault, click Create Key.
- Name the key. Provide other parameters or accept the defaults and click Create Key.
- Create a Database Tools connection:
- From the OCI service console navigation menu, click Developer Services and then select Connections.
- Click Create Connection.
- Name the connection, select Oracle Autonomous Database as the database cloud service, select the compartment, and specify a user name. Provide other parameters or accept the defaults and click Create Password Secret.
- Name the password secret, select the compartment, the vault compartment, the encryption key compartment and specify a password. Click Create.
- Select SSO wallet as the wallet format, then click Create wallet content secret, name the wallet content secret, select the vault and encryption key compartments and make sure that Retrieve regional wallet from Autonomous Database is selected. Click Create.
- Click Create on the Create Connection window. The newly created connection is listed under the Connection tab on the details page for the associated database.
- Build vectors using embedding models using PL/SQL:
- Set up credentials to allow access to OCI resources, such as the OCI Gen AI
service and credentials for DBMS_CLOUD. You will need OCI a configuration
file with private and public api_keys, a fingerprint, user, tenancy and
compartment
ocid.
begin DBMS_CLOUD.CREATE_CREDENTIAL ( credential_name => '<credential_name>', user_ocid => '<user_ocid>', tenancy_ocid => '<tenancy_ocid>', private_key => '<private_key>', fingerprint => '<fingerprint>' ); end; /
- Use built-in database functionality with 23ai stored pdf files to chunk
files and perform the text
extraction.
CREATE TABLE ai_extracted_data AS SELECT j.chunk_id, j.chunk_offset, j.chunk_length, j.chunk_data FROM -- divide a blob into chunks (utl_to_chunks): (select * from dbms_vector_chain.utl_to_chunks( dbms_vector_chain.utl_to_text( to_blob( DBMS_CLOUD.GET_OBJECT('OCI_CRED_BUCKET', '<path-to-object-pdf>') ) ), json('{"max":"75", "normalize":"all", "overlap":"15"}') )), JSON_TABLE(column_value, '$' COLUMNS ( chunk_id NUMBER PATH '$.chunk_id', chunk_offset NUMBER PATH '$.chunk_offset', chunk_length NUMBER PATH '$.chunk_length', chunk_data CLOB PATH '$.chunk_data' ) ) j;
- Create vector embeddings using a wide-range of embedding options, such as
the cohere.embed-multilingual-v3.0 model through OCI Generative AI.
create table ai_extracted_data_vector as ( select chunk_id as docid, to_char(chunk_data) as body, dbms_vector.utl_to_embedding( chunk_data, json('{ "provider": "OCIGenAI", "credential_name": "<credential_name>", "url": "https://example.com/<path>", "model": "cohere.embed-multilingual-v3.0" }') ) as text_vec from ai_extracted_data where chuck_id <= 400 );
- Create a function to query the vector tables and perform the AI Search
operations at
runtime.
create or replace FUNCTION retrieval_func_ai ( p_query IN VARCHAR2, top_k IN NUMBER ) RETURN SYS_REFCURSOR IS v_results SYS_REFCURSOR; query_vec VECTOR; BEGIN query_vec := dbms_vector.utl_to_embedding( p_query, json('{ "provider": "OCIGenAI", "credential_name": "<credential_name>", "url": "https://example.com/<path>", "model": "cohere.embed-multilingual-v3.0" }') ); OPEN v_results FOR SELECT DOCID, BODY, VECTOR_DISTANCE(text_vec, query_vec) as SCORE FROM ai_extracted_data_vector ORDER BY SCORE FETCH FIRST top_k ROWS ONLY; RETURN v_results; END;
- Set up credentials to allow access to OCI resources, such as the OCI Gen AI
service and credentials for DBMS_CLOUD. You will need OCI a configuration
file with private and public api_keys, a fingerprint, user, tenancy and
compartment
ocid.
- Create the knowledge-base using Oracle Database 23ai:
- From the OCI service console navigation menu, click Analytics & AI and then select Generative AI Agents.
- Click Knowledge Bases and the click Create knowledge base.
- Name the knowledge base, select Oracle AI Vector Search as the data store type and that you provide the database tool connection and search function, then click Create Knowledge Base.
- Create a Generative AI Agent with the Oracle Database 23 ai Knowledge Base:
- From the OCI service console navigation menu, click Analytics & AI and then select Agents.
- Click Create agent.
- Name the agent, select the knowledge base you created, then click Create Agent.
After the agent is created you should see the agent is active and ready for chatting.