Skip to content

Commit c315868

Browse files
sobychackoleijendary
authored andcommitted
Update vector store builder examples
Update documentation examples to show correct builder usage across all vector store implementations. Demonstrate passing required parameters directly in builder() method. Signed-off-by: leijendary <[email protected]>
1 parent a57a7ed commit c315868

File tree

17 files changed

+49
-74
lines changed

17 files changed

+49
-74
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/apache-cassandra.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ For more complex scenarios, the builder pattern offers extensive configuration o
163163
----
164164
@Bean
165165
public VectorStore vectorStore(CqlSession session, EmbeddingModel embeddingModel) {
166-
return CassandraVectorStore.builder()
167-
.session(session)
168-
.embeddingModel(embeddingModel)
166+
return CassandraVectorStore.builder(embeddingModel)
169167
.keyspace("my_keyspace")
170168
.table("my_vectors")
171169
.partitionKeys(List.of(new SchemaColumn("id", DataTypes.TEXT)))

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/azure-cosmos-db.adoc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ public class DemoApplication implements CommandLineRunner {
203203

204204
@Bean
205205
public VectorStore vectorStore(ObservationRegistry observationRegistry) {
206-
CosmosDBVectorStoreConfig config = new CosmosDBVectorStoreConfig();
207-
config.setDatabaseName("spring-ai-sample");
208-
config.setContainerName("container");
209-
config.setMetadataFields("country,city");
210-
config.setVectorStoreThroughput(400);
211206

212207
CosmosAsyncClient cosmosClient = new CosmosClientBuilder()
213208
.endpoint(System.getenv("COSMOSDB_AI_ENDPOINT"))
@@ -216,7 +211,13 @@ public class DemoApplication implements CommandLineRunner {
216211
.gatewayMode()
217212
.buildAsyncClient();
218213

219-
return new CosmosDBVectorStore(observationRegistry, null, cosmosClient, config, this.embeddingModel);
214+
return CosmosDBVectorStore.builder(cosmosClient, this.embeddingModel)
215+
.databaseName("test-database")
216+
.containerName("test-container")
217+
.metadataFields(List.of("country", "year", "city"))
218+
.vectorStoreThroughput(1000)
219+
.observationRegistry(observationRegistry)
220+
.build();
220221
}
221222

222223
@Bean

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/azure.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ To create a vector store, you can use the following code by injecting the `Searc
131131
----
132132
@Bean
133133
public VectorStore vectorStore(SearchIndexClient searchIndexClient, EmbeddingModel embeddingModel) {
134-
return new AzureVectorStore(searchIndexClient, embeddingModel,
134+
135+
return AzureVectorStore.builder(searchIndexClient, embeddingModel)
136+
.initializeSchema(true)
135137
// Define the metadata fields to be used
136138
// in the similarity search filters.
137-
List.of(MetadataField.text("country"),
138-
MetadataField.int64("year"),
139-
MetadataField.bool("active")));
139+
.filterMetadataFields(List.of(MetadataField.text("country"), MetadataField.int64("year"),
140+
MetadataField.date("activationDate")))
141+
.build();
140142
}
141143
----
142144

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/chroma.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ Integrate with OpenAI's embeddings by adding the Spring Boot OpenAI starter to y
231231
----
232232
@Bean
233233
public VectorStore chromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi) {
234-
return new ChromaVectorStore(embeddingModel, chromaApi, "TestCollection", false);
234+
return ChromaVectorStore.builder(chromaApi, embeddingModel)
235+
.collectionName("TestCollection")
236+
.initializeSchema(true)
237+
.build();
235238
}
236239
----
237240

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/elasticsearch.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ public VectorStore vectorStore(RestClient restClient, EmbeddingModel embeddingMo
256256
options.setSimilarity(COSINE); // Optional: defaults to COSINE
257257
options.setDimensions(1536); // Optional: defaults to model dimensions or 1536
258258
259-
return ElasticsearchVectorStore.builder()
260-
.restClient(restClient)
261-
.embeddingModel(embeddingModel)
259+
return ElasticsearchVectorStore.builder(restClient, embeddingModel)
262260
.options(options) // Optional: use custom options
263261
.initializeSchema(true) // Optional: defaults to false
264262
.batchingStrategy(new TokenCountBatchingStrategy()) // Optional: defaults to TokenCountBatchingStrategy

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/gemfire.adoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ Here is a sample that creates an instance of the `GemfireVectorStore` instead of
8383
[source,java]
8484
----
8585
@Bean
86-
public VectorStore vectorStore(EmbeddingModel embeddingModel) {
87-
return new GemFireVectorStore(new GemFireVectorStoreConfig()
88-
.setIndexName("my-vector-index")
89-
.setPort(7071), embeddingClient);
86+
public GemFireVectorStore vectorStore(EmbeddingModel embeddingModel) {
87+
return GemFireVectorStore.builder(embeddingModel)
88+
.host("localhost")
89+
.port(7071)
90+
.indexName("my-vector-index")
91+
.initializeSchema(true)
92+
.build();
9093
}
9194
----
9295

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/mariadb.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ Then create the `MariaDBVectorStore` bean using the builder pattern:
149149
----
150150
@Bean
151151
public VectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) {
152-
return MariaDBVectorStore.builder(jdbcTemplate)
153-
.embeddingModel(embeddingModel)
152+
return MariaDBVectorStore.builder(jdbcTemplate, embeddingModel)
154153
.dimensions(1536) // Optional: defaults to 1536
155154
.distanceType(MariaDBDistanceType.COSINE) // Optional: defaults to COSINE
156155
.schemaName("mydb") // Optional: defaults to null

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/milvus.adoc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ To configure MilvusVectorStore in your application, you can use the following se
109109
----
110110
@Bean
111111
public VectorStore vectorStore(MilvusServiceClient milvusClient, EmbeddingModel embeddingModel) {
112-
MilvusVectorStoreConfig config = MilvusVectorStoreConfig.builder()
113-
.withCollectionName("test_vector_store")
114-
.withDatabaseName("default")
115-
.withIndexType(IndexType.IVF_FLAT)
116-
.withMetricType(MetricType.COSINE)
117-
.build();
118-
return new MilvusVectorStore(milvusClient, embeddingModel, config);
112+
return MilvusVectorStore.builder(milvusClient, embeddingModel)
113+
.collectionName("test_vector_store")
114+
.databaseName("default")
115+
.indexType(IndexType.IVF_FLAT)
116+
.metricType(MetricType.COSINE)
117+
.batchingStrategy(new TokenCountBatchingStrategy())
118+
.initializeSchema(true)
119+
.build();
119120
}
120121
121122
@Bean

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/mongodb.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ Then create the `MongoDBAtlasVectorStore` bean using the builder pattern:
146146
----
147147
@Bean
148148
public VectorStore vectorStore(MongoTemplate mongoTemplate, EmbeddingModel embeddingModel) {
149-
return MongoDBAtlasVectorStore.builder()
150-
.mongoTemplate(mongoTemplate)
151-
.embeddingModel(embeddingModel)
149+
return MongoDBAtlasVectorStore.builder(mongoTemplate, embeddingModel)
152150
.collectionName("custom_vector_store") // Optional: defaults to "vector_store"
153151
.vectorIndexName("custom_vector_index") // Optional: defaults to "vector_index"
154152
.pathName("custom_embedding") // Optional: defaults to "embedding"

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/neo4j.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ Then create the `Neo4jVectorStore` bean using the builder pattern:
172172
----
173173
@Bean
174174
public VectorStore vectorStore(Driver driver, EmbeddingModel embeddingModel) {
175-
return Neo4jVectorStore.builder()
176-
.driver(driver)
177-
.embeddingModel(embeddingModel)
175+
return Neo4jVectorStore.builder(driver, embeddingModel)
178176
.databaseName("neo4j") // Optional: defaults to "neo4j"
179177
.distanceType(Neo4jDistanceType.COSINE) // Optional: defaults to COSINE
180178
.dimensions(1536) // Optional: defaults to 1536

0 commit comments

Comments
 (0)