Introduce checkstyle plugin
- Based on https://github.com/spring-io/spring-javaformat - In this iteration, checkstyles are only enabled for spring-ai-core
This commit is contained in:
committed by
Mark Pollack
parent
33a72417e1
commit
8e758dbd00
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2023 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.postgresml;
|
||||
|
||||
import java.sql.Array;
|
||||
@@ -54,34 +55,6 @@ public class PostgresMlEmbeddingModel extends AbstractEmbeddingModel implements
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public enum VectorType {
|
||||
|
||||
PG_ARRAY("", null, (rs, i) -> {
|
||||
Array embedding = rs.getArray("embedding");
|
||||
return EmbeddingUtils.toPrimitive((Float[]) embedding.getArray());
|
||||
|
||||
}),
|
||||
|
||||
PG_VECTOR("::vector", "vector", (rs, i) -> {
|
||||
String embedding = rs.getString("embedding");
|
||||
return EmbeddingUtils.toPrimitive(Arrays.stream((embedding.substring(1, embedding.length() - 1)
|
||||
/* remove leading '[' and trailing ']' */.split(","))).map(Float::parseFloat).toList());
|
||||
});
|
||||
|
||||
private final String cast;
|
||||
|
||||
private final String extensionName;
|
||||
|
||||
private final RowMapper<float[]> rowMapper;
|
||||
|
||||
VectorType(String cast, String extensionName, RowMapper<float[]> rowMapper) {
|
||||
this.cast = cast;
|
||||
this.extensionName = extensionName;
|
||||
this.rowMapper = rowMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* a constructor
|
||||
* @param jdbcTemplate JdbcTemplate
|
||||
@@ -237,4 +210,32 @@ public class PostgresMlEmbeddingModel extends AbstractEmbeddingModel implements
|
||||
}
|
||||
}
|
||||
|
||||
public enum VectorType {
|
||||
|
||||
PG_ARRAY("", null, (rs, i) -> {
|
||||
Array embedding = rs.getArray("embedding");
|
||||
return EmbeddingUtils.toPrimitive((Float[]) embedding.getArray());
|
||||
|
||||
}),
|
||||
|
||||
PG_VECTOR("::vector", "vector", (rs, i) -> {
|
||||
String embedding = rs.getString("embedding");
|
||||
return EmbeddingUtils.toPrimitive(Arrays.stream((embedding.substring(1, embedding.length() - 1)
|
||||
/* remove leading '[' and trailing ']' */.split(","))).map(Float::parseFloat).toList());
|
||||
});
|
||||
|
||||
private final String cast;
|
||||
|
||||
private final String extensionName;
|
||||
|
||||
private final RowMapper<float[]> rowMapper;
|
||||
|
||||
VectorType(String cast, String extensionName, RowMapper<float[]> rowMapper) {
|
||||
this.cast = cast;
|
||||
this.extensionName = extensionName;
|
||||
this.rowMapper = rowMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2023 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.postgresml;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -61,6 +62,50 @@ public class PostgresMlEmbeddingOptions implements EmbeddingOptions {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public String getTransformer() {
|
||||
return this.transformer;
|
||||
}
|
||||
|
||||
public void setTransformer(String transformer) {
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
public VectorType getVectorType() {
|
||||
return this.vectorType;
|
||||
}
|
||||
|
||||
public void setVectorType(VectorType vectorType) {
|
||||
this.vectorType = vectorType;
|
||||
}
|
||||
|
||||
public Map<String, Object> getKwargs() {
|
||||
return this.kwargs;
|
||||
}
|
||||
|
||||
public void setKwargs(Map<String, Object> kwargs) {
|
||||
this.kwargs = kwargs;
|
||||
}
|
||||
|
||||
public MetadataMode getMetadataMode() {
|
||||
return this.metadataMode;
|
||||
}
|
||||
|
||||
public void setMetadataMode(MetadataMode metadataMode) {
|
||||
this.metadataMode = metadataMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String getModel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Integer getDimensions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
protected PostgresMlEmbeddingOptions options;
|
||||
@@ -100,48 +145,4 @@ public class PostgresMlEmbeddingOptions implements EmbeddingOptions {
|
||||
|
||||
}
|
||||
|
||||
public String getTransformer() {
|
||||
return this.transformer;
|
||||
}
|
||||
|
||||
public void setTransformer(String transformer) {
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
public VectorType getVectorType() {
|
||||
return this.vectorType;
|
||||
}
|
||||
|
||||
public void setVectorType(VectorType vectorType) {
|
||||
this.vectorType = vectorType;
|
||||
}
|
||||
|
||||
public Map<String, Object> getKwargs() {
|
||||
return this.kwargs;
|
||||
}
|
||||
|
||||
public void setKwargs(Map<String, Object> kwargs) {
|
||||
this.kwargs = kwargs;
|
||||
}
|
||||
|
||||
public MetadataMode getMetadataMode() {
|
||||
return metadataMode;
|
||||
}
|
||||
|
||||
public void setMetadataMode(MetadataMode metadataMode) {
|
||||
this.metadataMode = metadataMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String getModel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Integer getDimensions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2023 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.postgresml;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -26,13 +27,6 @@ import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingRequest;
|
||||
import org.springframework.ai.embedding.EmbeddingResponse;
|
||||
import org.springframework.ai.embedding.EmbeddingResponseMetadata;
|
||||
import org.springframework.ai.postgresml.PostgresMlEmbeddingModel.VectorType;
|
||||
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -41,6 +35,11 @@ import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.document.MetadataMode;
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingRequest;
|
||||
import org.springframework.ai.embedding.EmbeddingResponse;
|
||||
import org.springframework.ai.embedding.EmbeddingResponseMetadata;
|
||||
import org.springframework.ai.postgresml.PostgresMlEmbeddingModel.VectorType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
|
||||
@@ -257,4 +256,4 @@ class PostgresMlEmbeddingModelIT {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2023 - 2024 the original author or authors.
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.postgresml;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
Reference in New Issue
Block a user