Using the JDBC Vector Store connector
Overview
JDBC vector store is a Java-specific feature, available only for Java applications.
Overview
JDBC vector store is a Java-specific feature, available only for Java applications.
Overview
The JDBC Vector Store connector can be used to access and manage data in SQL databases. The connector has the following characteristics.
Feature Area | Support |
---|---|
Collection maps to | SQL database table |
Supported SQL data sources |
|
Supported key property types | String |
Supported data property types |
|
Supported vector property types | List<Float> |
Supported index types |
|
Supported distance functions |
|
Supports multiple vectors in a record | Yes |
isFilterable supported? | Yes |
isFullTextSearchable supported? | No |
storageName supported? | No, use @JsonProperty instead. |
Limitations
PostgreSQL leverages pgvector
for vector indexing and search, uniquely offering approximate search capabilities. Other providers lack support for indexing, providing only exhaustive vector search.
Getting started
Include the latest version of the Semantic Kernel JDBC connector in your Maven project by adding the following dependency to your pom.xml
:
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-data-jdbc</artifactId>
<version>[LATEST]</version>
</dependency>
You can then create a vector store instance using the JDBCVectorStore
class, having the data source as a parameter.
import com.microsoft.semantickernel.data.jdbc.JDBCVectorStore;
import com.microsoft.semantickernel.data.jdbc.JDBCVectorStoreOptions;
import com.microsoft.semantickernel.data.jdbc.JDBCVectorStoreRecordCollection;
import com.microsoft.semantickernel.data.jdbc.JDBCVectorStoreRecordCollectionOptions;
import com.microsoft.semantickernel.data.jdbc.mysql.MySQLVectorStoreQueryProvider;
import org.postgresql.ds.PGSimpleDataSource;
public class Main {
public static void main(String[] args) {
// Configure the data source
PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setUrl("jdbc:postgresql://localhost:5432/sk");
dataSource.setUser("postgres");
dataSource.setPassword("root");
// Build a query provider
// Other available query providers are PostgreSQLVectorStoreQueryProvider, SQLiteVectorStoreQueryProvider
// and HSQDBVectorStoreQueryProvider
var queryProvider = MySQLVectorStoreQueryProvider.builder()
.withDataSource(dataSource)
.build();
// Build a vector store
var vectorStore = JDBCVectorStore.builder()
.withDataSource(dataSource)
.withOptions(JDBCVectorStoreOptions.builder()
.withQueryProvider(queryProvider)
.build())
.build();
}
}
You can also create a collection directly.
var collection = new JDBCVectorStoreRecordCollection<>(
dataSource,
"skhotels",
JDBCVectorStoreRecordCollectionOptions.<Hotel>builder()
.withRecordClass(Hotel.class)
.build()
);