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
Text ranking and scoring using Google Vertex AI Ranking API. Scores and ranks text segments by relevance to queries. Implements LangChain4j ScoringModel.
public class VertexAiScoringModel implements ScoringModel {
public Response<List<Double>> scoreAll(List<TextSegment> segments, String query);
public static Builder builder();
}import dev.langchain4j.model.vertexai.VertexAiScoringModel;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.scoring.ScoringModel;
import dev.langchain4j.model.output.Response;VertexAiScoringModel model = VertexAiScoringModel.builder()
.projectId("your-project-id")
.projectNumber("123456789012")
.location("us-central1")
.model("semantic-ranker-512@latest")
.build();
String query = "What is machine learning?";
List<TextSegment> documents = List.of(
TextSegment.from("Machine learning is a branch of AI..."),
TextSegment.from("Deep learning uses neural networks..."),
TextSegment.from("Supervised learning requires labels...")
);
Response<List<Double>> response = model.scoreAll(documents, query);
List<Double> scores = response.content(); // Relevance scoressemantic-ranker-512@latest - Semantic ranking model (512 dimensions)projectId (String) - Google Cloud Project IDprojectNumber (String) - Google Cloud Project number (12-digit)location (String) - GCP regionmodel (String) - Ranking model nametitleMetadataKey (String) - Metadata key for document titles (default: "title")Note: Configuration differs from other models - requires both projectId and projectNumber.
# Via gcloud CLI
gcloud projects describe PROJECT_ID --format="value(projectNumber)"
# Or check Google Cloud Console project dashboardInstall with Tessl CLI
npx tessl i tessl/maven-dev-langchain4j--langchain4j-vertex-ai