Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chroma vector store builder refactoring #1827

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ public ChromaVectorStore vectorStore(EmbeddingModel embeddingModel, ChromaApi ch
ChromaVectorStoreProperties storeProperties, ObjectProvider<ObservationRegistry> observationRegistry,
ObjectProvider<VectorStoreObservationConvention> customObservationConvention,
BatchingStrategy chromaBatchingStrategy) {
return new ChromaVectorStore(embeddingModel, chromaApi, storeProperties.getCollectionName(),
storeProperties.isInitializeSchema(), observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP),
customObservationConvention.getIfAvailable(() -> null), chromaBatchingStrategy);
return ChromaVectorStore.builder(embeddingModel, chromaApi)
.collectionName(storeProperties.getCollectionName())
.initializeSchema(storeProperties.isInitializeSchema())
.observationRegistry(observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP))
.customObservationConvention(customObservationConvention.getIfAvailable(() -> null))
.batchingStrategy(chromaBatchingStrategy)
.build();
}

static class PropertiesChromaConnectionDetails implements ChromaConnectionDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,6 @@ public class ChromaVectorStore extends AbstractObservationVectorStore implements

private boolean initialized = false;

public ChromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi, boolean initializeSchema) {
this(embeddingModel, chromaApi, DEFAULT_COLLECTION_NAME, initializeSchema);
}

public ChromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi, String collectionName,
boolean initializeSchema) {
this(embeddingModel, chromaApi, collectionName, initializeSchema, ObservationRegistry.NOOP, null,
new TokenCountBatchingStrategy());
}

public ChromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi, String collectionName,
boolean initializeSchema, ObservationRegistry observationRegistry,
VectorStoreObservationConvention customObservationConvention, BatchingStrategy batchingStrategy) {

super(observationRegistry, customObservationConvention);

this.embeddingModel = embeddingModel;
this.chromaApi = chromaApi;
this.collectionName = collectionName;
this.initializeSchema = initializeSchema;
this.filterExpressionConverter = new ChromaFilterExpressionConverter();
this.batchingStrategy = batchingStrategy;
this.objectMapper = JsonMapper.builder().addModules(JacksonUtils.instantiateAvailableModules()).build();
}

private ChromaVectorStore(Builder builder) {
super(builder.observationRegistry, builder.customObservationConvention);
this.embeddingModel = builder.embeddingModel;
Expand All @@ -128,6 +103,10 @@ private ChromaVectorStore(Builder builder) {
}
}

public static Builder builder(EmbeddingModel embeddingModel, ChromaApi chromaApi) {
return new Builder(embeddingModel, chromaApi);
}

public void setFilterExpressionConverter(FilterExpressionConverter filterExpressionConverter) {
Assert.notNull(filterExpressionConverter, "FilterExpressionConverter should not be null.");
this.filterExpressionConverter = filterExpressionConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public ChromaApi chromaApi(RestClient.Builder builder) {

@Bean
public VectorStore chromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi) {
return new ChromaVectorStore(embeddingModel, chromaApi, "TestCollection", true);
return ChromaVectorStore.builder(embeddingModel, chromaApi)
.collectionName("TestCollection")
.initializeSchema(true)
.build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ public ChromaApi chromaApi(RestClient.Builder builder) {

@Bean
public VectorStore chromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi) {
return new ChromaVectorStore(embeddingModel, chromaApi, "TestCollection", true);
return ChromaVectorStore.builder(embeddingModel, chromaApi)
.collectionName("TestCollection")
.initializeSchema(true)
.build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ public ChromaApi chromaApi(RestClient.Builder builder) {
@Bean
public VectorStore chromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi,
ObservationRegistry observationRegistry) {
return new ChromaVectorStore(embeddingModel, chromaApi, "TestCollection", true, observationRegistry, null,
new TokenCountBatchingStrategy());
return ChromaVectorStore.builder(embeddingModel, chromaApi)
.collectionName("TestCollection")
.initializeSchema(true)
.observationRegistry(observationRegistry)
.batchingStrategy(new TokenCountBatchingStrategy())
.build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public ChromaApi chromaApi(RestClient.Builder builder) {

@Bean
public VectorStore chromaVectorStore(EmbeddingModel embeddingModel, ChromaApi chromaApi) {
return new ChromaVectorStore(embeddingModel, chromaApi, "TestCollection", true);
return ChromaVectorStore.builder(embeddingModel, chromaApi)
.collectionName("TestCollection")
.initializeSchema(true)
.build();
}

@Bean
Expand Down