LangChain4j integration for Chroma embedding store enabling storage, retrieval, and similarity search of vector embeddings with metadata filtering support for both API V1 and V2.
—
Builder class for constructing ChromaEmbeddingStore instances with flexible configuration.
package dev.langchain4j.store.embedding.chroma;
public static class Builderpublic Builder apiVersion(ChromaApiVersion apiVersion);Sets the Chroma API version (V1 or V2).
Parameters:
apiVersion - API version enum valueDefault: ChromaApiVersion.V1
Example:
.apiVersion(ChromaApiVersion.V2)See: ChromaApiVersion
public Builder baseUrl(String baseUrl);Sets the base URL of the Chroma service.
Parameters:
baseUrl - URL including protocol and portRequired: Yes
Example:
.baseUrl("http://localhost:8000")
.baseUrl("https://chroma.example.com")public Builder tenantName(String tenantName);Sets the tenant name for V2 API.
Parameters:
tenantName - tenant identifierDefault: "default"
API Version: V2 only (ignored in V1)
Example:
.tenantName("production")
.tenantName("customer-123")public Builder databaseName(String databaseName);Sets the database name for V2 API.
Parameters:
databaseName - database identifierDefault: "default"
API Version: V2 only (ignored in V1)
Example:
.databaseName("main")
.databaseName("analytics")public Builder collectionName(String collectionName);Sets the collection name.
Parameters:
collectionName - collection identifierDefault: "default"
Example:
.collectionName("documents")
.collectionName("user-embeddings")public Builder timeout(java.time.Duration timeout);Sets timeout duration for HTTP requests.
Parameters:
timeout - timeout durationDefault: Duration.ofSeconds(5)
Example:
.timeout(Duration.ofSeconds(10))
.timeout(Duration.ofMinutes(1))public Builder logRequests(boolean logRequests);Enables or disables request logging.
Parameters:
logRequests - true to enable loggingDefault: false
Example:
.logRequests(true)public Builder logResponses(boolean logResponses);Enables or disables response logging.
Parameters:
logResponses - true to enable loggingDefault: false
Example:
.logResponses(true)public ChromaEmbeddingStore build();Builds the ChromaEmbeddingStore instance.
Returns: configured store instance
Throws: IllegalArgumentException if configuration is invalid
Example:
ChromaEmbeddingStore store = builder.build();ChromaEmbeddingStore store = ChromaEmbeddingStore.builder()
.baseUrl("http://localhost:8000")
.build();Uses defaults:
ChromaEmbeddingStore store = ChromaEmbeddingStore.builder()
.apiVersion(ChromaApiVersion.V1)
.baseUrl("http://localhost:8000")
.collectionName("my-documents")
.timeout(Duration.ofSeconds(30))
.logRequests(true)
.logResponses(true)
.build();ChromaEmbeddingStore store = ChromaEmbeddingStore.builder()
.apiVersion(ChromaApiVersion.V2)
.baseUrl("http://localhost:8000")
.build();Uses defaults:
ChromaEmbeddingStore store = ChromaEmbeddingStore.builder()
.apiVersion(ChromaApiVersion.V2)
.baseUrl("http://localhost:8000")
.tenantName("production")
.databaseName("main")
.collectionName("documents")
.timeout(Duration.ofSeconds(30))
.logRequests(true)
.logResponses(true)
.build();ChromaEmbeddingStore store = ChromaEmbeddingStore.builder()
.apiVersion(ChromaApiVersion.V2)
.baseUrl("https://chroma.production.com")
.tenantName("prod-tenant")
.databaseName("primary")
.collectionName("embeddings")
.timeout(Duration.ofSeconds(20))
.logRequests(false)
.logResponses(false)
.build();ChromaEmbeddingStore store = ChromaEmbeddingStore.builder()
.baseUrl("http://localhost:8000")
.collectionName("dev-test")
.timeout(Duration.ofSeconds(60))
.logRequests(true)
.logResponses(true)
.build();Required:
baseUrl - must be setOptional (with defaults):
apiVersion - defaults to V1collectionName - defaults to "default"tenantName - defaults to "default" (V2 only)databaseName - defaults to "default" (V2 only)timeout - defaults to 5 secondslogRequests - defaults to falselogResponses - defaults to falseV1 API:
tenantName and databaseName are ignoredV2 API:
tenantName and databaseName are usedWhen store is instantiated:
V1:
V2:
Choose timeout based on operation size:
// Small operations, local network
.timeout(Duration.ofSeconds(5)) // Default
// Medium operations, remote network
.timeout(Duration.ofSeconds(15))
// Large batch operations
.timeout(Duration.ofSeconds(30))
// Very large operations or slow network
.timeout(Duration.ofSeconds(60))Enable logging when:
Disable logging when:
// Development
.logRequests(true)
.logResponses(true)
// Production
.logRequests(false)
.logResponses(false)Builder validates configuration on build():
try {
ChromaEmbeddingStore store = ChromaEmbeddingStore.builder()
// .baseUrl(...) // Missing - will fail
.build();
} catch (IllegalArgumentException e) {
System.err.println("Invalid configuration: " + e.getMessage());
}Common validation errors:
baseUrlSee: Configuration Guide for more examples and patterns.
Install with Tessl CLI
npx tessl i tessl/maven-dev-langchain4j--langchain4j-chroma