|
| 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 | +} |
0 commit comments