Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Oracle · Agentic AI for Oracle AI Database Professional

Exact Similarity Search

Agentic AI for Oracle AI Database Professional · Lesson 5 of 20 · 27:24

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 Agentic AI for Oracle AI Database Professional exam (1Z0-1159-26). In this lesson: exact search with ORDER BY VECTOR_DISTANCE and FETCH EXACT FIRST, filters and joins in the same query, and when to choose exact or approximate search. 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.

No near miss

Ambergate's warranty team must find the five past cases closest to a new complaint, and for legal reasons the list must be complete, with no near miss left out. The table holds two hundred thousand cases, so precision matters more than speed. This lesson covers exact similarity search in SQL, filters and joins, and when an exact search is the right choice.

Exact search

An exact similarity search compares the query vector with every candidate vector, and returns the true nearest neighbors. It is also called a flat search, or a k nearest neighbors search. Its accuracy is perfect, since no vector is skipped. Its cost grows with the number of vectors, which is fine for small or filtered sets, and slow for many millions of rows.

The query

The query orders the rows by VECTOR_DISTANCE, between each stored vector and the question's vector. The fetch exact first clause keeps only the closest rows, here the first five. The question's vector can come from a bind variable, or from VECTOR_EMBEDDING, right inside the statement. And the word exact makes sure that no vector index is used, even when one exists.

Filters and joins

Since it is plain SQL, the same statement can filter with a where clause, on the product line or the date a case was opened. It can join other tables, like customers or parts, and read JSON columns. The top five are then the closest among the rows that qualify, all in one statement.

Exact or approximate

Exact search is the right choice when results must be complete, when the data set is small, or when a filter leaves few rows. Approximate search, with a vector index, is the right choice for millions of vectors, when a little accuracy can be traded for speed. Exact search is also the reference for measuring the accuracy of an index, as you will see in lesson eight. And the fetch exact clause turns any query back into an exact search, which helps when you compare results.

Recap

Let's recap. An exact search compares every candidate vector, so its accuracy is perfect and its cost grows with the data. The query orders by VECTOR_DISTANCE and keeps the closest rows with fetch exact first. The question's vector comes from a bind variable or from VECTOR_EMBEDDING in the same statement. Where clauses, joins, and JSON combine with the search, and the top rows are taken among those that qualify. And without the word exact, Autonomous AI Database may run an approximate search when an index exists.

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. On Autonomous AI Database, a developer writes FETCH FIRST 5 ROWS ONLY, without EXACT, on a column that has a vector index. What may happen?

    • An error, since a keyword is missing
    • An exact search, as always
    • An approximate search through the index
    • A full table scan with no ordering at all
    Show the answer

    An approximate search through the index

    On Autonomous AI Database, when neither exact nor approximate is written, an approximate search through the index is attempted if one exists. “An error, since a keyword is missing” is wrong, since both keywords are optional. “An exact search, as always” is what the word exact guarantees, and it was left out. And “A full table scan with no ordering at all” is wrong, because the order by clause still sorts the rows by distance.

  2. Ambergate wants the ten washer cases closest to a complaint, among the cases opened this year only. What is the simplest way?

    • Fetch 1,000 rows, then filter in Python
    • Copy this year’s cases to a vector store
    • Create one table for each year of cases
    • Filter with a WHERE clause in the query
    Show the answer

    Filter with a WHERE clause in the query

    A where clause filters the rows in the same statement, and the ten closest are taken among the cases that qualify. “Fetch 1,000 rows, then filter in Python” moves far too many rows to the application, and it can still miss cases. “Copy this year’s cases to a vector store” adds a second system to keep in sync. And “Create one table for each year of cases” changes the schema for a simple filter.

  3. Ambergate’s compliance team reviews a sample of answers from its vector index, and needs the true nearest neighbors for each sample question, to compare. What should the query use?

    • A higher target accuracy on the index
    • FETCH EXACT FIRST, with the same metric
    • A hint that suggests the vector index
    • Fewer rows in the FETCH clause of the query
    Show the answer

    FETCH EXACT FIRST, with the same metric

    Fetch exact first compares every vector, so it returns the true nearest neighbors for the comparison. “A higher target accuracy on the index” raises the accuracy, but an index search is still approximate. “A hint that suggests the vector index” pushes the optimizer toward the index, which is the opposite of what is needed. And “Fewer rows in the FETCH clause of the query” shortens the list, but it does not make it exact.