Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Oracle · Agentic AI Foundations

The vector search workflow

Agentic AI Foundations · Lesson 17 of 20 · 2:10:32

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.

In this lesson

Prepare for the Oracle Agentic AI Foundations Associate exam (1Z0-1157-26). In this lesson: the five steps of the vector search workflow, chunking and embeddings in the database, HNSW and IVF vector indexes, and grounding an agent in your own data. Includes three original practice questions, with Fairhaven Furniture, a fictional furniture seller, as the example.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Thousands of guides

Fairhaven keeps thousands of PDF guides: assembly steps, care instructions, and warranty terms, for every product line. Its support agent must answer from them, and quote the right passage. The guides are already stored in Oracle AI Database, so the whole pipeline can run there.

Five steps

Oracle AI Vector Search follows five steps. First, generate embeddings, inside the database or with an external provider. Second, store them in VECTOR columns, next to your business data. Third, create vector indexes, so that searches stay fast as the data grows. Fourth, run similarity searches with the vector distance function, combined with regular SQL filters. And fifth, use the results for retrieval-augmented generation, by passing the best chunks to a model.

Two ways to embed

There are two ways to generate embeddings. Inside the database, you load an ONNX model, and the vector embedding SQL function creates vectors with no network call, so the data never leaves the database. With an external provider, PL/SQL packages call the provider's REST API, which gives access to other models, but the text travels to that provider.

Text, chunks, vectors

Long documents need chunking first, because an embedding model reads a limited number of tokens at a time. The DBMS vector chain package offers chainable functions for this. UTL to text turns PDF or Word files into plain text. UTL to chunks splits that text into chunks. And UTL to embeddings creates a vector for each chunk. You can chain all three in one insert statement, from a PDF to stored vectors.

Chunk size and overlap

You control how the text is split. You set a maximum size for each chunk, counted in characters, words, or tokens, and where to cut, like at the end of a sentence or a paragraph. An overlap repeats a little text from one chunk to the next, so that an idea that crosses a border is not lost. Chunks that are too large blur several topics into one vector, and chunks that are too small lose their context.

Why vector indexes

Without an index, a similarity search compares the question with every vector, which is an exact search. That is fine for thousands of vectors, but slow for millions. A vector index finds approximate nearest neighbors, much faster, and it may miss a few of the exact closest rows. You set a target accuracy, on the index or on each search, to balance speed and quality.

HNSW and IVF

Oracle offers two kinds of vector index. HNSW, which stands for Hierarchical Navigable Small World, builds a graph in memory: upper layers have few links for long jumps, lower layers have more links for accuracy, and it is the fastest. IVF, for Inverted File Flat, groups vectors into partitions around centroids, and a search scans only the nearest partitions, so probing more partitions gives more accuracy. And hybrid vector indexes combine text search and vector search in one index.

Creating an index

You create an index with create vector index, and its organization sets the kind: an in-memory neighbor graph for HNSW, or neighbor partitions for IVF. The distance clause sets the metric, and it should be the one that your embedding model recommends. A search must use the same metric as the index, otherwise the index cannot be used, and the database falls back to an exact search. And a search can ask for its own target accuracy, like eighty percent.

Grounding an agent

Now, the support agent. Its search tool embeds the question with the same model as the chunks, runs one SQL statement with the vector distance and the business filters, and returns the best chunks with their source. The model then answers from those passages, and cites them. In Python, the python-oracledb driver connects in thin mode by default, so there is no Oracle client to install.

The search tool

Here is the tool. The docstring tells the model when to call it, and the question is embedded with the chunks' model. The SQL statement filters on the product line, orders by cosine distance, and keeps the four closest chunks. And the tool returns the passages with their source, ready for the model to cite.

Recap

Let's recap. The workflow is: embed, store, index, search, and use the results for RAG. Embed inside the database with an ONNX model, or call a provider, and chain text extraction, chunking, and embeddings in one insert statement. HNSW is an in-memory graph, IVF scans the nearest partitions, and a search must use the index's metric. And a grounded agent embeds the question with the same model, and filters in SQL before it ranks by distance.

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.

  1. Fairhaven’s warranty files contain customer details, and the security team says that their text must never leave the database, not even to create embeddings. How should the team generate the embeddings?

    • Call a provider’s embedding API from PL/SQL
    • Create an HNSW index on the warranty table
    • Load an ONNX model into the database
    • Export the files and embed them in a script
    Show the answer

    Load an ONNX model into the database

    An ONNX model loaded into the database creates the embeddings inside it, with no network call. “Call a provider’s embedding API from PL/SQL” sends the text to the provider's API. “Create an HNSW index on the warranty table” builds a search structure, but it needs embeddings first. And “Export the files and embed them in a script” would move the text out of the database, which is exactly what the security team forbids.

  2. Fairhaven built an HNSW index on forty million chunks, with the cosine metric. Its new search code orders by Euclidean distance, and every search is now slow. What should the developer change?

    • Use the cosine metric in the search
    • Rebuild the index as an IVF index
    • Fetch more rows in each search
    • Lower the target accuracy of the search
    Show the answer

    Use the cosine metric in the search

    With a different metric, the index cannot be used, so the database falls back to an exact search over every vector. “Rebuild the index as an IVF index” would rebuild a structure that the search still ignores. “Fetch more rows in each search” would make each search even heavier. And “Lower the target accuracy of the search” would trade accuracy for speed, but only once the index is used.

  3. Fairhaven’s support agent answers a question about the Larch sofa, but it quotes the assembly guide of a different sofa, whose wording is almost the same. What should the team change?

    • Switch from cosine to dot product distance
    • Fetch more chunks from each search
    • Add an HNSW index on the chunks
    • Filter on the product in the SQL statement
    Show the answer

    Filter on the product in the SQL statement

    The WHERE clause on the product keeps only that sofa's chunks, before the distance ranks them. “Switch from cosine to dot product distance” changes how close two texts look, but both guides stay close. “Fetch more chunks from each search” would return even more passages from the wrong guide. And “Add an HNSW index on the chunks” speeds up the search, without restricting it to the right product.