I Love Tech Romania - A High-Speed Data Ingestion Microservice in Java Using MQTT, AMQP, and STOMP.pdf

juarezjunior 38 views 53 slides Mar 11, 2025
Slide 1
Slide 1 of 53
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53

About This Presentation

I Love Tech Romania - A High-Speed Data Ingestion Microservice in Java Using MQTT, AMQP, and STOMP


Slide Content

i

2 OO!
ORACLE 23" 4
ORACLE Database =

Accelerating loT: A High-Speed Data
Ingestion Solution in Java

Accelerating /oT:
A High-Speed Data Ingestion

l Love Tech Timisoara 2024
Juarez Barbosa Jr Bq Qiuarezjunior

Sr Principal Java Developer Evangelist

ORACLE

wie

Juarez Barbosa Junior
Senior Principal Java Developer Evangelist @ Oracle

+ Coming from Dublin, Ireland

+ 28 years of experience in SW Engineering & DevRel
+ Oracle, Microsoft, IBM, Nokia, Unisys, Accenture, startups
+ Microsoft Azure Developer Relations Lead
+ IBM Watson Tech Evangelist & Cloud Rockstar
+ IBM Mobile Tech Evangelist & Global Thought Leader
+ Nokia Developers Global Champion

+ Java, Python, Cloud, DevOps, SRE, Cloud-native, loT, Al, Blockchain,
Rust

+ Speaker at conferences

+ Oracle CloudWorld, Oracle Code, Microsoft Ignite & TechX, ¡Prime,
JCON, DevConf.cz, GeeCon, DevOpsDays, DeveloperWeek, DevOps
Institute, CloudLand, DWX, The Developer's Conference (TDC),
Sec4Dev, JSNation, NodeConf, Conf42, Shift Conf, Global Azure,
Open-Source Lisbon, CodeFrenzy, Mélée Numérique, React Summit,
Tests Summit, Porto TechHub Conf, | Love Tech, Pyjamas,
MiTechCon, Data Science Summit, OpenSourceNorth,
WeAreDevelopers, Global Software Architecture Summit, JUGs,
OUGs, GDGs, meetups, hackathons, and customer engagements.

Confidential - Oracle Restricted

a ee ee

Agenda

Java App Dev with the Oracle Database

Oracle JDBC - Support for the Latest Java Versions
Overview of Oracle DB Access with Java

Oracle JDBC - Sync and Async

Classic Java Platform Threads

Project Loom - Virtual Threads

Virtual Threads - JEPs 425, 436, 444

Demo # 1: Virtual vs Platform Threads

Reactive JDBC - Synchronous vs Asynchronous JDBC
Reactive Streams Ingestion (RSI)

Demo # 2: Reactive Streams Ingestion (RSI)

From Sync to Reactive JDBC: Oracle R2DBC

Demo # 3: Oracle R2DBC with Project Reactor
Pipelined Database Operations, Oracle Al Vector Search

+ Demo #4: Structured Concurrency + Pipelined Database
Operations + Al Vector Search

+ Live Labs/Free Oracle Cloud Account/Oracle ACE Program

Confidential - Oracle Restricted,

Java Developers

te ©

Grave oca Koon Java App
paa Dev with
Oracle
Database

— Gpgo- 28eecs

Zo

Overview of Oracle DB Access with Java

operators (map, reduce, filters),
concurrency modeling,

monitoring, tracing, JavaucFlow Oracle JDBC Driver

User Java code + JDBC

Full Reactive Streams.

Oracle Database

Copyright © 2024, Oracle

Oracle JDBC - Support for the Latest Java
Versions

. Support to the latest Java versions
(11, 17, 21) and GraalVM

* Project Loom - Virtual Threads
support

+ Java Virtual Threads and Pipelined
Database Operations

5, a + JDBC Standards - 4.2 and 4.3
Java 23 is now available + Reactive Streams - Java Flow API
support

+ R2DBC, Reactive Streams Ingestion
(RSI)

+ Pipelined Database Operations

Oracle JDBC Reactive Extensions 3
(Flow API)

SQL Execution (OraclePreparedStatement):
Publisher<Boolean> executeAsyncOracle()
Publisher<Long> executeUpdateAsyncOracle()
Publisher<Long> executeBatchAsyncOracle()
Publisher<OracleResultset>
executeQueryAsyncOracle()

Comeactton Creation: Introduction to JDBC Reactive

(OracleConnectionBuilder): Row Fetching (OracleResultSet): mere era

Publisher<OracleConnection> Publisher<T> Extensions with the Oracle

buildConnectionPublisherOracle() publisherdracle(Function<OracleRow, T> f) Database 23c Free — Developer

Database 23c Free — Developer

LOB 1/0 (OracleBlob):

'comectian cronos Publisher<byte[ ]> publisherOracle(long Release

(OracleConnection): position)

Publisher<Success>

ramen sie ie iio

Transaction Closing 108 1/0 (Oractectob):

(OracLeConnection): ines IES

Publishen<Success» e eee

conmitAsyncOracle() Subscriber<String> subscriberOracle(long

Publisher<Success>

rolIbackAsyncOracle() — JDBC

Oracle JDBC — Async and Sync

- Project Loom - Virtual Threads

+ Synchronous database access with lightweight threads

+ Standard JDBC + Virtual Threads

+ Client application call stack may use blocking, synchronous code

+ Libraries must be compatible with Virtual Threads

+ Oracle instrumented the Oracle JDBC driver to support Virtual Threads
. Reactive Programming

+ Asynchronous database access with non-blocking network 1/0

+ Oracle Reactive Streams Ingestion (RSI) + Oracle R2DBC + Oracle JDBC Reactive
Extensions (Flow)

+ Reactive Streams Libraries: Reactor, RxJava, Akka, Vert.x

Classic Java Platform Threads

o> m

thread

. Database access with blocking threads progam sa]

+ A JDBC call blocks a thread for 100s of milliseconds
(thread-per-request style)

+ Thread count increases linearly with the number
of JDBC calls

+ Performance degrades as the number of threads
increases

1 MB of stack memory per thread typically

+ Scheduling many platform threads is expensive

Preemptive scheduling vs time-slicing

Virtual Threads - JEPs 425, 436, 444

- Virtual Threads — JEPs (JDK Enhancement Proposals)

. Lightweight (user mode) threads that dramatically reduce the effort of writing,
maintaining, and observing high-throughput concurrent applications

+ Enable applications written in the simple thread-per-request style to scale with near-
optimal hardware utilization

+ Enable easy troubleshooting, debugging, and profiling of virtual threads with existing JDK
tools

+ Do not remove the traditional implementation of threads
+ Do not alter the basic concurrency model of Java

. Enable existing code that uses Java threads (java.lang.Thread) to adopt virtual threads with
minimal change

Virtual Threads - JEPs 425, 436, 444

- Virtual Threads — JEPs (JDK Enhancement Proposals)
+ Virtual threads typically employ a small set of platform threads used as carrier threads
+ Code executing in a virtual thread is not aware of the underlying carrier thread
+ The currentThread() method will always return the Thread object for the virtual thread

+ Virtual threads do not have a thread name by default. The getName() method returns the
empty string if a thread name is not set

+ Virtual threads have a fixed thread priority that cannot be changed

+ Virtual threads are daemon threads so do not prevent the shutdown sequence from
beginning (low-priority ones).

- JDK Enhancement Proposals
+ JEP 425: Virtual Threads (Preview)

+ JEP 436: Virtual Threads (Second Preview)
+ JEP 444: Virtual Threads

Virtual | iii

+ final Boolean - isVirtual
Th rea ds ind + static Thread.Builder.OfVirtual - ofVirtual
J E P S 42 5 + static Thread.Builder.OfPlatform - ofPlatform
a . static Thread - startVirtualThread(Runnable task
436, 444 - java.lang.Thread.Builder
- java.util.concurrent.Executors

- static ExecutorService -
newVirtualThreadPerTaskExecutor()

Virtual Threads - JEPs 425, 436, 444

Runnable runnable =

// Start a daemon thread to run a task

Thread thread = Thread.ofPlatform().daemon().start(runnable);
+ java.lang.Thread.Builder

// Create an unstarted thread with name "duke", its start() method R

1 must be invoked to schedule it to execute. + Thread defines a

Thread thread = Thread.ofPlatform().name("duke") .unstarted(runnable); Thread.Builder API for

creating and starting
// A ThreadFactory that creates daemon threads named “worker-0", "worker-1", ... both platform and virtual
ThreadFactory factory = Thread. ofPlatform() .daemon().name("worker-", 0) .factory(); threads. The following

// Start a virtual thread to run a task are examples that use
Thread thread = Thread.ofVirtual().start(runnable); the builder:

// A ThreadFactory that creates virtual threads
ThreadFactory factory = Thread.ofVirtual().factory();

Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted

Demo + 1: Virtual vs Platform Threads

OSThread | OSThread | OSThread | OS Thread
+ Virtual Threads vs Platform Threads
Java Platform — JavaPlatiorm — JavaPlatiorm Java Platform
« JEP 425 Virtual Threads (Preview) Thread Thread Thread Thread
VI VI VI VI VI VI VI VI VI VI VI VI VI vr vr vr
« JEP 436 (Second Preview)
+» JEP 444 (JDK 21)

+ Oracle JDBC Driver instrumented to support Virtual Threads

*VT- Virtual Thread

« Intrinsic locks replaced with ReentrantLock to avoid thread pinning
+ Verifiable comparison of OS/HW resources consumption cig
(Platform Threads versus Virtual Threads)

« Introduction to Oracle JDBC Driver Support for Virtual Threads

Ei ee Macias.

Setup

Handle Result

Setup

Non-Blocking

Confidential - Oracle Restricted

Reactive Streams Ingestion (RSI)

+ Java Library for Reactive Streams Ingestion
+ Streaming capability: Ingest data in an unblocking, and "Poem
reactive way from a large group of clients
+ Group records through RAC (Real App Clusters),
and Shard affinity using native UCP (Universal Connection
Pool)

+ Optimize CPU allocation while decoupling record

Processing from |/O

« Fastest insert method for the Oracle Database through

Direct Path Insert, bypassing SQL and writing directly into the DB files

Ei ee Macias.

Confidential - Oracle Restricted

Demo #2: RSI - Architecture

Listener Application

js = Tope Subscriber
i ME d-
© =e ‘ActiveMQ $:

(Direct path insert) molle
Dataset

Oracle Database

Confidential - Oracle Restricted

Demo #2: RSI - Project Structure

v 53 rsi-example
v 2 src/main/java
y @ rsiexample.amgp
D Listenerjava
y @ rsiexample.common
D AuthHeadersRequestFilter.
D MessageProducer java
D Retailerjava
D RSIServicejava
v 8 rsiexample.matt
à Listenerjava
v 8 rsi.example.stomp
D Listenerjava
añ JRE System Library (jdk-19]
zà Referenced Libraries
& src
& target

8 pom.xml

Ei ee Macias.

Demo # 2: Reactive Streams Ingestion (RSI)

Memoptimized
Kubernetes Rowstore
worker nodes
ORACLE CLOUD INFRASTRUCTURI

51 Runtime: = Push Docker i

2 blocking, images to Bi ier h
8 streaming data E Registry rom Registry (= !
3 through Direct Path dard tr O ET :
E toolchain Cloud Container !
E Córtalner Infrastructur Enginefor |
3 one ‘ubernetes |
= Pipelines, e Registry I
Jenkins, etc. — i

images to :

production :

Record JDBC :

Y Streaming — :

E over Containers Direct Path == H

< Se ne INSERT

3 deployed over ATP, Fous ATP-D;

> Kubernetes im :

3 :

5 :

2 H

Virtual Threads or Reactive?

+ Oracle JDBC supports both!

+ Want Virtual Threads?
The Oracle JDBC driver is Virtual Thread compatible
Pipelined Database Operations

Want Reactive?
Oracle R2DBC, Oracle RSI, Oracle JDBC Reactive Extensions
+ Pipelined Database Operations

Virtual Threads or Reactive?

+ Benefits of Virtual Threads: Benefits of Reactive:

+ Easier to read and write + Reactive Libraries (Reactor, RxJava, Akka, Vert.x)
+ Easier to debug + Stream-like API with a functional style

+ Integration with JDK tools + Low-level concurrency is handled for you

+ Do not alter the basic concurrency model of Java (IoCkS, atomics, queues)

+ Now available in JDK 21 / 22

+ Limitations of Virtual Threads: Limitations of Reactive:
+ Some libraries/frameworks are not + Steep learning curve
compatible yet + Harder to read and write

+ Harder to debug

Confidential - Oracle Restricted

— — R2DBC - Reactive Relational DB Connectivity

From Sync to Reactive JDBC: Oracle
R2DBC Oracle R2DBC

Oracle Reactive Relational Database Connectivity (R2DBC) driver

Oracle R2DBC Driver is a Java library that supports reactive JDBC-thin 21c
programming with the Oracle Database Async APIs

It implements the R2DBC Service Provider Interface (SPI) as
specified by the Reactive Relational Database Connectivity TTC/sqinet
(R2DBC) spec

+ The R2DBC SPI exposes Reactive Streams as an abstraction nF
for remote database operations Oracle RDBMS 19¢
or above
+ The sample code uses Project Reactor. It could use RxJava, Se

Akka, or any Reactive Streams library

mone R2 DBC
=

Oracle RDBC 1.2.0, Apache v2.0 (OSS)

a ee ee

Confidential - Oracle Restricted

Demo # 3: Oracle R2DBC

static String queryldbc(java.sql.Connection connection) throws static Publisher<String> queryR2dbe(io.r2dbe.spi Connection
SQLException { connection) {
try (javassql.Statement statement = connection.createStatement()) { return Flux. from(connection.createStatement(
ResultSet resultSet = "SELECT * FROM CUSTOMERS")
statement.executeQuery("SELECT + FROM CUSTOMERS") 5 «execute())
+flatHap(result ->
if (resultSet.next()) result.map(row => rowsget(9, String.class)))
return resultSet.getString(1); «switehIfEmpty (Flux.error(
else new NoSuchElementException("Query returned zero rows")))$
throw new NoSuchElementException("Query returned zero rows"
3 3
3

R2DBC

Ei ee Macias.

Confidential - Oracle Restricted

== Pipelined Database Operations

= i a

‘tient Server

Before Pipelined Database Operations

The server must complete the processing
of the request and sending the response
before accepting another request

Server idle

FIs

The client and server have idle time ne

a ee ee

Confidential - Oracle Restricted

Pipelined Database Operations

Client Server Client Server

No-Blocking Requests and Responses

Send multiple requests from client to server
without waiting for responses

Application can asynchronously perform
other operations

The server processes the requests in order
and sends the responses back to the client
when ready, in the same order they

were received

Benefits
Improved response time and throughput
Particularly useful when network latency is high

No pipelining, Pipelining

a ee ee

Confidential - Oracle Restricted

== Pipelined Database Operations

Performance Improvements depending on the CPU load, the workload
profiles on the server side, and the network latency between client and server

+ Up to 90% improvement for queries only workload over a fast network
+ Up to 90x improvement for queries only workload over a slow network
+ Up to 24% improvement for OLTP workload over a fast network

+ Up to 7x improvement for OLTP workload over a slow network

+ Up to 100+x improvement for DML workload

The Oracle JDBC Driver 23ai supports Pipelined Database Operations through:

+ The Oracle JDBC Reactive Extensions
+ Reactive Streams libraries

6: „Java Virtual Threads ORACLE 23°

+ Structured Concurrency

+ The Standard JDBC Batching API Database

a ee ee

Confidential - Oracle Restricted

—— JDBC Reactive Extensions and Pipelined DB Operations

1 class PipelineExample(

2 void pipelineExample(OracleComnection connection) throws SQLException {

3 PreparedStatenent delete = connection. prepareStatement (

4 "DELETE FROM example WHERE id = 0"

5 PreparedStatement insert = connection. prepareStatement (

6 INSERT INTO example (id, value) VALUES (1, ‘x!

7 PreparedStatenent select = connection.prepareStatement(

8 SELECT id, value FROM example WHERE id = 2

9

10 Flow. Publisher<Long> deletePublisher

u delete. unurap(OraclePreparedStatement. class) .executeupdateAsyncOracle();
12 Flow. Publisher<Long> insertPublisher

13 insert. unwrap(OraclePreparedStatenent. class) .executeUpdateAsyncOrac le();
1 Flow. Publisher<OracleResultSet> selectPublisher

15 select .unwrap(OraclePreparedStatenent. class) .executeQueryAsyncOracle(
16

17 // Subscribe to publishers to get results back

18 =

19 }

20 }

Copyright © 2024, Oracle and/or its affiliates

ee

Confidential - Oracle Restricted

—— R2DBC and Pipelined Database Operations

1 | Push a SELECT into the pipeline

2 Flux.using(

3 () -> connection. prepareStatement (

4 “SELECT id, value FROM example ORDER BY id"),

5 preparedStatement ->

6 Mono. from(publishQuery(preparedStatement) )

7 -flatMapMany( resultSet -> publishRows(resultset)),
8 preparedStatement -> close(preparedStatement))

9 .subscribe(rowString ->

10 System.out.println(rowString) );

u }

12

13 |// Push an INSERT into the pipeline

14 Mono. using(

15 () -> connection. prepareStatement(

16 “INSERT INTO example (id, value) VALUES (1, ‘x')"),
17 preparedStatement -> Mono. from(publishUpdate(preparedStatement)),
18 preparedStatement -> close(preparedStatement))

19 .subscribe(insertCount ->

20 System.out.println(insertCount + " rows inserted"));

a ee ee

Enabling Generative Al
with Al Vector Search in
Oracle Database 23ai

New | Oracle Database 23ai

Next-Generation Converged Database Services

Over 300 major new features plus thousands of enhancements
Available on OCI and Azure
Major focus on

+ Al for Data features

ai
+ Developer/Analyst features Database 23

+ Mission-Critical features

Addresses data management pain points that have frustrated customers forever

Oracle Database 23ai - Al for Data

Algorithmic Al

TR

Distributed Al



Pad
dz

—+

Al Vector Search Augmented Generative Al (LLMs)

a

Al Storage Al Developer Tools

Free | Oracle Database 23ai For Developers

Oracle Always Free ADB ADB Free Container Image Oracle Database Free

Available on OCI Available for download Available as RPM, Docker
Image, VBox VM

Very Low Cost Supported Developer Edition of ADB, BaseDB, ExaDB-D, and ExaDB-C@C

Copé © 2024 rca ed ans

Democratizes

SIMPLE

SUPERFAST

ee alicia

M

Confidential - Oracle Restricted

content

ee alicia

Confidential - Oracle Restricted

An intuitive example
Word relatedness in two dimensions

di

Copyright © 2024, Oracle and/or its aftates
ee arte

Confidential - Oracle Restricted

Generating embeddings
Use an embedding model

Text documents
EN
Cas EN
ES
+

Ei ee Macias.

Natural Language

Embedding
Mod

y

1

Image
Embedding
Model

Text Vector Table

1 [08,0.5,1.6,-25,..].—— “ltwasthe best of times, it was the
worst of times, it was.”

2 [1:1,03,06,-13,..] — “Itisatruth universally
acknowledged, that a single man.”

3 [13,0,02,-14,..] | “itwes abright cold day in April, and
the clocks were striking.”

Image Vector Table

1 [05,1.5,26,-1.4, .]
2 1.0,09,1.6,-13, .]

FEN

Confidential - Oracle Restricted

Simple vector search
Pipeline
Input Data Embedding
Object alo | — =, road BS- - En
Matches

What were looking for
Ve Late Vector Search Data Object Retrieval =
content

‘compare

Copyright © 2024, Oracle and/or is afiistes
ee arte

Confidential - Oracle Restricted

Use cases
What do embeddings and vector databases enable?

Similarity Search Data Analytics

Match candidates with jobs ‘Anomaly detection
Image and video retrieval Pattern recognition
Find patients with similar issues
Legal e-discovery

Computer Vision Biomedical Research — Geographic
Information Systems
Spatial analysis
Map rendering

Face recognition Gene/DNA similarity analysis
Biometric identification ‘Molecular structure search
Object detection

Copyright © 2024, Oracle and/or its afiiste
Ei ee Macias.

Confidential - Oracle Restricted

— — Structured Concurrency and Java Virtual Threads

Structured concurrency treats groups of related tasks running in different threads as a single unit of work,
thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.

Create StructuredTask: E
use with try-with-resources

+ The StructuredTaskScope class enables you
coordinate a group of concurrent subtasks as a unit. J
With a StructuredTaskScope instance, you fork each
subtask, which runs them in their own individual

thread. After, you join them as a unit. Subtask || Subtask || Subtask || Subtask
+ Asa result, the StructuredTaskScope ensures that JL IL Il |
the subtasks are completed before the main task nth
continues. ll
+ Alternatively, you can specify that the application Handle outcome from subtasks

continues when one subtask succeeds. |

a ee ee

Confidential - Oracle Restricted

Demo #4: Structured Concurrency + Pipelined Database
= Operations + Oracle Al Vector Search

Combining Structured Concurrency + Pipelined Database Operations +
Oracle Al Vector Search

Create a database table

Populate the database

Update the database table with vector embeddings
Perform vector similarity searches

hd

zo

sen, ORACLE DATABASE 23ai
SEARCH MATCHES

ES, mo ma yz
wa enna =|

Confidential - Oracle Restricted

Demo #4: Structured Concurrency + Pipelined Database
= Operations + Oracle Al Vector Search

3- Perform similarities

1- Stream text from a Searches for search
book about animals | terms N
into a table "Ss,

Text +
Vector
Embeddings

2- Update the Text table with _..- ”
corresponding Vector. - ~~
Embedding from Oracle

Cloud's

Generative Al service

Oracle Database 23ai FREE

Demo code @ https://tinyurl.com/nbjmezjr

Confidential - Oracle Restricted

Demo #4: Structured Concurrency + Pipelined Database
— Operations + Al Vector Search

Create and populate the DB table

// Stream text from a book about animals mon TOUS Ir malen ee
String bookUrl =

CREATE TABLE example (
“https: //www.gutenberg. org/cache/epub/37959/pg37959. txt";

id NUMBER GENERATED ALWAYS AS IDENTITY,

try ( text CLOB NOT NULL,
Stream<String> paragraphStream = streamParagraphs (bookUrL) ; embedding VECTOR(*, FLOAT32) ,
ShutdownOnFailure taskScope = new ShutdownOnFailure()) { PRIMARY KEY (id);

// For every 100 paragraphs of text, execute a pipelined batch insert
paragraphStream. gather (Gatherers.windowFixed (100) )
.forEach(paragraphs ->
taskScope.fork(() -> pipelineBatchInsert(connection, paragraphs)));

// Wait for all pipelined batch insert tasks to complete

taskScope.join();
taskScope. throwIfFailed();

a ee ee

Confidential - Oracle Restricted

Demo #4: Structured Concurrency + Pipelined Database
— Operations + Al Vector Search

Update the Table with Embeddings

try (ShutdownOnFailure taskScope = new ShutdownOnFailure()) {

41 Stream rows from pipelined fetches|
pipelineQuery (connection)
«gather (Gatherers.windowF ixed (MAX_EMBEDDINGS_REQUEST) )
„forEach(textRecords ->
taskScope. fork(() -> {
// Request embeddings from Oracle Cloud
List<String> texts =
textRecords. stream().map(TextRecord: :text) .toList();
List<float []> embeddings = requestEmbeddings (texts);

// Pipeline batch updates
return pipelineBatchUpdate(connection, textRecords, embeddings);
ws

taskScope. join();

taskScope.throwIfFailed();
F

a ee ee

Confidential - Oracle Restricted

Demo #4: Structured Concurrency + Pipelined Database
— Operations + Al Vector Search

Perform Similarities Search 1/2

Perform vector similarity searches

with the following prompts:

augen, ORACLE DATABASE 23ai

SeaRCH MATCHES

+ Predatory behavior of cats | my an E
+ Location of bears > D ES

+ Best climate for dogs Re mes 2-2

+ Animals in ancient times =

+ Beautiful birds 23

+ Deadly fish

Where the wild things are

Confidential - Oracle Restricted

Demo #4: Structured Concurrency + Pipelined Database
— Operations + Al Vector Search

Perform Similarities Search 2/2

searchTableText(Connection, List)

Perform a similarity search against vector embeddings

Convert Search Terms to Vector Embeddings

Pipeline queries with VECTOR_DISTANCE on Virtual Threads as it allows for concurrent progress of
MANY statements from one (1) JDBC connection
SELECT text
FROM example
ORDER BY VECTOR_DISTANCE (embedding, ?, COSINE)
FETCH APPROX FIRST 1 ROW ONLY

Return Similarity Search Results

a ee ee

Confidential - Oracle Restricted

Demo #4: Structured Concurrency + Pipelined Database
— Operations + Al Vector Search

Perform Similarities Search 2/2

try (ShutdownOnFailul D) «

List<SubtaskeList<String>>> searchTasks =
searchTerms.stream()
.gather (Gatherers.windowFixed(MAX_EMBEDDINGS_REQUEST) )
smap(gatheredSearchTerms ->
taskScope. fork(() => {
// Request embeddings, and pipeline SELECT queries which perform
// a similarity search.
List<float []> embeddings = requestEmbeddings (gatheredSearchTerms) ;
return searchTableEmbeddings (connection, embeddings) ;
»
«toList();

taskScope. join();
taskScope. throwIfFailed();

return searchTasks. strean( 5

stoList();

a ee ee

Confidential - Oracle Restricted

Technical References
+ JDK22

+ The Arrival of Java 23 - https: //blogs.oracle.com/java/post/the-arrival-of-java-23
+ Virtual Threads
+ JEP 444 Virtual Threads - https://openjdk.org/jeps/444
+ JEP 480 Structured Concurrency (Third Preview) - https://openjdk.org/jeps/480
+ Introduction to Oracle JDBC Driver Support for Virtual Threads - https://bit.ly/3UINJWP.
+ Reactive Streams Ingestion Library
+ Getting Started with the Java library for Reactive Streams Ingestion (RSI) - https: / /bit.ly/3rEiRnC
+ AHigh-Speed Data Ingestion Solution in Java Using MQTT, AMQP, and STOMP -
https://medium.com/oracledevs/a-high-speed-data-ingestion-microservice-in-java-using-matt-
amap-and-stomp-135724223ae1
+ R2DBC
+ Getting Started with Reactive Relational Database Connectivity and the Oracle R2DBC Driver —
http://rb.gy/95u5f8
+ Pipelined Database Operations - https: //rb.gy/k57g3r
+ Generative Al Service - Oracle Cloud Infrastructure (OCI) - https: //rb.gy/a9k69e
+ What's in Oracle Database 23ai for Java Developers?
+ https://www.oracle.com/a/tech/docs/database/whats-in-oracledb23ai-for-java-developers.pdf

Ei ee Macias.

Oracle LiveLabs

Showcasing how Oracle's solutions can
solve your business problems

500+

free workshops,
available or in
development

people have already visited
LiveLabs

600+

events run
using LiveLabs
workshops

developer.oracle.com/livelabs
learn something new ...at your pace!

Qos

Oracle ACE Program

3 membership tiers à Oracle ACE

Oracle ACE à Oracle ACE Oracle ACE ás
Director Pro Associate Nominate

yourself or a candidate:

ace.oracle.com/nominate
Learn more - ace.oracle.com

Connect: EP [email protected] E @oracleace facebook.com/OracleACEs — [8] blogs.oracle.com/ace

Create your FREE
Cloud Account

* Goto

https://signup.cloud.oracle.com/

ORACLE
Cloud Infrastructure

de

~—_

Oracle Cloud Free Tier

Get started with.

Terms of Use

Juarez Junior

Y | @juarezjunior

ORACLE