Generating Answers in PL/SQL
Agentic AI for Oracle AI Database Professional · Lesson 12 of 20 · 1:23:41
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Agentic AI for Oracle AI Database Professional exam (1Z0-1159-26). In this lesson: the prerequisites (roles, host access control lists, proxy), credentials with CREATE_CREDENTIAL, generating the answer with UTL_TO_GENERATE_TEXT, and summaries and reranking. Follows Ambergate Appliances, a fictional appliance maker. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
One procedure, one answer
Ambergate's support app calls a single PL/SQL procedure for each question a technician asks. That procedure must retrieve the right chunks, call a language model on OCI Generative AI, and return a grounded answer. This lesson covers the prerequisites, credentials, generating the answer, and summaries and reranking.
Prerequisites
Calling an external model from the database needs a few things first. The user needs the DB_DEVELOPER_ROLE role, and the create credential privilege. The database needs a network access control entry for the provider's host, added with the APPEND_HOST_ACE procedure, with the connect privilege. And when the database sits behind a proxy, the SET_PROXY procedure of UTL_HTTP sets it for the session.
Credentials
A credential holds the secrets for the provider, so they never appear in your code. The CREATE_CREDENTIAL procedure of DBMS_VECTOR_CHAIN creates one, with a name and its parameters in JSON. For OCI Generative AI, the JSON holds the user OCID, the tenancy OCID, the compartment OCID, the private key, and its fingerprint. For many other providers, it holds an access token instead.
Generating the answer
The procedure first embeds the question with VECTOR_EMBEDDING, and retrieves the top k chunks with a similarity search. It joins the chunks into a context, and builds a prompt that asks the model to answer from that context only. Then UTL_TO_GENERATE_TEXT sends the prompt, with JSON parameters that name the provider, the credential, the URL, and the model. It returns the generated text, ready to show to the technician.
Summaries and reranking
The chain offers more steps for RAG. UTL_TO_SUMMARY asks a model to summarize a long text, for example before it goes into a prompt. Reranking reorders the retrieved chunks by their relevance to the question, with a dedicated model from providers like Cohere or Vertex AI, before the best ones go to the language model. The functions are RERANK and UTL_TO_RERANK, and better chunks in the prompt mean fewer hallucinations.
Recap
Let's recap. Calling an external model needs DB_DEVELOPER_ROLE, the create credential privilege, a host access control entry, and sometimes a proxy. CREATE_CREDENTIAL stores the provider's secrets, with OCIDs, a private key, and a fingerprint for OCI. A RAG procedure embeds the question, retrieves the top chunks, and builds a prompt from them. UTL_TO_GENERATE_TEXT sends it with the provider, the credential, the URL, and the model. And UTL_TO_SUMMARY summarizes, while reranking puts the most relevant chunks first.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
A developer’s first call to OCI Generative AI from PL/SQL fails with a network access error, although the credential is correct. What is most likely missing?
- The DB_DEVELOPER_ROLE role for the user
- A vector index on the chunk table
- An ONNX model loaded in the database
- A host access control entry
Show the answer
A host access control entry
Without an access control entry for the provider's host, the database refuses the outgoing connection. “The DB_DEVELOPER_ROLE role for the user” would cause a privilege error, not a network access error. “A vector index on the chunk table” is only needed for approximate searches, and it has nothing to do with the outgoing call. And “An ONNX model loaded in the database” is for embedding in the database, not for calling an outside model.
Ambergate’s DBA creates the credential for OCI Generative AI. Which values does its JSON document hold?
- A database username and its password
- A single access token for the provider
- OCIDs, a private key, and a fingerprint
- The model name, endpoint URL and region
Show the answer
OCIDs, a private key, and a fingerprint
An OCI credential holds the user, tenancy, and compartment OCIDs, with the private key and its fingerprint. “A database username and its password” is how users sign in to the database, not how it reaches OCI. “A single access token for the provider” is what many other providers use, but OCI signs requests with a key. And “The model name, endpoint URL and region” goes in the parameters of each call, not in the credential.
The similarity search returns twenty candidate chunks, but the prompt has room for only five. Ambergate wants the five most relevant to the question. Which step fits?
- Rerank the candidates with a reranking model
- Summarize all twenty chunks into a single one
- Raise the target accuracy of the vector index
- Increase the overlap between the chunks
Show the answer
Rerank the candidates with a reranking model
A reranking model scores each candidate against the question, and the five best go into the prompt. “Summarize all twenty chunks into a single one” mixes all twenty chunks together, and it can lose the details that matter. “Raise the target accuracy of the vector index” changes how many true neighbors the index finds, not how they are ranked for the prompt. And “Increase the overlap between the chunks” changes how the documents were chunked, which does not pick the best five.