Vertex AI RAG इंजन
प्रबंधित Vertex AI RAG इंजन कॉर्पोरा से ग्राउंडेड संदर्भ प्राप्त करें — स्वयं होस्ट किए गए वेक्टर स्टोर, एम्बेडिंग प्रदाता या इनजेशन पाइपलाइन की आवश्यकता नहीं है।
यह क्या है
Vertex AI RAG इंजन Google Cloud का प्रबंधित RAG बैकएंड है: आप दस्तावेज़ों को एक RAG कॉर्पस में आयात करते हैं और प्लेटफ़ॉर्म चंकिंग, एम्बेडिंग और वेक्टर खोज को संभालता है। adk-rag का vertex-rag फीचर प्रदान करता है:
VertexRagEngineClient— ADC-प्रमाणीकृत, केवल-पठन डेटा-प्लेन क्लाइंट: कॉर्पोरा प्राप्त/सूचीबद्ध करना, आयात की गई फ़ाइलों की सूची बनाना और संदर्भ प्राप्त करनाVertexAiRagRetrievalTool— एकadk_core::Toolके रूप में पुनर्प्राप्ति, adk-python केVertexAiRagRetrievalका Rust समकक्ष
दायरा: केवल पुनर्प्राप्ति। कॉर्पस निर्माण और फ़ाइल आयात प्रावधान संबंधी कार्य हैं — Vertex AI कंसोल या RagCorpora/RagFiles प्रबंधन APIs का उपयोग करें।
इंस्टॉलेशन
[dependencies]
adk-rag = { version = "2.1.0", features = ["vertex-rag"] }
प्रमाणीकरण Application Default Credentials का उपयोग करता है:
gcloud auth application-default login
क्लाइंट
use adk_rag::vertex_rag::{RetrieveContextsRequest, VertexRagConfig, VertexRagEngineClient};
#[tokio::main]
async fn main() -> adk_core::Result<()> {
// Or VertexRagConfig::from_env() reading GOOGLE_CLOUD_PROJECT / GOOGLE_CLOUD_LOCATION
let config = VertexRagConfig::new("my-project", "us-central1");
let client = VertexRagEngineClient::new_with_adc(config)?;
// Verify the corpus exists and has imported files; fails with
// actionable guidance when it is missing, empty, or in ERROR state.
let corpus = client.ensure_corpus_ready("1234567890").await?;
println!("corpus: {:?} ({:?} files)", corpus.display_name, corpus.rag_files_count);
// Enumerate what's in the project and the corpus.
let corpora = client.list_corpora().await?;
let files = client.list_rag_files("1234567890").await?;
println!("{} corpora, {} files", corpora.len(), files.len());
// Retrieve the most relevant passages for a query.
let request = RetrieveContextsRequest::new("what is the refund policy?", ["1234567890"])
.similarity_top_k(5)
.vector_distance_threshold(0.7);
for context in client.retrieve_contexts(&request).await? {
println!(
"[{:.3}] {} — {}",
context.score.unwrap_or_default(),
context.source_display_name.as_deref().unwrap_or("<unknown>"),
context.text.as_deref().unwrap_or(""),
);
}
Ok(())
}
कॉर्पोरा को केवल ID के रूप में (क्लाइंट के प्रोजेक्ट और स्थान के आधार पर हल किए जाने हेतु) या पूर्ण projects/*/locations/*/ragCorpora/* संसाधन नामों के रूप में पास किया जा सकता है।
नोट:
similarity_top_kऔरvector_distance_thresholdadk-python के नाम बनाए रखते हैं, लेकिन वर्तमान वायर पाथ पर भेजे जाते हैं —query.ragRetrievalConfig.topKऔरquery.ragRetrievalConfig.filter.vectorDistanceThreshold। अप्रचलित v1beta1 वर्तनी (query.similarityTopK,vertexRagStore.vectorDistanceThreshold) को v1 से हटा दिया गया है और कभी उत्सर्जित नहीं किया जाता।vector_similarity_thresholdफ़िल्टर की दूसरी, परस्पर अनन्य शाखा है।
पुनर्प्राप्ति टूल
VertexAiRagRetrievalTool एकल आवश्यक query स्ट्रिंग लेता है और
{text, sourceUri, sourceDisplayName, score} ऑब्जेक्ट की JSON ऐरे लौटाता है। यह
स्वयं को केवल-पठन और समवर्ती-सुरक्षित बताता है, इसलिए
ToolExecutionStrategy::Auto इसे अन्य पठन कार्यों के साथ समानांतर रूप से भेज सकता है।
use std::sync::Arc;
use adk_agent::LlmAgentBuilder;
use adk_model::GeminiModel;
use adk_rag::vertex_rag::{VertexAiRagRetrievalTool, VertexRagConfig, VertexRagEngineClient};
fn main() -> anyhow::Result<()> {
let config = VertexRagConfig::new("my-project", "us-central1");
let client = Arc::new(VertexRagEngineClient::new_with_adc(config)?);
let retrieval = VertexAiRagRetrievalTool::new(client, vec!["1234567890".into()])
.similarity_top_k(5)
.vector_distance_threshold(0.7);
let api_key = std::env::var("GOOGLE_API_KEY")?;
let agent = LlmAgentBuilder::new("rag-assistant")
.description("Answers questions grounded in a Vertex AI RAG Engine corpus")
.model(Arc::new(GeminiModel::new(&api_key, "gemini-3.7-flash")?))
.tool(Arc::new(retrieval))
.instruction(
"Answer using the vertex_rag_retrieval tool. Retrieve first, then \
answer strictly from the retrieved passages, citing sourceDisplayName.",
)
.build()?;
let _ = agent;
Ok(())
}
पूर्ण रूप से चलने वाले एजेंट के लिए examples/vertex_rag
देखें:
cargo run --manifest-path examples/vertex_rag/Cargo.toml
API संदर्भ
| संचालन | एंडपॉइंट | लौटाता है |
|---|---|---|
get_corpus(corpus) | GET v1beta1/{corpus} | RagCorpus (404 एक कार्रवाई योग्य नहीं मिला त्रुटि बन जाता है) |
ensure_corpus_ready(corpus) | GET v1beta1/{corpus} | RagCorpus; अनुपस्थित, रिक्त या ERROR स्थिति होने पर त्रुटियाँ |
list_corpora() | GET v1beta1/{parent}/ragCorpora | Vec<RagCorpus>, पृष्ठांकन जारी रहा |
list_rag_files(corpus) | GET v1beta1/{corpus}/ragFiles | Vec<RagFile>, पृष्ठांकन जारी रहा |
retrieve_contexts(&request) | POST v1beta1/{parent}:retrieveContexts | Vec<RagContext> |
Response प्रकारों को लचीले ढंग से डीसीरियलाइज़ किया जाता है — प्रत्येक फ़ील्ड वैकल्पिक है और अज्ञात फ़ील्ड को अनदेखा किया जाता है, इसलिए नए सर्वर फ़ील्ड पार्सिंग को बाधित नहीं कर सकते। त्रुटियों में घटक Memory (retrieval मेमोरी डोमेन है; AdkError का कोई समर्पित RAG घटक नहीं है), प्रदाता vertex_ai और मशीन-पठनीय rag.vertex.* कोड शामिल होते हैं।
पर्यावरण चर
| चर | द्वारा उपयोग किया जाता है | विवरण |
|---|---|---|
GOOGLE_CLOUD_PROJECT | VertexRagConfig::from_env | कॉर्पोरा का स्वामी प्रोजेक्ट |
GOOGLE_CLOUD_LOCATION | VertexRagConfig::from_env | क्षेत्र, जैसे us-central1 |
VERTEX_RAG_CORPUS | उदाहरण / लाइव परीक्षण | कॉर्पस ID या पूरा संसाधन नाम |
इसके बजाय स्वयं-होस्ट किया गया RAG?
अपने द्वारा चलाए जाने वाले पाइपलाइन के लिए — प्लग-इन किए जा सकने वाले चंकर, एम्बेडिंग प्रदाता, और वेक्टर स्टोर (Qdrant, LanceDB, pgvector, SurrealDB) — देखें RAG।