LangChain4j integration for Google Vertex AI models including chat, language, embedding, image, and scoring capabilities
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
public class VertexAiScoringModel implements ScoringModel {
public Response<List<Double>> scoreAll(List<TextSegment> segments, String query);
public static Builder builder();
}/**
* Score multiple text segments against a query.
*
* @param segments List of text segments to score
* @param query The query string to score segments against
* @return Response containing list of relevance scores (one per segment)
*/
public Response<List<Double>> scoreAll(List<TextSegment> segments, String query);
/**
* Create a new builder for configuring a VertexAiScoringModel.
*
* @return A new Builder instance
*/
public static Builder builder();/**
* Create a VertexAiScoringModel with explicit parameters.
*
* @param projectId Google Cloud Project ID
* @param projectNumber Google Cloud Project number
* @param location GCP region
* @param model Ranking model name
* @param titleMetadataKey Metadata key for document titles
*/
public VertexAiScoringModel(
String projectId,
String projectNumber,
String location,
String model,
String titleMetadataKey
);/**
* Set the ranking model name.
*
* @param model The model name (e.g., "semantic-ranker-512@latest")
* @return This builder
*/
public Builder model(String model);
/**
* Set the Google Cloud Project ID.
*
* @param projectId The GCP project ID
* @return This builder
*/
public Builder projectId(String projectId);
/**
* Set the Google Cloud Project number.
*
* @param projectNumber The GCP project number (12-digit number)
* @return This builder
*/
public Builder projectNumber(String projectNumber);
/**
* Set the GCP region/location.
*
* @param location The region (e.g., "us-central1", "europe-west1")
* @return This builder
*/
public Builder location(String location);
/**
* Set the metadata key for document titles.
*
* @param titleMetadataKey The metadata key name (default: "title")
* @return This builder
*/
public Builder titleMetadataKey(String titleMetadataKey);
/**
* Build the VertexAiScoringModel instance.
*
* @return Configured VertexAiScoringModel instance
*/
public VertexAiScoringModel build();my-project-123123456789012gcloud projects describe PROJECT_ID --format="value(projectNumber)"us-central1, europe-west1semantic-ranker-512@latest"title"public class Response<T> {
public T content();
public TokenUsage tokenUsage();
public FinishReason finishReason();
}If documents have titles in metadata (using titleMetadataKey), the model considers both:
This improves relevance scoring for documents with descriptive titles.
Unlike other models, VertexAiScoringModel does not support custom credentials() parameter. Always uses default application credentials.
If using custom metadata key:
VertexAiScoringModel model = VertexAiScoringModel.builder()
.titleMetadataKey("doc_title") // Custom key
.build();
TextSegment doc = TextSegment.from(
"Content...",
Metadata.from("doc_title", "Title") // Use same key
);Common errors:
Thread-safe, can be reused across threads. Builder is not thread-safe.
Integrates with LangChain4j retrieval and RAG components:
ScoringModel scoringModel = VertexAiScoringModel.builder()
.projectId("your-project")
.projectNumber("123456789012")
.location("us-central1")
.model("semantic-ranker-512@latest")
.build();
// Use with retrieved documents
List<TextSegment> retrieved = retriever.findRelevant(query);
Response<List<Double>> scores = scoringModel.scoreAll(retrieved, query);Install with Tessl CLI
npx tessl i tessl/maven-dev-langchain4j--langchain4j-vertex-ai@1.11.0