Enhance vector stores with consistent APIs and null safety

- Replace Document.getContent() with getText() across all vector store implementations
- Fix incorrect package declarations in package-info.java files
- Make builder constructors private and implement proper builder patterns
- Add @Nullable annotations for better null safety
- Simplify PineconeVectorStore builder API by requiring essential parameters in factory method
- Make static Map fields final
- Clean up code and improve JavaDoc documentation

The changes focus on making the vector store APIs more consistent,
type-safe, and maintainable while following best practices for
builder patterns and null safety.
This commit is contained in:
Soby Chacko
2024-12-19 19:32:27 -05:00
committed by Mark Pollack
parent ee8bf37359
commit 1a6e79cbb9
39 changed files with 695 additions and 256 deletions

View File

@@ -55,11 +55,9 @@ public class PineconeVectorStoreAutoConfiguration {
ObjectProvider<VectorStoreObservationConvention> customObservationConvention,
BatchingStrategy batchingStrategy) {
return PineconeVectorStore.builder(embeddingModel)
.apiKey(properties.getApiKey())
.environment(properties.getEnvironment())
.projectId(properties.getProjectId())
.indexName(properties.getIndexName())
return PineconeVectorStore
.builder(embeddingModel, properties.getApiKey(), properties.getProjectId(), properties.getEnvironment(),
properties.getIndexName())
.namespace(properties.getNamespace())
.contentFieldName(properties.getContentFieldName())
.distanceMetadataFieldName(properties.getDistanceMetadataFieldName())

View File

@@ -69,6 +69,7 @@ import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationContext;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -108,7 +109,8 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen
* @param cosmosClient the Cosmos DB client
* @param properties the configuration properties
* @param embeddingModel the embedding model
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(CosmosAsyncClient, EmbeddingModel)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CosmosDBVectorStore(ObservationRegistry observationRegistry,
@@ -126,7 +128,8 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen
* @param properties the configuration properties
* @param embeddingModel the embedding model
* @param batchingStrategy the batching strategy
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(CosmosAsyncClient, EmbeddingModel)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CosmosDBVectorStore(ObservationRegistry observationRegistry,
@@ -241,7 +244,7 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen
ObjectMapper objectMapper = new ObjectMapper();
String id = document.getId();
String content = document.getContent();
String content = document.getText();
// Convert metadata and embedding directly to JsonNode
JsonNode metadataNode = objectMapper.valueToTree(document.getMetadata());
@@ -430,10 +433,13 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen
private final CosmosAsyncClient cosmosClient;
@Nullable
private String containerName;
@Nullable
private String databaseName;
@Nullable
private String partitionKeyPath;
private int vectorStoreThroughput = 400;
@@ -444,13 +450,7 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen
private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
/**
* Sets the Cosmos DB client.
* @param cosmosClient the client to use
* @return the builder instance
* @throws IllegalArgumentException if cosmosClient is null
*/
public CosmosDBBuilder(CosmosAsyncClient cosmosClient, EmbeddingModel embeddingModel) {
private CosmosDBBuilder(CosmosAsyncClient cosmosClient, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(cosmosClient, "CosmosClient must not be null");
this.cosmosClient = cosmosClient;

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.cosmosdb;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -62,6 +62,7 @@ import org.springframework.ai.vectorstore.observation.AbstractObservationVectorS
import org.springframework.ai.vectorstore.observation.VectorStoreObservationContext;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -122,6 +123,7 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
*/
private final List<MetadataField> filterMetadataFields;
@Nullable
private SearchClient searchClient;
private int defaultTopK;
@@ -135,7 +137,8 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
* @param searchIndexClient the Azure search index client
* @param embeddingModel the embedding model to use
* @param initializeSchema whether to initialize schema
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(SearchIndexClient, EmbeddingModel)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public AzureVectorStore(SearchIndexClient searchIndexClient, EmbeddingModel embeddingModel,
@@ -149,7 +152,8 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
* @param embeddingModel the embedding model to use
* @param initializeSchema whether to initialize schema
* @param filterMetadataFields list of metadata fields for filtering
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(SearchIndexClient, EmbeddingModel)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public AzureVectorStore(SearchIndexClient searchIndexClient, EmbeddingModel embeddingModel,
@@ -166,7 +170,8 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
* @param filterMetadataFields list of metadata fields for filtering
* @param observationRegistry the observation registry
* @param customObservationConvention the custom observation convention
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(SearchIndexClient, EmbeddingModel)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public AzureVectorStore(SearchIndexClient searchIndexClient, EmbeddingModel embeddingModel,
@@ -208,8 +213,8 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
/**
* Change the Index Name.
* @param indexName The Azure VectorStore index name to use.
* @deprecated Since 1.0.0-M5, use {@link #builder()} with
* {@link AzureBuilder#indexName(String)} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(SearchIndexClient, EmbeddingModel)}
* ()} with {@link AzureBuilder#indexName(String)} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public void setIndexName(String indexName) {
@@ -220,8 +225,8 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
/**
* Sets the a default maximum number of similar documents returned.
* @param topK The default maximum number of similar documents returned.
* @deprecated Since 1.0.0-M5, use {@link #builder()} with
* {@link AzureBuilder#indexName(String)} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(SearchIndexClient, EmbeddingModel)}
* ()} with {@link AzureBuilder#indexName(String)} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public void setDefaultTopK(int topK) {
@@ -233,8 +238,8 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
* Sets the a default similarity threshold for returned documents.
* @param similarityThreshold The a default similarity threshold for returned
* documents.
* @deprecated Since 1.0.0-M5, use {@link #builder()} with
* {@link AzureBuilder#indexName(String)} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(SearchIndexClient, EmbeddingModel)}
* ()} with {@link AzureBuilder#indexName(String)} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public void setDefaultSimilarityThreshold(Double similarityThreshold) {
@@ -258,7 +263,7 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
SearchDocument searchDocument = new SearchDocument();
searchDocument.put(ID_FIELD_NAME, document.getId());
searchDocument.put(EMBEDDING_FIELD_NAME, embeddings.get(documents.indexOf(document)));
searchDocument.put(CONTENT_FIELD_NAME, document.getContent());
searchDocument.put(CONTENT_FIELD_NAME, document.getText());
searchDocument.put(METADATA_FIELD_NAME, new JSONObject(document.getMetadata()).toJSONString());
// Add the filterable metadata fields as top level fields, allowing filler
@@ -481,13 +486,7 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements
private String indexName = DEFAULT_INDEX_NAME;
/**
* Sets the Azure search index client.
* @param searchIndexClient the client to use
* @return the builder instance
* @throws IllegalArgumentException if searchIndexClient is null
*/
public AzureBuilder(SearchIndexClient searchIndexClient, EmbeddingModel embeddingModel) {
private AzureBuilder(SearchIndexClient searchIndexClient, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(searchIndexClient, "SearchIndexClient must not be null");
this.searchIndexClient = searchIndexClient;

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.azure;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -235,7 +235,7 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme
private final boolean returnEmbeddings;
/**
* @deprecated since 1.0.0-M5, use {@link #builder()} instead
* @deprecated since 1.0.0-M5, use {@link #builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CassandraVectorStore(CassandraVectorStoreConfig conf, EmbeddingModel embeddingModel) {
@@ -243,7 +243,7 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated since 1.0.0-M5, use {@link #builder()} instead
* @deprecated since 1.0.0-M5, use {@link #builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CassandraVectorStore(CassandraVectorStoreConfig conf, EmbeddingModel embeddingModel,
@@ -319,7 +319,7 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme
builder = builder.set(keyColumn.name(), primaryKeyValues.get(k), keyColumn.javaType());
}
builder = builder.setString(this.schema.content(), d.getContent())
builder = builder.setString(this.schema.content(), d.getText())
.setVector(this.schema.embedding(),
CqlVector.newInstance(EmbeddingUtils.toList(embeddings.get(documents.indexOf(d)))),
Float.class);

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.cassandra;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -143,7 +143,8 @@ public class CoherenceVectorStore extends AbstractObservationVectorStore impleme
* Creates a new CoherenceVectorStore with minimal configuration.
* @param embeddingModel the embedding model to use
* @param session the Coherence session
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(Session, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CoherenceVectorStore(EmbeddingModel embeddingModel, Session session) {
@@ -177,7 +178,8 @@ public class CoherenceVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(Session, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CoherenceVectorStore setMapName(String mapName) {
@@ -186,7 +188,8 @@ public class CoherenceVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(Session, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CoherenceVectorStore setDistanceType(DistanceType distanceType) {
@@ -195,7 +198,8 @@ public class CoherenceVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(Session, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CoherenceVectorStore setIndexType(IndexType indexType) {
@@ -204,7 +208,8 @@ public class CoherenceVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(Session, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public CoherenceVectorStore setForcedNormalization(boolean forcedNormalization) {
@@ -217,7 +222,7 @@ public class CoherenceVectorStore extends AbstractObservationVectorStore impleme
Map<DocumentChunk.Id, DocumentChunk> chunks = new HashMap<>((int) Math.ceil(documents.size() / 0.75f));
for (Document doc : documents) {
var id = toChunkId(doc.getId());
var chunk = new DocumentChunk(doc.getContent(), doc.getMetadata(),
var chunk = new DocumentChunk(doc.getText(), doc.getMetadata(),
toFloat32Vector(this.embeddingModel.embed(doc)));
chunks.put(id, chunk);
}
@@ -342,13 +347,7 @@ public class CoherenceVectorStore extends AbstractObservationVectorStore impleme
private IndexType indexType = IndexType.NONE;
/**
* Sets the Coherence session.
* @param session the session to use
* @return the builder instance
* @throws IllegalArgumentException if session is null
*/
public CoherenceBuilder(Session session, EmbeddingModel embeddingModel) {
private CoherenceBuilder(Session session, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(session, "Session must not be null");
this.session = session;

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.coherence;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -156,7 +156,7 @@ public class ElasticsearchVectorStore extends AbstractObservationVectorStore imp
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchVectorStore.class);
private static Map<SimilarityFunction, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(
private static final Map<SimilarityFunction, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(
SimilarityFunction.cosine, VectorStoreSimilarityMetric.COSINE, SimilarityFunction.l2_norm,
VectorStoreSimilarityMetric.EUCLIDEAN, SimilarityFunction.dot_product, VectorStoreSimilarityMetric.DOT);
@@ -224,7 +224,7 @@ public class ElasticsearchVectorStore extends AbstractObservationVectorStore imp
this.batchingStrategy);
for (Document document : documents) {
ElasticSearchDocument doc = new ElasticSearchDocument(document.getId(), document.getContent(),
ElasticSearchDocument doc = new ElasticSearchDocument(document.getId(), document.getText(),
document.getMetadata(), embeddings.get(documents.indexOf(document)));
bulkRequestBuilder.operations(
op -> op.index(idx -> idx.index(this.options.getIndexName()).id(document.getId()).document(doc)));

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.elasticsearch;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -31,7 +31,6 @@ import io.micrometer.observation.ObservationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.DocumentMetadata;
import reactor.util.annotation.NonNull;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.BatchingStrategy;
@@ -48,6 +47,7 @@ import org.springframework.ai.vectorstore.observation.VectorStoreObservationConv
import org.springframework.beans.factory.InitializingBean;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
@@ -126,7 +126,7 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
* @param config the vector store configuration
* @param embeddingModel the embedding model to use
* @param initializeSchema whether to initialize schema
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public GemFireVectorStore(GemFireVectorStoreConfig config, EmbeddingModel embeddingModel,
@@ -142,7 +142,7 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
* @param initializeSchema whether to initialize schema
* @param observationRegistry the observation registry
* @param customObservationConvention the custom observation convention
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public GemFireVectorStore(GemFireVectorStoreConfig config, EmbeddingModel embeddingModel, boolean initializeSchema,
@@ -240,6 +240,7 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
return !indexResponse.isEmpty();
}
@Nullable
public String getIndex() {
return this.client.get()
.uri("/" + this.indexName)
@@ -255,7 +256,7 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
this.batchingStrategy);
UploadRequest upload = new UploadRequest(documents.stream()
.map(document -> new UploadRequest.Embedding(document.getId(), embeddings.get(documents.indexOf(document)),
DOCUMENT_FIELD, document.getContent(), document.getMetadata()))
DOCUMENT_FIELD, document.getText(), document.getMetadata()))
.toList());
String embeddingsJson = null;
@@ -295,6 +296,7 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
@Override
@Nullable
public List<Document> doSimilaritySearch(SearchRequest request) {
if (request.hasFilterExpression()) {
throw new UnsupportedOperationException("GemFire currently does not support metadata filter expressions.");
@@ -514,7 +516,6 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
private static final class QueryRequest {
@JsonProperty("vector")
@NonNull
private final float[] vector;
@JsonProperty("top-k")
@@ -649,7 +650,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
boolean sslEnabled;
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()} instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
private GemFireVectorStoreConfig(Builder builder) {
@@ -667,7 +669,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
/**
* Start building a new configuration.
* @return The entry point for creating a new configuration.
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()} instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public static Builder builder() {
@@ -675,7 +678,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()} instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public static class Builder {
@@ -700,8 +704,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
boolean sslEnabled = GemFireVectorStoreConfig.DEFAULT_SSL_ENABLED;
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setHost(String host) {
@@ -711,8 +715,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setPort(int port) {
@@ -722,8 +726,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setSslEnabled(boolean sslEnabled) {
@@ -732,8 +736,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setIndexName(String indexName) {
@@ -743,8 +747,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setBeamWidth(int beamWidth) {
@@ -756,8 +760,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setMaxConnections(int maxConnections) {
@@ -770,8 +774,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setBuckets(int buckets) {
@@ -781,8 +785,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setVectorSimilarityFunction(String vectorSimilarityFunction) {
@@ -792,8 +796,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder setFields(String[] fields) {
@@ -802,8 +806,8 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Since 1.0.0-M5, use {@link GemFireVectorStore#builder()}
* instead
* @deprecated Since 1.0.0-M5, use
* {@link GemFireVectorStore#builder(EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public GemFireVectorStoreConfig build() {

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.gemfire;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -39,6 +39,7 @@ import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationContext;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -93,7 +94,8 @@ public class HanaCloudVectorStore extends AbstractObservationVectorStore {
* @param repository the HANA vector repository
* @param embeddingModel the embedding model to use
* @param config the vector store configuration
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use
* {@link #builder(HanaVectorRepository, EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public HanaCloudVectorStore(HanaVectorRepository<? extends HanaVectorEntity> repository,
@@ -108,7 +110,8 @@ public class HanaCloudVectorStore extends AbstractObservationVectorStore {
* @param config the vector store configuration
* @param observationRegistry the observation registry
* @param customObservationConvention the custom observation convention
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use
* {@link #builder(HanaVectorRepository, EmbeddingModel)} ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public HanaCloudVectorStore(HanaVectorRepository<? extends HanaVectorEntity> repository,
@@ -152,7 +155,7 @@ public class HanaCloudVectorStore extends AbstractObservationVectorStore {
for (Document document : documents) {
logger.info("[{}/{}] Calling EmbeddingModel for document id = {}", count++, documents.size(),
document.getId());
String content = document.getContent().replaceAll("\\s+", " ");
String content = document.getText().replaceAll("\\s+", " ");
String embedding = getEmbedding(document);
this.repository.save(this.tableName, document.getId(), embedding, content);
}
@@ -234,6 +237,7 @@ public class HanaCloudVectorStore extends AbstractObservationVectorStore {
private final HanaVectorRepository<? extends HanaVectorEntity> repository;
@Nullable
private String tableName;
private int topK;
@@ -244,7 +248,7 @@ public class HanaCloudVectorStore extends AbstractObservationVectorStore {
* @return the builder instance
* @throws IllegalArgumentException if repository is null
*/
public HanaCloudBuilder(HanaVectorRepository<? extends HanaVectorEntity> repository,
private HanaCloudBuilder(HanaVectorRepository<? extends HanaVectorEntity> repository,
EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(repository, "Repository must not be null");

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.hanadb;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -196,7 +196,8 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
private final int maxDocumentBatchSize;
/**
* @deprecated Use {@link #builder(JdbcTemplate)} instead
* @deprecated Use {@link #builder(JdbcTemplate, EmbeddingModel)} (JdbcTemplate)}
* instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public MariaDBVectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) {
@@ -204,7 +205,8 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Use {@link #builder(JdbcTemplate)} instead
* @deprecated Use {@link #builder(JdbcTemplate, EmbeddingModel)} (JdbcTemplate)}
* instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public MariaDBVectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel, int dimensions) {
@@ -212,7 +214,8 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Use {@link #builder(JdbcTemplate)} instead
* @deprecated Use {@link #builder(JdbcTemplate, EmbeddingModel)} (JdbcTemplate)}
* instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public MariaDBVectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel, int dimensions,
@@ -222,7 +225,8 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Use {@link #builder(JdbcTemplate)} instead
* @deprecated Use {@link #builder(JdbcTemplate, EmbeddingModel)} (JdbcTemplate)}
* instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public MariaDBVectorStore(String vectorTableName, JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel,
@@ -233,7 +237,8 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Use {@link #builder(JdbcTemplate)} instead
* @deprecated Use {@link #builder(JdbcTemplate, EmbeddingModel)} (JdbcTemplate)}
* instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
private MariaDBVectorStore(String schemaName, String vectorTableName, boolean vectorTableValidationsEnabled,
@@ -246,7 +251,8 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
}
/**
* @deprecated Use {@link #builder(JdbcTemplate)} instead
* @deprecated Use {@link #builder(JdbcTemplate, EmbeddingModel)} (JdbcTemplate)}
* instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
private MariaDBVectorStore(String schemaName, String vectorTableName, boolean vectorTableValidationsEnabled,
@@ -286,12 +292,10 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
this.objectMapper = JsonMapper.builder().addModules(JacksonUtils.instantiateAvailableModules()).build();
this.vectorTableName = (null == builder.vectorTableName || builder.vectorTableName.isEmpty())
? DEFAULT_TABLE_NAME
this.vectorTableName = builder.vectorTableName.isEmpty() ? DEFAULT_TABLE_NAME
: MariaDBSchemaValidator.validateAndEnquoteIdentifier(builder.vectorTableName.trim(), false);
logger.info("Using the vector table name: {}. Is empty: {}", this.vectorTableName,
(vectorTableName == null || vectorTableName.isEmpty()));
logger.info("Using the vector table name: {}. Is empty: {}", this.vectorTableName, vectorTableName.isEmpty());
this.schemaName = builder.schemaName == null ? null
: MariaDBSchemaValidator.validateAndEnquoteIdentifier(builder.schemaName, false);
@@ -341,14 +345,14 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
List<MariaDBDocument> mariaDBDocuments = new ArrayList<>(documents.size());
if (embeddings.size() == documents.size()) {
for (Document document : documents) {
mariaDBDocuments.add(new MariaDBDocument(document.getId(), document.getContent(),
document.getMetadata(), embeddings.get(documents.indexOf(document))));
mariaDBDocuments.add(new MariaDBDocument(document.getId(), document.getText(), document.getMetadata(),
embeddings.get(documents.indexOf(document))));
}
}
else {
for (Document document : documents) {
mariaDBDocuments
.add(new MariaDBDocument(document.getId(), document.getContent(), document.getMetadata(), null));
.add(new MariaDBDocument(document.getId(), document.getText(), document.getMetadata(), null));
}
}
@@ -571,6 +575,7 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
private final JdbcTemplate jdbcTemplate;
@Nullable
private String schemaName;
private String vectorTableName = DEFAULT_TABLE_NAME;
@@ -940,7 +945,8 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement
* @param metadata The metadata of the document
* @param embedding The vectors representing the content of the document
*/
public record MariaDBDocument(String id, String content, Map<String, Object> metadata, float[] embedding) {
public record MariaDBDocument(String id, @Nullable String content, Map<String, Object> metadata,
@Nullable float[] embedding) {
}
}

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.mariadb;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -169,9 +169,9 @@ public class MilvusVectorStore extends AbstractObservationVectorStore implements
private static final Logger logger = LoggerFactory.getLogger(MilvusVectorStore.class);
private static Map<MetricType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(MetricType.COSINE,
VectorStoreSimilarityMetric.COSINE, MetricType.L2, VectorStoreSimilarityMetric.EUCLIDEAN, MetricType.IP,
VectorStoreSimilarityMetric.DOT);
private static final Map<MetricType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(
MetricType.COSINE, VectorStoreSimilarityMetric.COSINE, MetricType.L2, VectorStoreSimilarityMetric.EUCLIDEAN,
MetricType.IP, VectorStoreSimilarityMetric.DOT);
public final FilterExpressionConverter filterExpressionConverter = new MilvusFilterExpressionConverter();
@@ -288,7 +288,7 @@ public class MilvusVectorStore extends AbstractObservationVectorStore implements
docIdArray.add(document.getId());
// Use a (future) DocumentTextLayoutFormatter instance to extract
// the content used to compute the embeddings
contentArray.add(document.getContent());
contentArray.add(document.getText());
metadataArray.add(new JSONObject(document.getMetadata()));
embeddingArray.add(EmbeddingUtils.toList(embeddings.get(documents.indexOf(document))));
}

View File

@@ -294,7 +294,7 @@ public class MongoDBAtlasVectorStore extends AbstractObservationVectorStore impl
List<float[]> embeddings = this.embeddingModel.embed(documents, EmbeddingOptionsBuilder.builder().build(),
this.batchingStrategy);
for (Document document : documents) {
MongoDBDocument mdbDocument = new MongoDBDocument(document.getId(), document.getContent(),
MongoDBDocument mdbDocument = new MongoDBDocument(document.getId(), document.getText(),
document.getMetadata(), embeddings.get(documents.indexOf(document)));
this.mongoTemplate.save(mdbDocument, this.collectionName);
}
@@ -379,7 +379,7 @@ public class MongoDBAtlasVectorStore extends AbstractObservationVectorStore impl
/**
* @throws IllegalArgumentException if mongoTemplate is null
*/
public MongoDBBuilder(MongoTemplate mongoTemplate, EmbeddingModel embeddingModel) {
private MongoDBBuilder(MongoTemplate mongoTemplate, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(mongoTemplate, "MongoTemplate must not be null");
this.mongoTemplate = mongoTemplate;

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.mongodb.atlas;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -154,7 +154,7 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements
public static final String DEFAULT_CONSTRAINT_NAME = DEFAULT_LABEL + "_unique_idx";
private static Map<Neo4jDistanceType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(
private static final Map<Neo4jDistanceType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(
Neo4jDistanceType.COSINE, VectorStoreSimilarityMetric.COSINE, Neo4jDistanceType.EUCLIDEAN,
VectorStoreSimilarityMetric.EUCLIDEAN);
@@ -339,7 +339,7 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements
row.put("id", document.getId());
var properties = new HashMap<String, Object>();
properties.put("text", document.getContent());
properties.put("text", document.getText());
document.getMetadata().forEach((k, v) -> properties.put("metadata." + k, Values.value(v)));
row.put("properties", properties);
@@ -426,7 +426,7 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements
private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
public Neo4jBuilder(Driver driver, EmbeddingModel embeddingModel) {
private Neo4jBuilder(Driver driver, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(driver, "Neo4j driver must not be null");
this.driver = driver;

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.neo4j;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -176,7 +176,7 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem
/**
* Creates a new OpenSearchVectorStore with default mapping and collection name.
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(OpenSearchClient, EmbeddingModel)} ()} instead
* @param openSearchClient The OpenSearch client
* @param embeddingModel The embedding model to use
* @param initializeSchema Whether to initialize the schema
@@ -190,7 +190,7 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem
/**
* Creates a new OpenSearchVectorStore with custom mapping.
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(OpenSearchClient, EmbeddingModel)} ()} instead
* @param openSearchClient The OpenSearch client
* @param embeddingModel The embedding model to use
* @param mappingJson The JSON mapping for the index
@@ -205,7 +205,7 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem
/**
* Creates a new OpenSearchVectorStore with custom index name and mapping.
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(OpenSearchClient, EmbeddingModel)} ()} instead
* @param index The name of the index
* @param openSearchClient The OpenSearch client
* @param embeddingModel The embedding model to use
@@ -222,7 +222,7 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem
/**
* Creates a new OpenSearchVectorStore with all configuration options.
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(OpenSearchClient, EmbeddingModel)} ()} instead
* @param index The name of the index
* @param openSearchClient The OpenSearch client
* @param embeddingModel The embedding model to use
@@ -285,7 +285,7 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem
this.batchingStrategy);
BulkRequest.Builder bulkRequestBuilder = new BulkRequest.Builder();
for (Document document : documents) {
OpenSearchDocument openSearchDocument = new OpenSearchDocument(document.getId(), document.getContent(),
OpenSearchDocument openSearchDocument = new OpenSearchDocument(document.getId(), document.getText(),
document.getMetadata(), embedding.get(documents.indexOf(document)));
bulkRequestBuilder.operations(op -> op
.index(idx -> idx.index(this.index).id(openSearchDocument.id()).document(openSearchDocument)));
@@ -468,7 +468,7 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem
* @return The builder instance
* @throws IllegalArgumentException if openSearchClient is null
*/
public OpenSearchBuilder(OpenSearchClient openSearchClient, EmbeddingModel embeddingModel) {
private OpenSearchBuilder(OpenSearchClient openSearchClient, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(openSearchClient, "OpenSearchClient must not be null");
this.openSearchClient = openSearchClient;

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.opensearch;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -101,10 +101,10 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements
private static final Logger logger = LoggerFactory.getLogger(OracleVectorStore.class);
private static Map<OracleVectorStoreDistanceType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(
OracleVectorStoreDistanceType.COSINE, VectorStoreSimilarityMetric.COSINE,
OracleVectorStoreDistanceType.EUCLIDEAN, VectorStoreSimilarityMetric.EUCLIDEAN,
OracleVectorStoreDistanceType.DOT, VectorStoreSimilarityMetric.DOT);
private static final Map<OracleVectorStoreDistanceType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map
.of(OracleVectorStoreDistanceType.COSINE, VectorStoreSimilarityMetric.COSINE,
OracleVectorStoreDistanceType.EUCLIDEAN, VectorStoreSimilarityMetric.EUCLIDEAN,
OracleVectorStoreDistanceType.DOT, VectorStoreSimilarityMetric.DOT);
public final FilterExpressionConverter filterExpressionConverter = new SqlJsonPathFilterExpressionConverter();
@@ -150,7 +150,8 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements
* Creates a new OracleVectorStore with default configuration.
* @param jdbcTemplate the JDBC template to use
* @param embeddingModel the embedding model to use
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(JdbcTemplate, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public OracleVectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) {
@@ -163,7 +164,8 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements
* @param jdbcTemplate the JDBC template to use
* @param embeddingModel the embedding model to use
* @param initializeSchema whether to initialize the schema
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(JdbcTemplate, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public OracleVectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel, boolean initializeSchema) {
@@ -183,7 +185,8 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements
* @param initializeSchema whether to initialize the schema
* @param removeExistingVectorStoreTable whether to remove existing vector store table
* @param forcedNormalization whether to force vector normalization
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(JdbcTemplate, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public OracleVectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel, String tableName,
@@ -211,7 +214,8 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements
* @param observationRegistry the observation registry
* @param customObservationConvention the custom observation convention
* @param batchingStrategy the batching strategy
* @deprecated Since 1.0.0-M5, use {@link #builder()} instead
* @deprecated Since 1.0.0-M5, use {@link #builder(JdbcTemplate, EmbeddingModel)} ()}
* instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public OracleVectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel, String tableName,
@@ -268,7 +272,7 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
final Document document = documents.get(i);
final String content = document.getContent();
final String content = document.getText();
final byte[] json = toJson(document.getMetadata());
final VECTOR embeddingVector = toVECTOR(embeddings.get(documents.indexOf(document)));
@@ -745,7 +749,7 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements
*/
public static class OracleBuilder extends AbstractVectorStoreBuilder<OracleBuilder> {
private JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
private String tableName = DEFAULT_TABLE_NAME;

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.oracle;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -260,9 +260,9 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini
this.objectMapper = JsonMapper.builder().addModules(JacksonUtils.instantiateAvailableModules()).build();
String vectorTable = builder.vectorTableName;
this.vectorTableName = (null == vectorTable || vectorTable.isEmpty()) ? DEFAULT_TABLE_NAME : vectorTable.trim();
this.vectorTableName = vectorTable.isEmpty() ? DEFAULT_TABLE_NAME : vectorTable.trim();
logger.info("Using the vector table name: {}. Is empty: {}", this.vectorTableName,
(this.vectorTableName == null || this.vectorTableName.isEmpty()));
this.vectorTableName.isEmpty());
this.vectorIndexName = this.vectorTableName.equals(DEFAULT_TABLE_NAME) ? DEFAULT_VECTOR_INDEX_NAME
: this.vectorTableName + "_index";
@@ -317,7 +317,7 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini
public void setValues(PreparedStatement ps, int i) throws SQLException {
var document = batch.get(i);
var content = document.getContent();
var content = document.getText();
var json = toJson(document.getMetadata());
var embedding = embeddings.get(documents.indexOf(document));
var pGvector = new PGvector(embedding);
@@ -388,7 +388,6 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini
new RowMapper<Double>() {
@Override
@Nullable
public Double mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getDouble(DocumentRowMapper.COLUMN_DISTANCE);
}
@@ -624,7 +623,7 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini
public static class PgVectorStoreBuilder extends AbstractVectorStoreBuilder<PgVectorStoreBuilder> {
private JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
private String schemaName = PgVectorStore.DEFAULT_SCHEMA_NAME;

View File

@@ -52,6 +52,7 @@ import org.springframework.ai.vectorstore.filter.converter.PineconeFilterExpress
import org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationContext;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -87,7 +88,8 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* Constructs a new PineconeVectorStore.
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(EmbeddingModel, String, String, String, String)}
* ()} instead
* @param config The configuration for the store
* @param embeddingModel The client for embedding operations
*/
@@ -98,7 +100,8 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* Constructs a new PineconeVectorStore.
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(EmbeddingModel, String, String, String, String)}
* ()} instead
* @param config The configuration for the store
* @param embeddingModel The client for embedding operations
* @param observationRegistry The registry for observations
@@ -109,10 +112,8 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
public PineconeVectorStore(PineconeVectorStoreConfig config, EmbeddingModel embeddingModel,
ObservationRegistry observationRegistry, VectorStoreObservationConvention customObservationConvention,
BatchingStrategy batchingStrategy) {
this(builder(embeddingModel).apiKey(config.clientConfig.getApiKey())
.projectId(config.clientConfig.getProjectName())
.environment(config.clientConfig.getEnvironment())
.indexName(config.connectionConfig.getIndexName())
this(builder(embeddingModel, config.clientConfig.getApiKey(), config.clientConfig.getProjectName(),
config.clientConfig.getEnvironment(), config.connectionConfig.getIndexName())
.namespace(config.namespace)
.contentFieldName(config.contentFieldName)
.distanceMetadataFieldName(config.distanceMetadataFieldName)
@@ -155,8 +156,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Creates a new builder instance for configuring a PineconeVectorStore.
* @return A new PineconeBuilder instance
*/
public static PineconeBuilder builder(EmbeddingModel embeddingModel) {
return new PineconeBuilder(embeddingModel);
public static PineconeBuilder builder(EmbeddingModel embeddingModel, String apiKey, String projectId,
String environment, String indexName) {
return new PineconeBuilder(embeddingModel, apiKey, projectId, environment, indexName);
}
/**
@@ -217,7 +219,7 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* @return The content value.
*/
private Value contentValue(Document document) {
return Value.newBuilder().setStringValue(document.getContent()).build();
return Value.newBuilder().setStringValue(document.getText()).build();
}
/**
@@ -297,8 +299,7 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
try {
var structBuilder = Struct.newBuilder();
JsonFormat.parser().ignoringUnknownFields().merge(metadataFilters, structBuilder);
var filterStruct = structBuilder.build();
return filterStruct;
return structBuilder.build();
}
catch (Exception e) {
throw new RuntimeException(e);
@@ -339,13 +340,13 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
*/
public static class PineconeBuilder extends AbstractVectorStoreBuilder<PineconeBuilder> {
private String apiKey;
private final String apiKey;
private String projectId;
private final String projectId;
private String environment;
private final String environment;
private String indexName;
private final String indexName;
private String namespace = "";
@@ -357,56 +358,19 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
private PineconeBuilder(EmbeddingModel embeddingModel) {
private PineconeBuilder(EmbeddingModel embeddingModel, String apiKey, String projectId, String environment,
String indexName) {
super(embeddingModel);
}
/**
* Sets the Pinecone API key.
* @param apiKey The API key to use
* @return The builder instance
* @throws IllegalArgumentException if apiKey is null or empty
*/
public PineconeBuilder apiKey(String apiKey) {
Assert.hasText(apiKey, "ApiKey must not be null or empty");
this.apiKey = apiKey;
return this;
}
/**
* Sets the Pinecone project ID.
* @param projectId The project ID to use
* @return The builder instance
* @throws IllegalArgumentException if projectId is null or empty
*/
public PineconeBuilder projectId(String projectId) {
Assert.hasText(projectId, "ProjectId must not be null or empty");
this.projectId = projectId;
return this;
}
/**
* Sets the Pinecone environment.
* @param environment The environment to use (e.g. gcp-starter)
* @return The builder instance
* @throws IllegalArgumentException if environment is null or empty
*/
public PineconeBuilder environment(String environment) {
Assert.hasText(environment, "Environment must not be null or empty");
this.environment = environment;
return this;
}
/**
* Sets the Pinecone index name.
* @param indexName The index name to use
* @return The builder instance
* @throws IllegalArgumentException if indexName is null or empty
*/
public PineconeBuilder indexName(String indexName) {
Assert.hasText(indexName, "IndexName must not be null or empty");
this.apiKey = apiKey;
this.projectId = projectId;
this.environment = environment;
this.indexName = indexName;
return this;
}
/**
@@ -415,7 +379,7 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* @param namespace The namespace to use (leave empty for free tier)
* @return The builder instance
*/
public PineconeBuilder namespace(String namespace) {
public PineconeBuilder namespace(@Nullable String namespace) {
this.namespace = namespace != null ? namespace : "";
return this;
}
@@ -425,7 +389,7 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* @param contentFieldName The content field name to use
* @return The builder instance
*/
public PineconeBuilder contentFieldName(String contentFieldName) {
public PineconeBuilder contentFieldName(@Nullable String contentFieldName) {
this.contentFieldName = contentFieldName != null ? contentFieldName : CONTENT_FIELD_NAME;
return this;
}
@@ -435,7 +399,7 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* @param distanceMetadataFieldName The distance metadata field name to use
* @return The builder instance
*/
public PineconeBuilder distanceMetadataFieldName(String distanceMetadataFieldName) {
public PineconeBuilder distanceMetadataFieldName(@Nullable String distanceMetadataFieldName) {
this.distanceMetadataFieldName = distanceMetadataFieldName != null ? distanceMetadataFieldName
: DocumentMetadata.DISTANCE.value();
return this;
@@ -446,7 +410,7 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* @param serverSideTimeout The timeout duration to use
* @return The builder instance
*/
public PineconeBuilder serverSideTimeout(Duration serverSideTimeout) {
public PineconeBuilder serverSideTimeout(@Nullable Duration serverSideTimeout) {
this.serverSideTimeout = serverSideTimeout != null ? serverSideTimeout : Duration.ofSeconds(20);
return this;
}
@@ -478,8 +442,10 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* Configuration for PineconeVectorStore.
*
* @deprecated Use {@link PineconeVectorStore#builder()} instead. This class will be
* removed in a future release as part of the migration to the builder pattern.
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead. This class will be removed in a future release as part of the
* migration to the builder pattern.
* @since 1.0.0
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
@@ -502,7 +468,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* Constructor using the builder.
* @param builder The configuration builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public PineconeVectorStoreConfig(Builder builder) {
@@ -520,7 +488,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* Start building a new configuration.
* @return The entry point for creating a new configuration
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public static Builder builder() {
@@ -529,7 +499,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* {@return the default config}
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public static PineconeVectorStoreConfig defaultConfig() {
@@ -539,8 +511,10 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* Builder for PineconeVectorStoreConfig.
*
* @deprecated Use {@link PineconeVectorStore#builder()} instead. This class will
* be removed in a future release as part of the migration to the builder pattern.
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead. This class will be removed in a future release as part of the
* migration to the builder pattern.
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public static final class Builder {
@@ -573,7 +547,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Pinecone api key.
* @param apiKey key to use
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withApiKey(String apiKey) {
@@ -585,7 +561,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Pinecone project id.
* @param projectId Project id to use
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withProjectId(String projectId) {
@@ -597,7 +575,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Pinecone environment name.
* @param environment Environment name (e.g. gcp-starter)
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withEnvironment(String environment) {
@@ -609,7 +589,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Pinecone index name.
* @param indexName Pinecone index name to use
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withIndexName(String indexName) {
@@ -622,7 +604,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* For free-tier leave the namespace empty.
* @param namespace Pinecone namespace to use
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withNamespace(String namespace) {
@@ -634,7 +618,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Content field name.
* @param contentFieldName content field name to use
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withContentFieldName(String contentFieldName) {
@@ -646,7 +632,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Distance metadata field name.
* @param distanceMetadataFieldName distance metadata field name to use
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withDistanceMetadataFieldName(String distanceMetadataFieldName) {
@@ -658,7 +646,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
* Pinecone server side timeout.
* @param serverSideTimeout server timeout to use
* @return this builder
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public Builder withServerSideTimeout(Duration serverSideTimeout) {
@@ -668,7 +658,9 @@ public class PineconeVectorStore extends AbstractObservationVectorStore {
/**
* {@return the immutable configuration}
* @deprecated Use {@link PineconeVectorStore#builder()} instead
* @deprecated Use
* {@link PineconeVectorStore#builder(EmbeddingModel, String, String, String, String)}
* ()} instead
*/
@Deprecated(since = "1.0.0-M5", forRemoval = true)
public PineconeVectorStoreConfig build() {

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.pinecone;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -275,11 +275,8 @@ public class PineconeVectorStoreIT {
@Bean
public VectorStore vectorStore(EmbeddingModel embeddingModel) {
String apikey = System.getenv("PINECONE_API_KEY");
return PineconeVectorStore.builder(embeddingModel)
.apiKey(apikey)
.environment(PINECONE_ENVIRONMENT)
.projectId(PINECONE_PROJECT_ID)
.indexName(PINECONE_INDEX_NAME)
return PineconeVectorStore
.builder(embeddingModel, apikey, PINECONE_PROJECT_ID, PINECONE_ENVIRONMENT, PINECONE_INDEX_NAME)
.namespace(PINECONE_NAMESPACE)
.contentFieldName(CUSTOM_CONTENT_FIELD_NAME)
.build();

View File

@@ -187,11 +187,9 @@ public class PineconeVectorStoreObservationIT {
@Bean
public VectorStore vectorStore(EmbeddingModel embeddingModel, ObservationRegistry observationRegistry) {
return PineconeVectorStore.builder(embeddingModel)
.apiKey(System.getenv("PINECONE_API_KEY"))
.environment(PINECONE_ENVIRONMENT)
.projectId(PINECONE_PROJECT_ID)
.indexName(PINECONE_INDEX_NAME)
return PineconeVectorStore
.builder(embeddingModel, System.getenv("PINECONE_API_KEY"), PINECONE_PROJECT_ID, PINECONE_ENVIRONMENT,
PINECONE_INDEX_NAME)
.namespace(PINECONE_NAMESPACE)
.contentFieldName(CUSTOM_CONTENT_FIELD_NAME)
.observationRegistry(observationRegistry)

View File

@@ -320,7 +320,7 @@ public class QdrantVectorStore extends AbstractObservationVectorStore implements
private Map<String, Value> toPayload(Document document) {
try {
var payload = QdrantValueFactory.toValueMap(document.getMetadata());
payload.put(CONTENT_FIELD_NAME, io.qdrant.client.ValueFactory.value(document.getContent()));
payload.put(CONTENT_FIELD_NAME, io.qdrant.client.ValueFactory.value(document.getText()));
return payload;
}
catch (Exception e) {

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.qdrant;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -62,6 +62,7 @@ import org.springframework.ai.vectorstore.observation.AbstractObservationVectorS
import org.springframework.ai.vectorstore.observation.VectorStoreObservationContext;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -291,7 +292,7 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements
for (Document document : documents) {
var fields = new HashMap<String, Object>();
fields.put(this.embeddingFieldName, embeddings.get(documents.indexOf(document)));
fields.put(this.contentFieldName, document.getContent());
fields.put(this.contentFieldName, document.getText());
fields.putAll(document.getMetadata());
pipeline.jsonSetWithEscape(key(document.getId()), JSON_SET_PATH, fields);
}
@@ -505,7 +506,7 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements
private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
public RedisBuilder(JedisPooled jedis, EmbeddingModel embeddingModel) {
private RedisBuilder(JedisPooled jedis, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(jedis, "JedisPooled must not be null");
this.jedis = jedis;
@@ -564,7 +565,7 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements
* @param algorithm the vector algorithm to use
* @return the builder instance
*/
public RedisBuilder vectorAlgorithm(Algorithm algorithm) {
public RedisBuilder vectorAlgorithm(@Nullable Algorithm algorithm) {
if (algorithm != null) {
this.vectorAlgorithm = algorithm;
}
@@ -585,7 +586,7 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements
* @param fields the list of metadata fields to include
* @return the builder instance
*/
public RedisBuilder metadataFields(List<MetadataField> fields) {
public RedisBuilder metadataFields(@Nullable List<MetadataField> fields) {
if (fields != null && !fields.isEmpty()) {
this.metadataFields = new ArrayList<>(fields);
}

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.redis;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -52,6 +52,7 @@ import org.springframework.ai.vectorstore.observation.AbstractObservationVectorS
import org.springframework.ai.vectorstore.observation.VectorStoreObservationContext;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -169,7 +170,7 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme
private final int embeddingDimension;
/**
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(Client, EmbeddingModel)} ()} instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public TypesenseVectorStore(Client client, EmbeddingModel embeddingModel) {
@@ -177,7 +178,7 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(Client, EmbeddingModel)} ()} instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public TypesenseVectorStore(Client client, EmbeddingModel embeddingModel, TypesenseVectorStoreConfig config,
@@ -187,7 +188,7 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated Use {@link #builder()} instead
* @deprecated Use {@link #builder(Client, EmbeddingModel)} ()} instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public TypesenseVectorStore(Client client, EmbeddingModel embeddingModel, TypesenseVectorStoreConfig config,
@@ -244,7 +245,7 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme
List<HashMap<String, Object>> documentList = documents.stream().map(document -> {
HashMap<String, Object> typesenseDoc = new HashMap<>();
typesenseDoc.put(DOC_ID_FIELD_NAME, document.getId());
typesenseDoc.put(CONTENT_FIELD_NAME, document.getContent());
typesenseDoc.put(CONTENT_FIELD_NAME, document.getText());
typesenseDoc.put(METADATA_FIELD_NAME, document.getMetadata());
typesenseDoc.put(EMBEDDING_FIELD_NAME, embeddings.get(documents.indexOf(document)));
@@ -424,6 +425,7 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme
}
}
@Nullable
Map<String, Object> getCollectionInfo() {
try {
CollectionResponse retrievedCollection = this.client.collections(this.collectionName).retrieve();
@@ -460,9 +462,10 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme
private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
/**
* Configures the Typesense client.
* @param client the client for Typesense operations
* @return this builder instance
* Constructs a new TypesenseBuilder instance.
* @param client The Typesense client instance used for database operations. Must
* not be null.
* @param embeddingModel The embedding model used for vector transformations.
* @throws IllegalArgumentException if client is null
*/
public TypesenseBuilder(Client client, EmbeddingModel embeddingModel) {
@@ -525,7 +528,8 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme
}
/**
* @deprecated Use {@link TypesenseVectorStore#builder()} instead
* @deprecated Use {@link TypesenseVectorStore#builder(Client, EmbeddingModel)} ()}
* instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public static class TypesenseVectorStoreConfig {

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.typesense;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -32,6 +32,7 @@ import io.weaviate.client.base.Result;
import io.weaviate.client.base.WeaviateErrorMessage;
import io.weaviate.client.v1.batch.model.BatchDeleteResponse;
import io.weaviate.client.v1.batch.model.ObjectGetResponse;
import io.weaviate.client.v1.batch.model.ObjectsGetResponseAO2Result;
import io.weaviate.client.v1.data.model.WeaviateObject;
import io.weaviate.client.v1.filters.Operator;
import io.weaviate.client.v1.filters.WhereFilter;
@@ -151,9 +152,10 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
* @param vectorStoreConfig The configuration for the store
* @param embeddingModel The client for embedding operations
* @param weaviateClient The client for Weaviate operations
* @deprecated Use {@link #builder()} instead to create instances of
* WeaviateVectorStore. This constructor will be removed in a future release.
* @see #builder()
* @deprecated Use {@link #builder(WeaviateClient, EmbeddingModel)} ()} instead to
* create instances of WeaviateVectorStore. This constructor will be removed in a
* future release.
* @see #builder(WeaviateClient, EmbeddingModel) ()
* @since 1.0.0
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
@@ -171,9 +173,10 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
* @param observationRegistry The registry for observations
* @param customObservationConvention The custom observation convention
* @param batchingStrategy The strategy for batching operations
* @deprecated Use {@link #builder()} instead to create instances of
* WeaviateVectorStore. This constructor will be removed in a future release.
* @see #builder()
* @deprecated Use {@link #builder(WeaviateClient, EmbeddingModel)} ()} instead to
* create instances of WeaviateVectorStore. This constructor will be removed in a
* future release.
* @see #builder(WeaviateClient, EmbeddingModel) ()
* @since 1.0.0
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
@@ -265,7 +268,7 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
errorMessages.add(response.getError()
.getMessages()
.stream()
.map(wm -> wm.getMessage())
.map(WeaviateErrorMessage::getMessage)
.collect(Collectors.joining(System.lineSeparator())));
throw new RuntimeException("Failed to add documents because: \n" + errorMessages);
}
@@ -276,7 +279,7 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
var error = r.getResult().getErrors();
errorMessages.add(error.getError()
.stream()
.map(e -> e.getMessage())
.map(ObjectsGetResponseAO2Result.ErrorItem::getMessage)
.collect(Collectors.joining(System.lineSeparator())));
}
}
@@ -291,13 +294,13 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
// https://weaviate.io/developers/weaviate/config-refs/datatypes
Map<String, Object> fields = new HashMap<>();
fields.put(CONTENT_FIELD_NAME, document.getContent());
fields.put(CONTENT_FIELD_NAME, document.getText());
try {
String metadataString = this.objectMapper.writeValueAsString(document.getMetadata());
fields.put(METADATA_FIELD_NAME, metadataString);
}
catch (JsonProcessingException e) {
throw new RuntimeException("Failed to serialize the Document metadata: " + document.getContent());
throw new RuntimeException("Failed to serialize the Document metadata: " + document.getText());
}
// Add the filterable metadata fields as top level fields, allowing filler
@@ -334,7 +337,7 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
String errorMessages = result.getError()
.getMessages()
.stream()
.map(wm -> wm.getMessage())
.map(WeaviateErrorMessage::getMessage)
.collect(Collectors.joining(","));
throw new RuntimeException("Failed to delete documents because: \n" + errorMessages);
}
@@ -538,14 +541,15 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
private List<MetadataField> filterMetadataFields = List.of();
private WeaviateClient weaviateClient;
private final WeaviateClient weaviateClient;
private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
/**
* Configures the Weaviate client.
* @param weaviateClient the client for Weaviate operations
* @return this builder instance
* Constructs a new WeaviateBuilder instance.
* @param weaviateClient The Weaviate client instance used for database
* operations. Must not be null.
* @param embeddingModel The embedding model used for vector transformations.
* @throws IllegalArgumentException if weaviateClient is null
*/
private WeaviateBuilder(WeaviateClient weaviateClient, EmbeddingModel embeddingModel) {
@@ -618,9 +622,9 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Configuration class for WeaviateVectorStore.
*
* @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure and
* create instances of WeaviateVectorStore. This class will be removed in a future
* release. Example migration: <pre>{@code
* @deprecated Use {@link WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel)}
* ()} instead to configure and create instances of WeaviateVectorStore. This class
* will be removed in a future release. Example migration: <pre>{@code
* // Old approach:
* WeaviateVectorStoreConfig config = WeaviateVectorStoreConfig.builder()
* .withObjectClass("CustomClass")
@@ -633,7 +637,7 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
* .consistencyLevel(ConsistentLevel.QUORUM)
* .build();
* }</pre>
* @see WeaviateVectorStore#builder()
* @see WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel) ()
* @since 1.0.0
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
@@ -655,7 +659,8 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Constructor using the builder.
* @param builder The configuration builder
* @deprecated Use {@link WeaviateVectorStore#builder()} instead
* @deprecated Use
* {@link WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel)} ()} instead
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public WeaviateVectorStoreConfig(Builder builder) {
@@ -668,8 +673,9 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Start building a new configuration.
* @return The entry point for creating a new configuration
* @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure and
* create instances of WeaviateVectorStore
* @deprecated Use
* {@link WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel)} ()} instead
* to configure and create instances of WeaviateVectorStore
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public static Builder builder() {
@@ -679,8 +685,9 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Returns the default configuration.
* @return the default configuration
* @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure and
* create instances of WeaviateVectorStore with default settings
* @deprecated Use
* {@link WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel)} ()} instead
* to configure and create instances of WeaviateVectorStore with default settings
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public static WeaviateVectorStoreConfig defaultConfig() {
@@ -801,8 +808,9 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Builder for WeaviateVectorStoreConfig.
*
* @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure and
* create instances of WeaviateVectorStore
* @deprecated Use
* {@link WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel)} ()} instead
* to configure and create instances of WeaviateVectorStore
* @since 1.0.0
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
@@ -841,7 +849,7 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
* @return this builder
* @throws IllegalArgumentException if headers is null
* @deprecated Use the new builder API in
* {@link WeaviateVectorStore#builder()}
* {@link WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel)} ()}
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withHeaders(Map<String, String> headers) {
@@ -884,8 +892,9 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Builds and returns the immutable configuration.
* @return the immutable configuration
* @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure
* and create instances of WeaviateVectorStore
* @deprecated Use
* {@link WeaviateVectorStore#builder(WeaviateClient, EmbeddingModel)} ()}
* instead to configure and create instances of WeaviateVectorStore
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public WeaviateVectorStoreConfig build() {

View File

@@ -0,0 +1,25 @@
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.vectorstore.weaviate;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;