i ran the spring javaformat maven plugin to clean up any source code incompatabilities.

This commit is contained in:
Josh Long
2024-05-06 12:36:37 +02:00
committed by Christian Tzolov
parent 8c758617f3
commit c5b7dd9c46
8 changed files with 53 additions and 47 deletions

View File

@@ -109,37 +109,37 @@ public class AzureVectorStore implements VectorStore, ApplicationListener<Applic
List<SearchField> fields = new ArrayList<>();
fields.add(new SearchField(ID_FIELD_NAME, SearchFieldDataType.STRING).setKey(true)
.setFilterable(true)
.setSortable(true));
.setFilterable(true)
.setSortable(true));
fields.add(new SearchField(EMBEDDING_FIELD_NAME, SearchFieldDataType.collection(SearchFieldDataType.SINGLE))
.setSearchable(true)
.setVectorSearchDimensions(dimensions)
// This must match a vector search configuration name.
.setVectorSearchProfileName(SPRING_AI_VECTOR_PROFILE));
.setSearchable(true)
.setVectorSearchDimensions(dimensions)
// This must match a vector search configuration name.
.setVectorSearchProfileName(SPRING_AI_VECTOR_PROFILE));
fields.add(new SearchField(CONTENT_FIELD_NAME, SearchFieldDataType.STRING).setSearchable(true)
.setFilterable(true));
.setFilterable(true));
fields.add(new SearchField(METADATA_FIELD_NAME, SearchFieldDataType.STRING).setSearchable(true)
.setFilterable(true));
.setFilterable(true));
for (MetadataField filterableMetadataField : this.filterMetadataFields) {
fields.add(new SearchField(METADATA_FIELD_PREFIX + filterableMetadataField.name(),
filterableMetadataField.fieldType())
.setSearchable(false)
.setFacetable(true));
.setSearchable(false)
.setFacetable(true));
}
SearchIndex searchIndex = new SearchIndex(this.indexName).setFields(fields)
// VectorSearch configuration is required for a vector field. The name used
// for the vector search algorithm configuration must match the configuration
// used by the search field used for vector search.
.setVectorSearch(new VectorSearch()
.setProfiles(Collections
.singletonList(new VectorSearchProfile(SPRING_AI_VECTOR_PROFILE, SPRING_AI_VECTOR_CONFIG)))
.setAlgorithms(Collections.singletonList(new HnswAlgorithmConfiguration(SPRING_AI_VECTOR_CONFIG)
.setParameters(new HnswParameters().setM(4)
.setEfConstruction(400)
.setEfSearch(1000)
.setMetric(VectorSearchAlgorithmMetric.COSINE)))));
// VectorSearch configuration is required for a vector field. The name used
// for the vector search algorithm configuration must match the configuration
// used by the search field used for vector search.
.setVectorSearch(new VectorSearch()
.setProfiles(Collections
.singletonList(new VectorSearchProfile(SPRING_AI_VECTOR_PROFILE, SPRING_AI_VECTOR_CONFIG)))
.setAlgorithms(Collections.singletonList(new HnswAlgorithmConfiguration(SPRING_AI_VECTOR_CONFIG)
.setParameters(new HnswParameters().setM(4)
.setEfConstruction(400)
.setEfSearch(1000)
.setMetric(VectorSearchAlgorithmMetric.COSINE)))));
SearchIndex index = this.searchIndexClient.createOrUpdateIndex(searchIndex);

View File

@@ -32,7 +32,8 @@ import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Converts {@link org.springframework.ai.vectorstore.filter.Filter.Expression} into CQL where clauses.
* Converts {@link org.springframework.ai.vectorstore.filter.Filter.Expression} into CQL
* where clauses.
*
* @author Mick Semb Wever
* @since 1.0.0

View File

@@ -153,4 +153,5 @@ public class ChromaVectorStore implements VectorStore, ApplicationListener<Appli
}
this.collectionId = collection.id();
}
}

View File

@@ -226,4 +226,5 @@ public class ElasticsearchVectorStore implements VectorStore, ApplicationListene
createIndexMapping();
}
}
}

View File

@@ -64,7 +64,7 @@ import org.springframework.util.StringUtils;
* @author Christian Tzolov
* @author Josh Long
*/
public class MilvusVectorStore implements VectorStore, ApplicationListener <ApplicationReadyEvent> {
public class MilvusVectorStore implements VectorStore, ApplicationListener<ApplicationReadyEvent> {
private static final Logger logger = LoggerFactory.getLogger(MilvusVectorStore.class);

View File

@@ -52,8 +52,8 @@ public class Neo4jVectorStore implements VectorStore, ApplicationListener<Applic
this.name = name;
}
}
/**
* Configuration for the Neo4j vector store.
*/
@@ -74,6 +74,7 @@ public class Neo4jVectorStore implements VectorStore, ApplicationListener<Applic
// needed for similarity search call
private final String indexNameNotSanitized;
private final String idProperty;
private final String constraintName;
@@ -251,7 +252,6 @@ public class Neo4jVectorStore implements VectorStore, ApplicationListener<Applic
return new Neo4jVectorStoreConfig(this);
}
}
}
@@ -262,9 +262,9 @@ public class Neo4jVectorStore implements VectorStore, ApplicationListener<Applic
try (var session = this.driver.session(this.config.sessionConfig)) {
session
.run("CREATE CONSTRAINT %s IF NOT EXISTS FOR (n:%s) REQUIRE n.%s IS UNIQUE"
.formatted(this.config.constraintName, this.config.label, this.config.idProperty))
.consume();
.run("CREATE CONSTRAINT %s IF NOT EXISTS FOR (n:%s) REQUIRE n.%s IS UNIQUE"
.formatted(this.config.constraintName, this.config.label, this.config.idProperty))
.consume();
var statement = """
CREATE VECTOR INDEX %s IF NOT EXISTS FOR (n:%s) ON (n.%s)

View File

@@ -52,7 +52,7 @@ import org.springframework.util.StringUtils;
* @author Christian Tzolov
* @author Josh Long
*/
public class PgVectorStore implements VectorStore, ApplicationListener <ApplicationReadyEvent> {
public class PgVectorStore implements VectorStore, ApplicationListener<ApplicationReadyEvent> {
private static final Logger logger = LoggerFactory.getLogger(PgVectorStore.class);
@@ -82,7 +82,7 @@ public class PgVectorStore implements VectorStore, ApplicationListener <Applicat
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
try {
try {
// Enable the PGVector, JSONB and UUID support.
this.jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS vector");
this.jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS hstore");
@@ -105,12 +105,14 @@ public class PgVectorStore implements VectorStore, ApplicationListener <Applicat
if (this.createIndexMethod != PgIndexType.NONE) {
this.jdbcTemplate.execute(String.format("""
CREATE INDEX IF NOT EXISTS %s ON %s USING %s (embedding %s)
""", VECTOR_INDEX_NAME, VECTOR_TABLE_NAME, this.createIndexMethod, this.getDistanceType().index));
""", VECTOR_INDEX_NAME, VECTOR_TABLE_NAME, this.createIndexMethod,
this.getDistanceType().index));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* By default, pgvector performs exact nearest neighbor search, which provides perfect

View File

@@ -58,6 +58,7 @@ import static io.qdrant.client.WithPayloadSelectorFactory.enable;
public class QdrantVectorStore implements VectorStore, ApplicationListener<ApplicationReadyEvent> {
private static final String CONTENT_FIELD_NAME = "doc_content";
private static final String DISTANCE_FIELD_NAME = "distance";
public static final String DEFAULT_COLLECTION_NAME = "vector_store";
@@ -89,6 +90,7 @@ public class QdrantVectorStore implements VectorStore, ApplicationListener<Appli
private QdrantVectorStoreConfig(Builder builder) {
this.collectionName = builder.collectionName;
}
/**
* Start building a new configuration.
* @return The entry point for creating a new configuration.
@@ -127,10 +129,10 @@ public class QdrantVectorStore implements VectorStore, ApplicationListener<Appli
return new QdrantVectorStoreConfig(this);
}
}
}
/**
* Constructs a new QdrantVectorStore.
* @param config The configuration for the store.
@@ -165,16 +167,16 @@ public class QdrantVectorStore implements VectorStore, ApplicationListener<Appli
// Create the collection if it does not exist.
if (!isCollectionExists()) {
var vectorParams = VectorParams.newBuilder()
.setDistance(Distance.Cosine)
.setSize(this.embeddingClient.dimensions())
.build();
try {
this.qdrantClient.createCollectionAsync(this.collectionName, vectorParams).get();
} //
catch (Exception e) {
throw new RuntimeException(e);
}
}
.setDistance(Distance.Cosine)
.setSize(this.embeddingClient.dimensions())
.build();
try {
this.qdrantClient.createCollectionAsync(this.collectionName, vectorParams).get();
} //
catch (Exception e) {
throw new RuntimeException(e);
}
}
}
/**
@@ -303,7 +305,6 @@ public class QdrantVectorStore implements VectorStore, ApplicationListener<Appli
return doubleList.stream().map(d -> d.floatValue()).toList();
}
private boolean isCollectionExists() {
try {
return this.qdrantClient.listCollectionsAsync().get().stream().anyMatch(c -> c.equals(this.collectionName));