Skip to content

Commit 113ae52

Browse files
committed
Merge remote-tracking branch 'origin/main' into add-oracle-store
2 parents 0e044a0 + 92339ab commit 113ae52

6 files changed

Lines changed: 151 additions & 11 deletions

File tree

  • data/semantickernel-data-oracle
  • samples
    • semantickernel-concepts/semantickernel-syntax-examples
    • semantickernel-learn-resources/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/data/vectorstores/oracle

data/semantickernel-data-oracle/pom.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,10 @@
2929
</dependencyManagement>
3030

3131
<dependencies>
32-
<dependency>
33-
<groupId>com.microsoft.semantic-kernel</groupId>
34-
<artifactId>semantickernel-api-data</artifactId>
35-
</dependency>
3632
<dependency>
3733
<groupId>com.microsoft.semantic-kernel</groupId>
3834
<artifactId>semantickernel-data-jdbc</artifactId>
3935
</dependency>
40-
<dependency>
41-
<groupId>org.slf4j</groupId>
42-
<artifactId>slf4j-api</artifactId>
43-
</dependency>
4436
<dependency>
4537
<groupId>com.fasterxml.jackson.core</groupId>
4638
<artifactId>jackson-databind</artifactId>
@@ -56,10 +48,12 @@
5648
<artifactId>jackson-datatype-jsr310</artifactId>
5749
<version>2.18.0</version>
5850
</dependency>
51+
<!--
5952
<dependency>
6053
<groupId>com.github.spotbugs</groupId>
6154
<artifactId>spotbugs-annotations</artifactId>
6255
</dependency>
56+
-->
6357
<dependency>
6458
<groupId>com.oracle.database.jdbc</groupId>
6559
<artifactId>ojdbc11</artifactId>

data/semantickernel-data-oracle/src/test/resources/initialize.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ WHENEVER SQLERROR EXIT SQL.SQLCODEAdd commentMore actions
44
-- Configure the size of the Vector Pool to 1 GiB.
55
ALTER SYSTEM SET vector_memory_size=1G SCOPE=SPFILE;
66

7+
sqlplus / as sysdba
8+
79
SHUTDOWN ABORT;
810
STARTUP;
911

10-
exit;
12+
exit

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<module>semantickernel-bom</module>
7272
<module>semantickernel-api</module>
7373
<module>semantickernel-experimental</module>
74+
<module>samples</module>
7475
<module>aiservices/openai</module>
7576
<module>aiservices/google</module>
7677
<module>aiservices/huggingface</module>

samples/semantickernel-concepts/semantickernel-syntax-examples/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,13 @@
138138
</dependency>
139139
<dependency>
140140
<groupId>com.microsoft.semantic-kernel</groupId>
141-
<artifactId>semantickernel-data-postgres</artifactId>
142-
<version>1.4.4-RC2-SNAPSHOT</version>
141+
<artifactId>semantickernel-data-jdbc</artifactId>
142+
<version>1.4.4-SNAPSHOT</version>
143+
</dependency>
144+
<dependency>
145+
<groupId>com.microsoft.semantic-kernel</groupId>
146+
<artifactId>semantickernel-learn-resources</artifactId>
147+
<version>1.4.4-SNAPSHOT</version>
143148
<scope>compile</scope>
144149
</dependency>
145150
</dependencies>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
package com.microsoft.semantickernel.samples.syntaxexamples.memory;
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.oracle.OracleVectorStoreQueryProvider;
9+
import com.microsoft.semantickernel.data.vectorstorage.VectorStoreRecordCollection;
10+
import com.microsoft.semantickernel.samples.documentationexamples.data.index.Hotel;
11+
import java.sql.SQLException;
12+
import java.util.Collections;
13+
import oracle.jdbc.datasource.impl.OracleDataSource;
14+
15+
public class VectorStoreWithOracle {
16+
17+
public static void main(String[] args) throws SQLException {
18+
System.out.println("==============================================================");
19+
System.out.println("============== Oracle Vector Store Example ===================");
20+
System.out.println("==============================================================");
21+
22+
// Configure the data source
23+
OracleDataSource dataSource = new OracleDataSource();
24+
dataSource.setURL("jdbc:oracle:thin:@localhost:1521/FREEPDB1");
25+
dataSource.setUser("scott");
26+
dataSource.setPassword("tiger");
27+
28+
// Build a query provider
29+
OracleVectorStoreQueryProvider queryProvider = OracleVectorStoreQueryProvider.builder()
30+
.withDataSource(dataSource)
31+
.build();
32+
33+
// Build a vector store
34+
JDBCVectorStore vectorStore = JDBCVectorStore.builder()
35+
.withDataSource(dataSource)
36+
.withOptions(JDBCVectorStoreOptions.builder()
37+
.withQueryProvider(queryProvider)
38+
.build())
39+
.build();
40+
41+
// Get a collection from the vector store
42+
VectorStoreRecordCollection<String, Hotel> collection =
43+
vectorStore.getCollection("skhotels",
44+
JDBCVectorStoreRecordCollectionOptions.<Hotel>builder()
45+
.withRecordClass(Hotel.class)
46+
.build());
47+
48+
// Create the collection if it doesn't exist yet.
49+
collection.createCollectionAsync().block();
50+
51+
collection.upsertAsync(new Hotel("1",
52+
"HotelOne",
53+
"Desc for HotelOne",
54+
Collections.emptyList(), Collections.emptyList()),
55+
null)
56+
.block();
57+
58+
}
59+
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)