Monday, November 30, 2026

Exploring Hybrid Vector Search in Oracle AI Database 26ai — Part III

In the previous post, we used a hybrid vector index to search park descriptions using semantic search and keyword search separately. The semantic search returned descriptions related to the meaning of a question, while the keyword search returned descriptions matching an Oracle Text expression.

For the following examples, we are going to use the same PARKS_INFO table and PARK_DESCRIPTION_HVI index. This time, we will combine the two searches and examine how their scores affect the order of the returned results.

Consider someone looking for a park where they can learn about prehistoric mammals. They might ask the following question:

Where can I learn about prehistoric mammals and ancient animal remains?

The question provides the text for semantic search. Along with this question, we can supply a keyword expression to search for descriptions containing fossil, fossils, or mammoths.

fossil OR fossils OR mammoths

The following statement supplies both the semantic question and the keyword expression to DBMS_HYBRID_VECTOR.SEARCH. We will use DOCUMENT mode to return park-level results and MAX to represent each document using its strongest retrieved chunk score.

demo@ADB26ai> select json_serialize(
  2      dbms_hybrid_vector.search(
  3          json('{
  4              "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  5              "search_fusion": "UNION",
  6              "search_scorer": "RSF",
  7              "vector": {
  8                  "search_text": "Where can I learn about prehistoric mammals and ancient animal remains?",
  9                  "search_mode": "DOCUMENT",
 10                  "aggregator": "MAX",
 11                  "score_weight": 1
 12              },
 13              "text": {
 14                  "contains": "fossil OR fossils OR mammoths",
 15                  "score_weight": 1
 16              },
 17              "return": {
 18                  "topN": 5,
 19                  "values": [
 20                      "rowid",
 21                      "score",
 22                      "vector_score",
 23                      "text_score"
 24                  ]
 25              }
 26          }
 27          ')
 28      )
 29      returning clob pretty
 30  ) as search_results;

SEARCH_RESULTS
--------------------------------------------------------------------------------
[
  {
    "rowid": "AAQVAeABUAAPJSyABC",
    "score": 41.18,
    "vector_score": 60.35,
    "text_score": 22
  },
  {
    "rowid": "AAQVAeABUAAPJS5AAy",
    "score": 40.02,
    "vector_score": 71.04,
    "text_score": 9
  },
  {
    "rowid": "AAQVAeABUAAPHl8AAF",
    "score": 39.19,
    "vector_score": 70.37,
    "text_score": 8
  },
  {
    "rowid": "AAQVAeABUAAPJS5AAI",
    "score": 38.02,
    "vector_score": 67.04,
    "text_score": 9
  },
  {
    "rowid": "AAQVAeABUAAPJSpAAe",
    "score": 37.68,
    "vector_score": 67.35,
    "text_score": 8
  }
]

Notice that the request contains both a vector section and a text section. The vector section supplies the question for semantic search, and text.contains supplies the Oracle Text expression.

The response contains three scores. VECTOR_SCORE represents semantic relevance, TEXT_SCORE represents keyword relevance, and SCORE is the final combined score used to rank the results.

The SEARCH_FUSION parameter is set to UNION. This allows candidates retrieved by either search to participate in the combined result set. SEARCH_SCORER is set to RSF, or Relative Score Fusion, which combines the two scores using the specified weights. The SEARCH documentation describes these parameters in more detail.

To understand the final ranking, let us look at the first two rows from the JSON response.

ROWID                 VECTOR_SCORE  TEXT_SCORE  FINAL_SCORE
--------------------  ------------  ----------  -----------
AAQVAeABUAAPJSyABC            60.35          22        41.18
AAQVAeABUAAPJS5AAy            71.04           9        40.02

The table above presents the captured JSON values in a compact format.

As you can see, the first result has a vector score of 60.35, while the second has a higher vector score of 71.04. However, the first result appears above the second in the final ranking.

The difference comes from the keyword scores. The first description has a text score of 22, compared with 9 for the second description. The first result discusses Columbian mammoths and an ancient nursery herd in Texas. The second is the Hagerman description, which discusses Pliocene habitats and extinct animals.

Both score weights are explicitly set to 1 in this request. The displayed final scores therefore follow an equal-weight combination of the semantic and keyword scores.

Final score =
    (vector_score × vector_weight + text_score × text_weight)
    -------------------------------------------------------
                  vector_weight + text_weight

For the first result, the calculation is:

(60.35 × 1 + 22 × 1) / (1 + 1)
    = 41.175

Displayed score: 41.18

For the second result:

(71.04 × 1 + 9 × 1) / (1 + 1)
    = 40.02

The stronger keyword score moves the mammoth description above the document with the stronger semantic score. This illustrates how the two relevance signals contribute to the final ordering. Oracle describes the RSF calculation in Understand Hybrid Search.

This example shows the effect of combining the scores for this particular question. To determine whether the combined ranking is more useful for an application, we would need to evaluate a representative set of questions and expected results.

Using INTERSECT to combine the results

The previous query used UNION to allow candidates from either search. We can change SEARCH_FUSION to INTERSECT when we want to retain candidates that appear in both retrieved result sets.

The following query makes that change. The semantic question, keyword expression, score weights, and requested number of results remain the same.

demo@ADB26ai> select json_serialize(
  2      dbms_hybrid_vector.search(
  3          json('{
  4              "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  5              "search_fusion": "INTERSECT",
  6              "search_scorer": "RSF",
  7              "vector": {
  8                  "search_text": "Where can I learn about prehistoric mammals and ancient animal remains?",
  9                  "search_mode": "DOCUMENT",
 10                  "aggregator": "MAX",
 11                  "score_weight": 1
 12              },
 13              "text": {
 14                  "contains": "fossil OR fossils OR mammoths",
 15                  "score_weight": 1
 16              },
 17              "return": {
 18                  "topN": 5,
 19                  "values": [
 20                      "rowid",
 21                      "score",
 22                      "vector_score",
 23                      "text_score"
 24                  ]
 25              }
 26          }
 27          ')
 28      )
 29      returning clob pretty
 30  ) as search_results;

SEARCH_RESULTS
--------------------------------------------------------------------------------
[
  {
    "rowid": "AAQVAeABUAAPJSyABC",
    "score": 41.18,
    "vector_score": 60.35,
    "text_score": 22
  },
  {
    "rowid": "AAQVAeABUAAPJS5AAy",
    "score": 40.02,
    "vector_score": 71.04,
    "text_score": 9
  },
  {
    "rowid": "AAQVAeABUAAPHl8AAF",
    "score": 39.19,
    "vector_score": 70.37,
    "text_score": 8
  },
  {
    "rowid": "AAQVAeABUAAPJS5AAI",
    "score": 38.02,
    "vector_score": 67.04,
    "text_score": 9
  },
  {
    "rowid": "AAQVAeABUAAPJSpAAe",
    "score": 37.68,
    "vector_score": 67.35,
    "text_score": 8
  }
]

The query returns the same top five documents, in the same order and with the same scores, as the preceding UNION query.

This means the five leading results in this run also survive INTERSECT. It does not mean that UNION and INTERSECT are equivalent, or that the complete candidate sets are identical. A different question or a keyword expression with less overlap could produce different results.

The distinction is in which retrieved candidates qualify. UNION retains candidates from either search, while INTERSECT retains candidates found in both. This applies to the retrieved candidate sets; it is not an unlimited semantic comparison against every document in the table.

Returning the matching passages

The previous queries returned document-level results. An application may also need the relevant passage itself, for example when displaying the text that supports a search result.

For the following query, we change SEARCH_MODE to CHUNK and request CHUNK_ID and CHUNK_TEXT along with the scores. We continue using the same question, keyword expression, INTERSECT operator, and RSF scoring method.

demo@ADB26ai> select json_serialize(
  2      dbms_hybrid_vector.search(
  3          json('{
  4              "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  5              "search_fusion": "INTERSECT",
  6              "search_scorer": "RSF",
  7              "vector": {
  8                  "search_text": "Where can I learn about prehistoric mammals and ancient animal remains?",
  9                  "search_mode": "CHUNK",
 10                  "score_weight": 1
 11              },
 12              "text": {
 13                  "contains": "fossil OR fossils OR mammoths",
 14                  "score_weight": 1
 15              },
 16              "return": {
 17                  "topN": 5,
 18                  "values": [
 19                      "rowid",
 20                      "chunk_id",
 21                      "chunk_text",
 22                      "score",
 23                      "vector_score",
 24                      "text_score"
 25                  ]
 26              }
 27          }
 28          ')
 29      )
 30      returning clob pretty
 31  ) as search_results;

The first result is shown below.

SEARCH_RESULTS
--------------------------------------------------------------------------------
[
  {
    "rowid": "AAQVAeABUAAPJS5AAy",
    "chunk_id": "1",
    "chunk_text": "During the Pliocene, this place looked quite different. Lush wetlands,
forests, and grasslands provided excellent habitat for a variety of animals.
From fascinating, now-extinct creatures like the saber-toothed cat, mastodon,
and ground sloth, to more familiar animals like horses, beavers, and birds,
the scientific study of Pliocene fossils is the key to Hagerman.
",
    "score": 40.02,
    "vector_score": 71.04,
    "text_score": 9
  }
]

Only the first result is shown. The array is shortened for presentation, and the passage is line-wrapped for readability.

The response now includes the matching passage as well as its parent ROWID and chunk identifier. The Hagerman passage discusses extinct animals, including the saber-toothed cat, mastodon, and ground sloth, which helps us understand its relationship to the question.

The scores for all five returned chunks are shown below.

ROWID                 CHUNK_ID  VECTOR_SCORE  TEXT_SCORE  FINAL_SCORE
--------------------  --------  ------------  ----------  -----------
AAQVAeABUAAPJS5AAy            1         71.04           9        40.02
AAQVAeABUAAPHl8AAF            1         70.37           8        39.19
AAQVAeABUAAPJS5AAI            1         67.04           9        38.02
AAQVAeABUAAPJSpAAe            1         67.35           8        37.68
AAQVAeABUAAPJSgABI            1         64.74           9        36.87

This is a compact presentation of the captured JSON results, with the passage text omitted.

Notice that Hagerman is now the first result. The mammoth description that ranked first in document mode does not appear in this top-five chunk result set. The captured output shows a difference between the two requests, but it does not establish the exact cause. Examining a larger candidate set would be a useful next step.

In hybrid chunk mode, the keyword score comes from the parent document. A passage returned by the query should therefore not automatically be assumed to contain every keyword that matched its parent. See the DBMS_HYBRID_VECTOR documentation for the search-mode and fusion details.

These examples use the same hybrid vector index to combine meaning-based retrieval with keyword relevance. SEARCH_FUSION controls which retrieved candidates remain, SEARCH_SCORER controls how they are ranked, and SEARCH_MODE controls whether the results represent documents or individual passages.

For the next experiment, we can keep the question and keyword expression unchanged and adjust the score weights. Changing one setting at a time will make it easier to see how increasing keyword or semantic influence affects the final results.

Thursday, November 19, 2026

Streaming Window Table Functions in Oracle AI Database 26ai

 When working with time-based data, we often need to calculate totals over specific intervals. For example, we might want sales totals for every ten minutes, overlapping totals calculated every five minutes, or customer activity grouped into sessions.

Oracle AI Database 26ai provides streaming window table functions for these requirements: TUMBLE, HOP, CUMULATE, and SESSIONS.

These functions return the input columns along with WINDOW_START and WINDOW_END. We can then use these boundaries to group and aggregate the data.

In the remainder of this blogpost, I’m going to demonstrate these functions using a small sales dataset, so that we can easily follow how each event gets assigned to a window.

TUMBLE — fixed-size windows

First, let us look at TUMBLE, which divides the data into fixed-size, non-overlapping windows.

TUMBLE: separate, fixed-size buckets

Think: “Sales for each 10-minute period.”

10:00 ├─────────────┤ 10:10 ├─────────────┤ 10:20

  A B C                    D E

Each event belongs to one bucket.

The following example contains five sales events. We will assign them to ten-minute windows.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select *
 13  from tumble(
 14      sales,
 15      columns(event_time),
 16      interval '10' minute
 17* );

EVENT_ID    EVENT_TIME                            AMOUNT WINDOW_START                       WINDOW_END
___________ __________________________________ _________ __________________________________ __________________________________
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
D           11-NOV-26 10.12.00.000000000 AM           40 11-NOV-26 10.10.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.10.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM

As you can see, events A, B, and C belong to the window starting at 10:00 and ending at 10:10. Events D and E belong to the next window, starting at 10:10 and ending at 10:20.

The function assigns window boundaries to each row. To calculate sales totals, we can group the result by these boundaries.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select to_char(window_start, 'HH24:MI') window_from,
 13         to_char(window_end,   'HH24:MI') window_to,
 14         count(*) sale_count,
 15         sum(amount) total_amount
 16     , listagg(event_id,'->') within group(order by event_time) event_ids
 17  from tumble(
 18      sales,
 19      columns(event_time),
 20      interval '10' minute
 21  )
 22  group by window_start, window_end
 23* order by window_start;

WINDOW_FROM    WINDOW_TO       SALE_COUNT    TOTAL_AMOUNT EVENT_IDS
______________ ____________ _____________ _______________ ____________
10:00          10:10                    3              60 A->B->C
10:10          10:20                    2              90 D->E

The first window contains three sales with a total amount of 60, while the second contains two sales with a total amount of 90.

I have included LISTAGG in the query so that we can see which events contributed to each total.

HOP — overlapping windows

Now, suppose we want ten-minute sales totals, with a new window starting every five minutes.

HOP: overlapping buckets

Think: “Calculate 10-minute sales totals, starting a new window every 5 minutes.”

09:55 ├─────────────┤ 10:05

   10:00 ├─────────────┤ 10:10

  10:05 ├─────────────┤ 10:15

10:10 ├─────────────┤ 10:20

The window stays 10 minutes wide; its start advances by 5 minutes. An event can appear in multiple windows.

We can use HOP for this requirement. The first interval specifies the slide between window starts, while the second specifies the window size.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select *
 13  from hop(
 14      sales,
 15      columns(event_time),
 16      interval '5' minute,   -- Start a window every 5 minutes
 17  interval '10' minute   -- Each window covers 10 minutes
 18  )
 19* order by window_start;

EVENT_ID    EVENT_TIME                            AMOUNT WINDOW_START                       WINDOW_END
___________ __________________________________ _________ __________________________________ __________________________________
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 09.55.00.000000000 AM    11-NOV-26 10.05.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 09.55.00.000000000 AM    11-NOV-26 10.05.00.000000000 AM
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.05.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
D           11-NOV-26 10.12.00.000000000 AM           40 11-NOV-26 10.05.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
D           11-NOV-26 10.12.00.000000000 AM           40 11-NOV-26 10.10.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.10.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.15.00.000000000 AM    11-NOV-26 10.25.00.000000000 AM

10 rows selected.

Notice that our five input events produce ten rows. Each event belongs to two overlapping windows in this example.

For instance, event A at 10:01 belongs to both the 09:55–10:05 window and the 10:00–10:10 window.

Let us now aggregate these rows.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select to_char(window_start, 'HH24:MI') window_from,
 13         to_char(window_end,   'HH24:MI') window_to,
 14         count(*) sale_count,
 15         sum(amount) total_amount
 16     , listagg(event_id,'->') within group(order by event_time) event_ids
 17  from hop(
 18      sales,
 19      columns(event_time),
 20      interval '5' minute,   -- Start a window every 5 minutes
 21      interval '10' minute   -- Each window covers 10 minutes
 22  )
 23  group by window_start, window_end
 24* order by window_start;

WINDOW_FROM    WINDOW_TO       SALE_COUNT    TOTAL_AMOUNT EVENT_IDS
______________ ____________ _____________ _______________ ____________
09:55          10:05                    2              30 A->B
10:00          10:10                    3              60 A->B->C
10:05          10:15                    2              70 C->D
10:10          10:20                    2              90 D->E
10:15          10:25                    1              50 E

The window remains ten minutes wide, while its start advances by five minutes.

Also notice that the first window starts at 09:55, even though the first event occurs at 10:01. The windows follow their time alignment rather than starting at the first event.

Since these windows overlap, the same sale contributes to multiple totals. Adding all the window totals would therefore count the same sales more than once.

CUMULATE — growing windows with a shared start

Next, let us calculate accumulated sales at five-minute checkpoints within a twenty-minute block.

CUMULATE: growing buckets with a shared start

Think: “Within each 20-minute block, show the accumulated sales at 5-minute checkpoints.”

Unlike HOP, the start stays fixed while the end moves forward. After reaching the maximum size, a new block begins.

With CUMULATE, the window start remains fixed while the end advances by the specified step, until the maximum window size is reached.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select *
 13  from cumulate(
 14      sales,
 15      columns(event_time),
 16      interval '5' minute,   -- Grow by 5 minutes
 17      interval '20' minute   -- Stop at 20 minutes
 18  )
 19* order by window_start,window_end,event_id;

EVENT_ID    EVENT_TIME                            AMOUNT WINDOW_START                       WINDOW_END
___________ __________________________________ _________ __________________________________ __________________________________
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.05.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.05.00.000000000 AM
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
D           11-NOV-26 10.12.00.000000000 AM           40 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
D           11-NOV-26 10.12.00.000000000 AM           40 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM

14 rows selected.

As you can see, all the windows start at 10:00, but their end times advance through 10:05, 10:10, 10:15, and 10:20.

Events A and B appear in all four windows. Event E appears only in the final window because it occurs at 10:16.

Aggregating the result makes the accumulated totals easier to follow.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select to_char(window_start, 'HH24:MI') window_from,
 13         to_char(window_end,   'HH24:MI') window_to,
 14         count(*) sale_count,
 15         sum(amount) total_amount
 16    , listagg(event_id,'->') within group(order by event_time) event_ids
 17  from cumulate(
 18      sales,
 19      columns(event_time),
 20      interval '5' minute,   -- Grow by 5 minutes
 21      interval '20' minute   -- Stop at 20 minutes
 22  )
 23  group by window_start, window_end
 24* order by window_start, window_end;

WINDOW_FROM    WINDOW_TO       SALE_COUNT    TOTAL_AMOUNT EVENT_IDS
______________ ____________ _____________ _______________ ________________
10:00          10:05                    2              30 A->B
10:00          10:10                    3              60 A->B->C
10:00          10:15                    4             100 A->B->C->D
10:00          10:20                    5             150 A->B->C->D->E

The accumulated amount grows from 30 to 60, then to 100, and finally to 150.

Let us now change the maximum window size from twenty minutes to fifteen minutes. The inline comment in the original transcript still says twenty minutes; the actual interval supplied is fifteen minutes.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select *
 13  from cumulate(
 14      sales,
 15      columns(event_time),
 16      interval '5' minute,   -- Grow by 5 minutes
 17      interval '15' minute   -- Stop at 20 minutes
 18  )
 19* order by window_start, window_end, event_id;

EVENT_ID    EVENT_TIME                            AMOUNT WINDOW_START                       WINDOW_END
___________ __________________________________ _________ __________________________________ __________________________________
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.05.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.05.00.000000000 AM
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.10.00.000000000 AM
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
D           11-NOV-26 10.12.00.000000000 AM           40 11-NOV-26 10.00.00.000000000 AM    11-NOV-26 10.15.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.15.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.15.00.000000000 AM    11-NOV-26 10.25.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.15.00.000000000 AM    11-NOV-26 10.30.00.000000000 AM

12 rows selected.

Here, event E belongs to the next block, starting at 10:15. It appears in the growing windows ending at 10:20, 10:25, and 10:30.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select to_char(window_start, 'HH24:MI') window_from,
 13         to_char(window_end,   'HH24:MI') window_to,
 14         count(*) sale_count,
 15         sum(amount) total_amount
 16    , listagg(event_id,'->') within group(order by event_time) event_ids
 17  from cumulate(
 18      sales,
 19      columns(event_time),
 20      interval '5' minute,   -- Grow by 5 minutes
 21      interval '15' minute   -- Stop at 20 minutes
 22  )
 23  group by window_start, window_end
 24* order by window_start, window_end;

WINDOW_FROM    WINDOW_TO       SALE_COUNT    TOTAL_AMOUNT EVENT_IDS
______________ ____________ _____________ _______________ _____________
10:00          10:05                    2              30 A->B
10:00          10:10                    3              60 A->B->C
10:00          10:15                    4             100 A->B->C->D
10:15          10:20                    1              50 E
10:15          10:25                    1              50 E
10:15          10:30                    1              50 E

6 rows selected.

The accumulated total restarts for the new block. Since E is the only event in that block, all three windows have a total of 50.

SESSIONS — windows based on inactivity

So far, we have used fixed intervals to determine window boundaries. Next, let us group events based on the time between consecutive events.

SESSIONS: buckets defined by inactivity

Think: “Treat events as one session until there is more than 4 minutes of inactivity.”

Look at the gaps:

A 10:01 → B 10:04 → C 10:07    D 10:12 → E 10:16

3 min       3 min     ↑         4 min

   5-minute gap

   New session

The gap is checked between consecutive events. A gap equal to 4 minutes stays in the same session; a larger gap starts another.

The following query uses a four-minute inactivity gap.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select *
 13  from sessions(
 14      sales,
 15      columns(event_time),
 16      interval '4' minute
 17  )
 18* ;

EVENT_ID    EVENT_TIME                            AMOUNT WINDOW_START                       WINDOW_END
___________ __________________________________ _________ __________________________________ __________________________________
A           11-NOV-26 10.01.00.000000000 AM           10 11-NOV-26 10.01.00.000000000 AM    11-NOV-26 10.11.00.000000000 AM
B           11-NOV-26 10.04.00.000000000 AM           20 11-NOV-26 10.01.00.000000000 AM    11-NOV-26 10.11.00.000000000 AM
C           11-NOV-26 10.07.00.000000000 AM           30 11-NOV-26 10.01.00.000000000 AM    11-NOV-26 10.11.00.000000000 AM
D           11-NOV-26 10.12.00.000000000 AM           40 11-NOV-26 10.12.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM
E           11-NOV-26 10.16.00.000000000 AM           50 11-NOV-26 10.12.00.000000000 AM    11-NOV-26 10.20.00.000000000 AM

Let us look at the gaps to understand the above output.

A occurs at 10:01, B at 10:04, and C at 10:07. Both consecutive gaps are three minutes, so all three events belong to the same session.

D occurs at 10:12, five minutes after C. Since this exceeds the four-minute gap, D starts a new session.

E occurs at 10:16, exactly four minutes after D. It remains in the same session because a new session starts only when the gap exceeds four minutes.

Also notice the window end times. The first session’s last event occurs at 10:07, while its WINDOW_END is 10:11. The second session’s last event occurs at 10:16, while its WINDOW_END is 10:20.

In this output, the session end includes the four-minute inactivity allowance after the last event. The interval controls the gap between events, rather than the total session duration.

Let us now calculate the totals for each session.

demo@ADB26AI> with sales (event_id, event_time, amount) as (
  2      select 'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11  )
 12  select to_char(min(event_time), 'HH24:MI') first_event,
 13         to_char(max(event_time), 'HH24:MI') last_event,
 14         count(*) event_count,
 15         sum(amount) total_amount
 16     , listagg(event_id,'->') within group(order by event_time) event_ids
 17  from sessions(
 18      sales,
 19      columns(event_time),
 20      interval '4' minute
 21  )
 22  group by window_start, window_end
 23* order by min(event_time);

FIRST_EVENT    LAST_EVENT       EVENT_COUNT    TOTAL_AMOUNT EVENT_IDS
______________ _____________ ______________ _______________ ____________
10:01          10:07                      3              60 A->B->C
10:12          10:16                      2              90 D->E

Here, FIRST_EVENT and LAST_EVENT show the actual activity times. The first session contains three events totalling 60, while the second contains two events totalling 90.

Separate sessions for each customer

As a final step of the demonstration, let us calculate sessions independently for each customer.

The following example contains the same five events for two customers. We can use PARTITION BY CUST_ID inside the SESSIONS call to calculate their session boundaries separately.

demo@ADB26AI> with sales (cust_id,event_id, event_time, amount) as (
  2      select 1 as cust_id,'A', timestamp '2026-11-11 10:01:00', 10 from dual
  3      union all
  4      select 1 as cust_id,'B', timestamp '2026-11-11 10:04:00', 20 from dual
  5      union all
  6      select 1 as cust_id,'C', timestamp '2026-11-11 10:07:00', 30 from dual
  7      union all
  8      select 1 as cust_id,'D', timestamp '2026-11-11 10:12:00', 40 from dual
  9      union all
 10      select 1 as cust_id,'E', timestamp '2026-11-11 10:16:00', 50 from dual
 11      union all
 12      select 2 as cust_id,'A', timestamp '2026-11-11 10:01:00', 10 from dual
 13      union all
 14      select 2 as cust_id,'B', timestamp '2026-11-11 10:04:00', 20 from dual
 15      union all
 16      select 2 as cust_id,'C', timestamp '2026-11-11 10:07:00', 30 from dual
 17      union all
 18      select 2 as cust_id,'D', timestamp '2026-11-11 10:12:00', 40 from dual
 19      union all
 20      select 2 as cust_id,'E', timestamp '2026-11-11 10:16:00', 50 from dual
 21  )
 22  select cust_id,to_char(min(event_time), 'HH24:MI') first_event,
 23         to_char(max(event_time), 'HH24:MI') last_event,
 24         count(*) event_count,
 25         sum(amount) total_amount
 26        , listagg(event_id,'->') within group(order by event_time) event_ids
 27  from sessions(
 28      sales partition by cust_id,
 29      columns(event_time),
 30      interval '4' minute
 31  )
 32  group by cust_id,window_start, window_end
 33  order by min(event_time);

   CUST_ID FIRST LAST_ EVENT_COUNT TOTAL_AMOUNT EVENT_IDS
---------- ----- ----- ----------- ------------ --------------------
         1 10:01 10:07           3           60 A->B->C
         2 10:01 10:07           3           60 A->B->C
         1 10:12 10:16           2           90 D->E
         2 10:12 10:16           2           90 D->E

Each customer has two sessions, calculated independently. One customer’s activity does not extend or otherwise affect another customer’s session.

This makes SESSIONS useful for analysing activity such as customer visits or application interactions, where a period of inactivity determines when one session ends and another begins.

Thursday, November 12, 2026

Exploring Hybrid Vector Search in Oracle AI Database 26ai - Part II

In my earlier post, I explored hybrid vector search in Oracle AI Database.

For this post, let us work through a practical example using park descriptions. We will search the same data in different ways and examine how the results change.

Consider someone looking for a park where they can learn about prehistoric mammals. They might search for fossils, or ask a question such as:

Where can I explore ancient fossils and prehistoric mammals?

These searches express a related interest, but they give the search engine different information. The keyword expression specifies words to match. The question provides text that can be embedded and compared with the meaning of the park descriptions.

Using the execution below, we will explore both approaches and then combine them.

Prepare the hybrid vector index

For this demonstration, we will use the park data from the previous blogpost, The resulting table includes the park name, code, description, location, directions, and weather information. Our searches will use the PARK_DESCRIPTION column.

With the data available, creating a hybrid vector index can be as simple as:

demo@ADB26ai> create hybrid vector index park_description_hvi
  2  on parks_info( park_description )
  3  parameters( 'MODEL MY_DEMO_MODEL');

Index created.

Here, MY_DEMO_MODEL is an embedding model already available in my database.

For the remaining examples, I recreated the index using an explicit vectorizer preference. This gives us visibility into the chunking and vector-index settings used for the demonstration.

demo@ADB26ai> begin
  2     dbms_vector_chain.create_preference(
  3             pref_name => 'MY_HYBRID_INDEX_PREF'
  4             , pref_type => dbms_vector_chain.VECTORIZER
  5             , params => json_object('vector_idxtype' value 'ivf'
  6                                     , 'distance' value 'cosine'
  7                                     , 'accuracy' value 90 , 'model' value 'MY_DEMO_MODEL'
  8                                     , 'by' value 'words' , 'max' value 100
  9                                     , 'overlap' value 0, 'split' value 'recursively'
 10                                     returning json)
 11                             );
 12  end;
 13  /

PL/SQL procedure successfully completed.

The preference specifies word-based chunking with a maximum chunk size of 100 words, no overlap, and recursive splitting. It also selects an IVF vector index with cosine distance and a target search accuracy of 90. This accuracy setting is a vector-search target, rather than a measure of how relevant the answers are to a user. Oracle vectorizer preference documentation

I then recreated the index using this preference:

demo@ADB26ai> create hybrid vector index park_description_hvi
  2  on parks_info( park_description )
  3  parameters( 'VECTORIZER MY_HYBRID_INDEX_PREF');

Index created.

Inspect the generated vector data

Before searching, let us inspect a few rows from the generated vector data:

demo@ADB26ai> select *
  2  from park_description_hvi$VECTORS
  3  fetch first 5 rows only;

DOC_ROWID          DOC_CHUNK_ID DOC_CHUNK_COUNT DOC_CHUNK_OFFSET DOC_CHUNK_LENGTH DOC_CHUNK_TEXT                           DOC_CHUNK_EMBEDDING
------------------ ------------ --------------- ---------------- ---------------- ---------------------------------------- ----------------------------------------
AAQVAeABUAAPJSpAAu            1               1                1              297 Headlines screamed "Gold!" The dream of  [4.77597751E-002,7.22050816E-002,3.07750
AAQVAeABUAAPJSpAA2            1               1                1              390 The ancient geologic landscape of the up [-4.76894975E-002,9.31795128E-003,7.6873
AAQVAeABUAAPJSpAA4            1               1                1              382 Lava Beds National Monument is a land of [4.78412099E-002,2.7518522E-002,6.380993
AAQVAeABUAAPJSpABD            1               1                1              344 The Delaware River, the largest free-flo [5.27650416E-002,-3.61868404E-002,4.4181
AAQVAeABUAAPJSpABO            1               1                1              395 Welcome to Martin Luther King, Jr. Natio [6.68741763E-002,1.09639429E-001,-1.0090

This makes the relationship between the source description, its text chunk, and its embedding visible.

In the five sampled rows, DOC_CHUNK_COUNT is 1. The descriptions shown fit into a single chunk with the selected settings. This observation applies to the sampled rows; it does not establish that every park description has only one chunk.

Now let us search the index.

Starting with semantic search in document mode

Our first query asks:

Where can I explore ancient fossils and prehistoric mammals?

We supply the question inside the vector section and omit the text section.

demo@ADB26ai> SELECT JSON_SERIALIZE(
  2      DBMS_HYBRID_VECTOR.SEARCH(
  3          JSON('{
  4              "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  5              "vector": {
  6                  "search_text": "Where can I explore ancient fossils and prehistoric mammals?",
  7                  "search_mode": "DOCUMENT",
  8                  "aggregator": "MAX"
  9              },
 10              "return": {
 11                  "topN": 5,
 12                  "values": ["rowid", "score","vector_score"]
 13              }
 14          }')
 15      )
 16      RETURNING CLOB PRETTY
 17  ) final_output ;

FINAL_OUTPUT
--------------------------------------------------------------------------------
[
  {
    "rowid" : "AAQVAeABUAAPJS5AAy",
    "score" : 70.91,
    "vector_score" : 70.91
  },
  {
    "rowid" : "AAQVAeABUAAPJS5AAI",
    "score" : 70.47,
    "vector_score" : 70.47
  },
  {
    "rowid" : "AAQVAeABUAAPJSgABd",
    "score" : 69.25,
    "vector_score" : 69.25
  },
  {
    "rowid" : "AAQVAeABUAAPJSgABI",
    "score" : 69.08,
    "vector_score" : 69.08
  },
  {
    "rowid" : "AAQVAeABUAAPHl8AAF",
    "score" : 69.03,
    "vector_score" : 69.03
  }
]

Because this is a vector-only search, the final score is the vector score.

DOCUMENT mode returns park-level results. When retrieved chunks belong to the same document, MAX uses the highest retrieved chunk score as that document’s vector score. Oracle search parameter documentation

The returned descriptions discuss Pliocene mammals, fossil deposits, prehistoric plants, dinosaurs, and Miocene mammals. They relate to the subject of the question without needing to contain its complete wording.

The scores are relevance values used for ranking; a score of 70.91 should not be interpreted as a 70.91% probability that the result is correct.

Connecting the results to the original park data

The search output contains the ROWID of the source row. We can use it to retrieve the original description and other park attributes.

My execution log uses JSON_TABLE to extract those row identifiers and join them back to PARKS_INFO.

demo@ADB26ai> with hits as (
  2      SELECT JSON_SERIALIZE(
  3      DBMS_HYBRID_VECTOR.SEARCH(
  4          JSON('{
  5              "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  6              "vector": {
  7                  "search_text": "Where can I explore ancient fossils and prehistoric mammals?",
  8                  "search_mode": "DOCUMENT",
  9                  "aggregator": "MAX"
 10              },
 11              "return": {
 12                  "topN": 5,
 13                  "values": ["rowid", "score","vector_score"]
 14              }
 15          }')
 16      )
 17      RETURNING CLOB PRETTY
 18  ) final_output
 19  )
 20  select p.park_description
 21  from parks_info p , hits, json_table ( hits.final_output , '$[*]'
 22          columns( rid varchar2(80) path '$.rowid' , score number, vector_score) ) jt
 23  where p.rowid = jt.rid ;

PARK_DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In the early 1900s, paleontologists unearthed the Age of Mammals when they found full skeletons of extinct Miocene mammals in the hills of Nebraska -- species previously only known through fragments.
At the same time, an age of friendship began between rancher James Cook and Chief Red Cloud of the Lakota. These two unprecedented events are preserved and protected here... at Agate Fossil Beds.

Beneath a grassy mountain valley in central Colorado lies one of the richest and most diverse fossil deposits in the world. Petrified redwood stumps up to 14 feet wide and thousands of detailed fossil
s of insects and plants reveal the story of a very different, prehistoric Colorado.

150 million years ago, dinosaurs roamed here. Their fossils are still embedded in the rocks. Today, mountains, desert, and rivers flowing in canyons support a variety of life. Petroglyphs reveal the l
ives and connections of Indigenous people to this land. Homesteaders and outlaws found refuge here. Whether your passion is science, adventure, history, or scenery, Dinosaur offers much to explore.

During the Pliocene, this place looked quite different. Lush wetlands, forests, and grasslands provided excellent habitat for a variety of animals. From fascinating, now-extinct creatures like the sab
er-toothed cat, mastodon, and ground sloth, to more familiar animals like horses, beavers, and birds, the scientific study of Pliocene fossils is the key to Hagerman.

In the ridges of southwest Wyoming are some of the best-preserved fossils in the world. They tell the story of ancient life in a warm, wet environment in and around a freshwater lake. Stingrays swam i
n the lake. Turtles basked in the sun. Leaves rustled in the breeze while early horses darted between the trunks. We reveal more of the past with each fossil found.

Returning the matching passages with chunk mode

Sometimes we want the relevant passage itself, rather than only a reference to the source document.

For the same question, we can switch to CHUNK mode and request the chunk text:

demo@ADB26ai> SELECT JSON_SERIALIZE(
  2      DBMS_HYBRID_VECTOR.SEARCH(
  3          JSON('{
  4              "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  5              "vector": {
  6                  "search_text":
  7                      "Where can I explore ancient fossils and prehistoric mammals?",
  8                  "search_mode": "CHUNK"
  9              },
 10              "return": {
 11                  "values": [
 12                      "rowid",
 13                      "chunk_id",
 14                      "chunk_text",
 15                      "score",
 16                      "vector_score"
 17                  ],
 18                  "topN": 5
 19              }
 20          }')
 21      )
 22      RETURNING CLOB PRETTY
 23  ) AS search_results ;

SEARCH_RESULTS
--------------------------------------------------------------------------------
[
  {
    "rowid" : "AAQVAeABUAAPJS5AAy",
    "chunk_id" : "1",
    "chunk_text" : "During the Pliocene, this place looked quite different. Lush
 wetlands, forests, and grasslands provided excellent habitat for a variety of a
nimals. From fascinating, now-extinct creatures like the saber-toothed cat, mast
odon, and ground sloth, to more familiar animals like horses, beavers, and birds
, the scientific study of Pliocene fossils is the key to Hagerman.",
    "score" : 70.91,
    "vector_score" : 70.91
  },
  {
    "rowid" : "AAQVAeABUAAPJS5AAI",
    "chunk_id" : "1",
    "chunk_text" : "In the ridges of southwest Wyoming are some of the best-pres
erved fossils in the world. They tell the story of ancient life in a warm, wet e
nvironment in and around a freshwater lake. Stingrays swam in the lake. Turtles
basked in the sun. Leaves rustled in the breeze while early horses darted betwee
n the trunks. We reveal more of the past with each fossil found.",
    "score" : 70.47,
    "vector_score" : 70.47
  },
  {
    "rowid" : "AAQVAeABUAAPJSgABd",
    "chunk_id" : "1",
    "chunk_text" : "Beneath a grassy mountain valley in central Colorado lies on
e of the richest and most diverse fossil deposits in the world. Petrified redwoo
d stumps up to 14 feet wide and thousands of detailed fossils of insects and pla
nts reveal the story of a very different, prehistoric Colorado.",
    "score" : 69.25,
    "vector_score" : 69.25
  },
  {
    "rowid" : "AAQVAeABUAAPJSgABI",
    "chunk_id" : "1",
    "chunk_text" : "150 million years ago, dinosaurs roamed here. Their fossils
are still embedded in the rocks. Today, mountains, desert, and rivers flowing in
 canyons support a variety of life. Petroglyphs reveal the lives and connections
 of Indigenous people to this land. Homesteaders and outlaws found refuge here.
Whether your passion is science, adventure, history, or scenery, Dinosaur offers
 much to explore.",
    "score" : 69.08,
    "vector_score" : 69.08
  },
  {
    "rowid" : "AAQVAeABUAAPHl8AAF",
    "chunk_id" : "1",
    "chunk_text" : "In the early 1900s, paleontologists unearthed the Age of Mam
mals when they found full skeletons of extinct Miocene mammals in the hills of N
ebraska -- species previously only known through fragments. At the same time, an
 age of friendship began between rancher James Cook and Chief Red Cloud of the L
akota. These two unprecedented events are preserved and protected here... at Aga
te Fossil Beds.",
    "score" : 69.03,
    "vector_score" : 69.03
  }
]

This result gives us the passage that explains the match: it directly discusses extinct mammals and the study of Pliocene fossils.

For this execution, the document and chunk searches returned the same five row identifiers with the same scores. The returned chunks all had chunk_id = 1.

That similarity should not be generalized to larger documents. A document can contain several relevant chunks. Document mode groups retrieved chunks by their source document; chunk mode can return multiple passages from the same document. Oracle search modes

Searching with keywords

Next, let us search using an Oracle Text expression: fossil OR fossils

This time, we supply a text section and omit the vector section.

demo@ADB26ai> SELECT JSON_SERIALIZE(
  2      DBMS_HYBRID_VECTOR.SEARCH(
  3          JSON('{
  4              "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  5              "text": {
  6                  "contains": "fossil OR fossils"
  7              },
  8              "return": {
  9                  "values": ["rowid", "score", "text_score"],
 10                  "topN": 5
 11              }
 12          }')
 13      )
 14      RETURNING CLOB PRETTY
 15  ) AS search_results ;

SEARCH_RESULTS
--------------------------------------------------------------------------------
[
  {
    "rowid" : "AAQVAeABUAAPJSpACM",
    "score" : 9,
    "text_score" : 9
  },
  {
    "rowid" : "AAQVAeABUAAPJSgABI",
    "score" : 9,
    "text_score" : 9
  },
  {
    "rowid" : "AAQVAeABUAAPJS5AAy",
    "score" : 9,
    "text_score" : 9
  },
  {
    "rowid" : "AAQVAeABUAAPJS5AAI",
    "score" : 9,
    "text_score" : 9
  },
  {
    "rowid" : "AAQVAeABUAAPJSgABd",
    "score" : 9,
    "text_score" : 9
  }
]
demo@ADB26ai>
demo@ADB26ai> with hits as (
  2     SELECT JSON_SERIALIZE(
  3             DBMS_HYBRID_VECTOR.SEARCH(
  4                     JSON('{
  5                             "hybrid_index_name": "PARK_DESCRIPTION_HVI",
  6                             "text": {
  7                                     "contains": "fossil OR fossils"
  8                             },
  9                             "return": {
 10                                     "values": ["rowid", "score", "text_score"],
 11                                     "topN": 5
 12                             }
 13                     }')
 14             )
 15             RETURNING CLOB PRETTY
 16     ) AS final_output
 17  )
 18  select p.park_description
 19  from parks_info p , hits, json_table ( hits.final_output , '$[*]'
 20          columns( rid varchar2(80) path '$.rowid' , score number, vector_score) ) jt
 21  where p.rowid = jt.rid ;

PARK_DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
During the Pliocene, this place looked quite different. Lush wetlands, forests, and grasslands provided excellent habitat for a variety of animals. From fascinating, now-extinct creatures like the sab
er-toothed cat, mastodon, and ground sloth, to more familiar animals like horses, beavers, and birds, the scientific study of Pliocene fossils is the key to Hagerman.

In the ridges of southwest Wyoming are some of the best-preserved fossils in the world. They tell the story of ancient life in a warm, wet environment in and around a freshwater lake. Stingrays swam i
n the lake. Turtles basked in the sun. Leaves rustled in the breeze while early horses darted between the trunks. We reveal more of the past with each fossil found.

150 million years ago, dinosaurs roamed here. Their fossils are still embedded in the rocks. Today, mountains, desert, and rivers flowing in canyons support a variety of life. Petroglyphs reveal the l
ives and connections of Indigenous people to this land. Homesteaders and outlaws found refuge here. Whether your passion is science, adventure, history, or scenery, Dinosaur offers much to explore.

Beneath a grassy mountain valley in central Colorado lies one of the richest and most diverse fossil deposits in the world. Petrified redwood stumps up to 14 feet wide and thousands of detailed fossil
s of insects and plants reveal the story of a very different, prehistoric Colorado.

A landscape where deep time lies fully on display, Petrified Forest National Park blends colorful badlands, vast grasslands, and one of the worldÆs largest and most vivid collections of petrified wood
. Spanning more than 200 million years of geologic history, the park protects ancient fossils, ancestral Puebloan sites, habitat for desert animals, and a sweeping stretch of historic Route 66.

The returned descriptions included Hagerman, Dinosaur, and Petrified Forest, along with descriptions of fossil deposits in Wyoming and Colorado.

The distinction is in the request we made. The semantic query asked about a subject. This request asks Oracle Text to evaluate a keyword expression against the indexed descriptions. Both requests use PARK_DESCRIPTION_HVI, but they provide different relevance signals

RequestReturned information
Semantic DOCUMENTSource documents ranked using retrieved chunk scores
Semantic CHUNKIndividual passages with their source row identifiers
Keyword searchSource documents matching the Oracle Text expression