RAG and agents on OCI
OCI AI Foundations · Lesson 13 of 16 · 1:31: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 Oracle Cloud Infrastructure AI Foundations Associate exam (1Z0-1122-26). In this lesson: semantic search with embeddings (cosine similarity, Euclidean distance, dot product, and top k), RAG on OCI (hybrid search, rerank, knowledge bases, the RAG tool of OCI Enterprise AI Agents, and File Search), agents built with the OCI Responses API (File Search, Code Interpreter, function calling, MCP calling, and short-term and long-term memory), and governance with IAM policies, private endpoints, and guardrails (content moderation, prompt injection detection, PII detection, inform and block modes). Includes three original practice questions, with Willowmere Motors, a fictional network of car dealerships and repair shops, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Answers, actions, and safety
Willowmere's assistant must now answer from the company's own manuals and warranty policies, not just from what the model learned. It must also take actions, like booking a service appointment. And the security team wants to be sure that it never leaks customer data, or follows hidden instructions.
Semantic search
Keyword search misses synonyms: a search for car battery can miss a page that only says vehicle power cell. Semantic search compares meanings instead: an embedding model turns each chunk of a document, and the question, into vectors, and the closest vectors belong to the most similar texts. Closeness is measured with cosine similarity, which compares the angle between vectors, with Euclidean distance, or with the dot product. The search returns the top k closest chunks, and the documents and the question must use the same embedding model, or their vectors cannot be compared.
RAG on OCI
Retrieval-augmented generation, or RAG, builds on semantic search, in three steps. Retrieve finds the most relevant chunks, augment adds them to the prompt, and generate lets the model answer from them, which grounds the answer, and reduces hallucinations. Many systems use hybrid search, which combines keyword and semantic search, and a rerank model can then reorder the results: embeddings favor recall, finding everything relevant, and rerank favors precision, putting the best first. On OCI, the documents sit in a knowledge base, backed by sources like Object Storage, OpenSearch, or Oracle AI Database, where they are ingested and indexed. You can build RAG with no code, with the RAG tool of OCI Enterprise AI Agents, or in code, with the File Search tool of the OCI Responses API.
Agents, tools, and memory
An agent is a model that can act: it reasons about a goal, calls tools, observes the results, and repeats until the task is done. On OCI, the OCI Responses API builds agents in code: it's compatible with the OpenAI Responses API, it keeps the data in OCI, and it needs a project. It offers tools like File Search, Code Interpreter, Function Calling, and MCP Calling. With function calling, the model asks for a function, your application runs it, and sends the result back in a second call, while with MCP calling, OCI calls the tools of a remote MCP server directly. Memory keeps the context: short-term memory carries the conversation, for example by passing the previous response ID, and long-term memory keeps facts about a user across conversations.
Governance and guardrails
Governance keeps all of this under control. Identity and Access Management policies give groups verbs, from inspect, the lowest, to manage, the highest, on resources in a compartment, following least privilege. Private endpoints keep traffic inside your virtual cloud network, and OCI Generative AI does not keep your inference data, or share it with model providers. Guardrails check inputs and outputs: content moderation flags harmful content, prompt injection detection catches instructions like ignore previous instructions, even when they are hidden in documents, and PII detection finds personal data, like names, email addresses, or phone numbers. Each guardrail can run in inform mode, which returns its results while the request goes on, or in block mode, which rejects the request with an error.
Recap
Let's recap. Semantic search compares embeddings, with cosine, Euclidean, or dot product measures, and documents and questions need the same embedding model. RAG retrieves relevant chunks, adds them to the prompt, and grounds the answer, with hybrid search and rerank for better results. The OCI Responses API builds agents with tools like File Search, Code Interpreter, function calling, and MCP calling, and memory keeps the context across turns. IAM policies, private endpoints, and inference data that is not kept or shared protect the service. And guardrails moderate content, detect prompt injection, and find personal data, in inform or block mode.
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.
Willowmere stored its manuals as vectors made by one embedding model, but it embeds the customers’ questions with another model. The search results are poor. What is the most likely cause?
- The top k setting returns too many chunks to read
- Hybrid search needs keywords that the manuals lack
- Vectors from two different models are not comparable
- The chat model’s temperature is too low for search
Show the answer
Vectors from two different models are not comparable
The documents and the questions must use the same embedding model, or their vectors are not comparable. “The top k setting returns too many chunks to read” is a tuning setting, and it would not explain poor matches on every question. “Hybrid search needs keywords that the manuals lack” is wrong, because semantic search compares meanings, and does not need shared keywords. And “The chat model’s temperature is too low for search” is a setting of the chat model, which takes no part in the search itself.
Willowmere’s assistant must book service appointments through the company’s own booking system, which Willowmere’s application calls itself. Which tool of the OCI Responses API fits?
- Function Calling
- File Search
- MCP Calling
- Code Interpreter
Show the answer
Function Calling
With function calling, the model asks for the booking function, and Willowmere's application runs it, then sends back the result. “File Search” searches documents in a vector store, and does not book anything. “MCP Calling” would have OCI call a remote MCP server directly, not Willowmere's application. And “Code Interpreter” runs code that the model writes, for calculations and data, not calls to the booking system.
A customer uploads a document to Willowmere’s assistant, with a hidden line that tells the model to reveal its system prompt. Which guardrail is designed to catch this?
- Content moderation of the input
- Personal data (PII) detection
- A private endpoint in the network
- Prompt injection detection
Show the answer
Prompt injection detection
Prompt injection detection looks for instructions that try to override the system, including indirect ones hidden in documents. “Content moderation of the input” is for harmful content, like hate or violence. “Personal data (PII) detection” is for personal data, like names or phone numbers. And “A private endpoint in the network” keeps network traffic private, but it does not inspect what prompts say.