Vertex AI Gen AI Evaluation Service
vertex-eval सुविधा adk-eval को Vertex AI Gen AI Evaluation
Service से जोड़ती है। मॉडल-आधारित निर्णय स्थानीय LLM के बजाय
सेवा के ऑटोरेटर पर चलते हैं, और टूल ट्रेजेक्टरी का स्कोर सेवा के
कम्प्यूटेशन-आधारित ट्रेजेक्टरी मेट्रिक्स द्वारा निर्धारित किया जाता है। हर
कॉल projects.locations:evaluateInstances (v1beta1) पर एकल POST होती है।
सेटअप
[dependencies]
adk-eval = { version = "2.1.0", features = ["vertex-eval"] }
प्रमाणीकरण Application Default Credentials
(gcloud auth application-default login, या परिनियोजित कंटेनर की
workload identity) का उपयोग करता है। कॉल करने वाले को aiplatform.endpoints.predict
अनुमति (roles/aiplatform.user) की आवश्यकता होती है।
| पर्यावरण चर | उद्देश्य |
|---|---|
GOOGLE_CLOUD_PROJECT | VertexEvalConfig::from_env के लिए GCP प्रोजेक्ट |
GOOGLE_CLOUD_LOCATION | क्षेत्र, उदाहरणार्थ us-central1 |
सेवा-समर्थित निर्णायक
VertexEvalJudge, LlmJudge के मूल्यांकन इंटरफ़ेस को प्रतिबिंबित करता है — समान विधि नाम,
समान परिणाम प्रकार — इसलिए यह स्थानीय निर्णायक के लिए लिखे गए कोड में सीधे प्रयुक्त हो सकता है:
use adk_eval::{VertexEvalClient, VertexEvalConfig, VertexEvalJudge};
use adk_eval::criteria::{Rubric, RubricConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = VertexEvalConfig::from_env()?;
let judge = VertexEvalJudge::new(VertexEvalClient::new_with_adc(config)?);
// Semantic equivalence (pointwiseMetricInput under the hood)
let result = judge
.semantic_match("The capital is Paris", "Paris is the capital of France", None)
.await?;
println!("score={} equivalent={}", result.score, result.equivalent);
// Rubric-based quality, weight-normalized like LlmJudge
let rubrics = RubricConfig {
rubrics: vec![
Rubric::new("Accuracy", "Response is factually correct").with_weight(2.0),
Rubric::new("Clarity", "Response is easy to follow"),
],
};
let quality = judge.evaluate_rubrics("agent output", "task context", &rubrics).await?;
println!("overall={}", quality.overall_score);
// Safety and hallucination checks
let safety = judge.evaluate_safety("agent output").await?;
let hallucination = judge
.detect_hallucinations("agent output", "provided context", Some("ground truth"))
.await?;
println!("safe={} grounded={}", safety.is_safe, hallucination.hallucination_free);
Ok(())
}
LlmJudge से अंतर, जो सेवा द्वारा प्रत्येक निर्णय के लिए एक
{score, explanation} युग्म लौटाने के परिणाम हैं:
- बूलियन निर्णय (
equivalent,is_safe,hallucination_free) स्कोर से निकाले जाते हैं — 0.5 या उससे अधिक को उत्तीर्ण माना जाता है। issues, पार्स की गई सूची के बजाय, सेवा का स्पष्टीकरण एकल प्रविष्टि के रूप में रखता है।
ट्रैजेक्टरी मेट्रिक्स
VertexEvalClient::evaluate_trajectory, adk-eval ToolUse मानों को वायर Trajectory संरचना
(name → toolName, args → JSON-एन्कोडेड
toolInput) पर मैप करता है और स्कोर लौटाता है:
TrajectoryMetric | अर्थ |
|---|---|
ExactMatch | यदि ट्रेजेक्टरी बिल्कुल मेल खाती हैं तो 1, अन्यथा 0 |
InOrderMatch | यदि सभी संदर्भ टूल कॉल क्रम में दिखाई देती हैं तो 1, अन्यथा 0 |
AnyOrderMatch | 1 यदि सभी संदर्भ टूल कॉल किसी भी क्रम में दिखाई देते हैं, अन्यथा 0 |
Precision | पूर्वानुमानित टूल कॉल की औसत परिशुद्धता |
Recall | संदर्भ टूल कॉल का औसत रिकॉल |
use adk_eval::{TrajectoryMetric, VertexEvalClient, VertexEvalConfig};
use adk_eval::schema::ToolUse;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = VertexEvalClient::new_with_adc(VertexEvalConfig::from_env()?)?;
let predicted = vec![ToolUse::new("get_weather").with_args(json!({ "city": "Paris" }))];
let reference = predicted.clone();
let score = client
.evaluate_trajectory(TrajectoryMetric::ExactMatch, &predicted, &reference)
.await?;
assert_eq!(score, 1.0);
Ok(())
}
जज मॉडल कॉन्फ़िगरेशन
AutoraterConfig मॉडल-आधारित मेट्रिक्स के लिए जज मॉडल और सैंपलिंग का चयन करता है; सर्वर गणना-आधारित मेट्रिक्स के लिए इसे अनदेखा करता है:
use adk_eval::{AutoraterConfig, VertexEvalClient, VertexEvalConfig};
fn build() -> adk_core::Result<VertexEvalClient> {
let client = VertexEvalClient::new_with_adc(VertexEvalConfig::from_env()?)?
.with_autorater_config(
AutoraterConfig::new()
.with_autorater_model(
"projects/p/locations/us-central1/publishers/google/models/gemini-3.7-flash",
)
.with_sampling_count(1),
);
Ok(client)
}
कस्टम मेट्रिक्स
evaluate_pointwise कोई भी PointwiseMetricSpec स्वीकार करता है — metricPromptTemplate में {placeholder} वेरिएबल होते हैं, जिन्हें इंस्टेंस ऑब्जेक्ट से सर्वर-साइड रेंडर किया जाता है:
use adk_eval::{PointwiseMetricSpec, VertexEvalClient, VertexEvalConfig};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = VertexEvalClient::new_with_adc(VertexEvalConfig::from_env()?)?;
let spec = PointwiseMetricSpec::new(
"Rate the politeness of the response from 0.0 to 1.0.\n\nResponse:\n{response}",
);
let result = client
.evaluate_pointwise(&spec, &json!({ "response": "Thanks for asking!" }))
.await?;
println!("score={:?} explanation={:?}", result.score, result.explanation);
Ok(())
}
evaluate_instances कच्चा एस्केप विकल्प है: यह कोई भी EvaluateInstancesRequest बॉडी POST करता है और कच्चा रिस्पॉन्स लौटाता है, जिससे सेवा द्वारा समर्थित हर अन्य मेट्रिक (BLEU, ROUGE, पेयरवाइज़, टूल-कॉल मेट्रिक्स) तक पहुँचा जा सकता है।
त्रुटि प्रबंधन
त्रुटियाँ संरचित AdkError मान होती हैं, जिनमें कंपोनेंट eval और eval.vertex.* कोड (eval.vertex.rate_limited, eval.vertex.unauthorized, eval.vertex.invalid_response, ...) होते हैं। VertexEvalJudge मेथड क्रेट का EvalError::JudgeError लौटाते हैं, जो LlmJudge से मेल खाता है।
यह भी देखें
- एजेंट मूल्यांकन — मूल्यांकनकर्ता, मानदंड और स्थानीय जज
- Vertex AI Gen AI मूल्यांकन का अवलोकन
projects.locations.evaluateInstancesREST संदर्भ