1+ // Copyright (c) Microsoft. All rights reserved.
2+ package com .microsoft .semantickernel .samples .documentationexamples .data .vectorstores .oracle ;
3+
4+ import com .microsoft .semantickernel .data .jdbc .JDBCVectorStore ;
5+ import com .microsoft .semantickernel .data .jdbc .JDBCVectorStoreOptions ;
6+ import com .microsoft .semantickernel .data .jdbc .JDBCVectorStoreRecordCollection ;
7+ import com .microsoft .semantickernel .data .jdbc .JDBCVectorStoreRecordCollectionOptions ;
8+ import com .microsoft .semantickernel .data .jdbc .postgres .PostgreSQLVectorStoreQueryProvider ;
9+ import com .microsoft .semantickernel .samples .documentationexamples .data .index .Hotel ;
10+
11+ public class Main {
12+ public static void main (String [] args ) {
13+ // Configure the data source
14+ OracleDataSource dataSource = new OracleDataSource ();
15+ dataSource .setURL ("jdbc:oracle:thin:@localhost:1521/FREEPDB1" );
16+ dataSource .setUser ("scott" );
17+ dataSource .setPassword ("tiger" );
18+
19+ // Build a query provider
20+ OracleVectorStoreQueryProvider queryProvider = OracleVectorStoreQueryProvider .builder ()
21+ .withDataSource (dataSource )
22+ .build ();
23+
24+ // Build a vector store
25+ JDBCVectorStore vectorStore = JDBCVectorStore .builder ()
26+ .withDataSource (dataSource )
27+ .withOptions (JDBCVectorStoreOptions .builder ()
28+ .withQueryProvider (queryProvider )
29+ .build ())
30+ .build ();
31+
32+ VectorStoreRecordCollection <String , Hotel > collection = vectorStore .getCollection (
33+ "skhotels" ,
34+ JDBCVectorStoreRecordCollectionOptions .<Hotel >builder ()
35+ .withRecordClass (Hotel .class )
36+ .build ());
37+
38+ // Create the collection if it doesn't exist yet.
39+ collection .createCollectionIfNotExistsAsync ().block ();
40+
41+ collection .upsertBatchAsync (getHotels (), null ).block ();
42+
43+ // Retrieve the upserted record.
44+ var retrievedHotel = collection .getAsync ("1" , null ).block ();
45+
46+ // Generate a vector for your search text, using your chosen embedding generation implementation.
47+ // Just showing a placeholder method here for brevity.
48+ // var searchVector = generateEmbeddingsAsync(
49+ // "I'm looking for a hotel where customer happiness is the priority.").block();
50+
51+ // Do the search.
52+ // var searchResult = collection.searchAsync(searchVector, VectorSearchOptions.builder()
53+ // .withTop(1).build()).block();
54+
55+ // Hotel record = searchResult.getResults().get(0).getRecord();
56+ // System.out.printf("Found hotel description: %s\n", record.getDescription());
57+
58+ }
59+
60+ private static List <Hotel > getHotels () {
61+ return Arrays .asList (
62+ new Hotel ("id_1" , "Hotel 1" , 1 , "Hotel 1 description" ,
63+ Arrays .asList (0.5f , 3.2f , 7.1f , -4.0f , 2.8f , 10.0f , -1.3f , 5.5f ), null , null , null ,
64+ 4.0 ),
65+ new Hotel ("id_2" , "Hotel 2" , 2 , "Hotel 2 description" ,
66+ Arrays .asList (-2.0f , 8.1f , 0.9f , 5.4f , -3.3f , 2.2f , 9.9f , -4.5f ), null , null , null ,
67+ 4.0 ),
68+ new Hotel ("id_3" , "Hotel 3" , 3 , "Hotel 3 description" ,
69+ Arrays .asList (4.5f , -6.2f , 3.1f , 7.7f , -0.8f , 1.1f , -2.2f , 8.3f ), null , null , null ,
70+ 5.0 ),
71+ new Hotel ("id_4" , "Hotel 4" , 4 , "Hotel 4 description" ,
72+ Arrays .asList (7.0f , 1.2f , -5.3f , 2.5f , 6.6f , -7.8f , 3.9f , -0.1f ), null , null , null ,
73+ 4.0 ),
74+ new Hotel ("id_5" , "Hotel 5" , 5 , "Hotel 5 description" ,
75+ Arrays .asList (-3.5f , 4.4f , -1.2f , 9.9f , 5.7f , -6.1f , 7.8f , -2.0f ), null , null , null ,
76+ 4.0 ));
77+ }
78+ }
0 commit comments