rs-adk 0.5.0

Agent runtime for Gemini Live — tools, streaming, agent transfer, middleware
Documentation
//! Vertex AI RAG retrieval tool — retrieve context via Vertex AI RAG API.
//!
//! Mirrors ADK-Python's `vertex_ai_rag_retrieval` tool.

use async_trait::async_trait;

use super::base::{BaseRetrievalTool, RetrievalResult};
use crate::error::ToolError;

/// Configuration for Vertex AI RAG retrieval.
#[derive(Debug, Clone)]
pub struct VertexAiRagConfig {
    /// The RAG corpus resource name.
    /// Format: `projects/{project}/locations/{location}/ragCorpora/{corpus_id}`
    pub corpus: String,
    /// Minimum similarity score threshold.
    pub similarity_threshold: f64,
}

/// Retrieval tool that searches via Vertex AI RAG API.
///
/// Calls the Vertex AI RAG API to retrieve relevant document chunks
/// from a configured corpus.
#[derive(Debug, Clone)]
pub struct VertexAiRagRetrievalTool {
    config: VertexAiRagConfig,
}

impl VertexAiRagRetrievalTool {
    /// Create a new Vertex AI RAG retrieval tool.
    pub fn new(config: VertexAiRagConfig) -> Self {
        Self { config }
    }

    /// Returns the configured corpus resource name.
    pub fn corpus(&self) -> &str {
        &self.config.corpus
    }
}

#[async_trait]
impl BaseRetrievalTool for VertexAiRagRetrievalTool {
    fn name(&self) -> &str {
        "vertex_ai_rag_retrieval"
    }

    async fn retrieve(
        &self,
        query: &str,
        _top_k: usize,
    ) -> Result<Vec<RetrievalResult>, ToolError> {
        // In a real integration, this would call the Vertex AI RAG API:
        // POST https://{endpoint}/v1beta1/{corpus}:retrieveContexts
        //
        // The actual API integration requires the Google Cloud SDK
        // and authentication. This stub returns empty results.
        let _ = query;
        Ok(vec![])
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn tool_metadata() {
        let tool = VertexAiRagRetrievalTool::new(VertexAiRagConfig {
            corpus: "projects/my-proj/locations/us-central1/ragCorpora/my-corpus".into(),
            similarity_threshold: 0.7,
        });
        assert_eq!(tool.name(), "vertex_ai_rag_retrieval");
        assert!(tool.corpus().contains("my-corpus"));
    }

    #[tokio::test]
    async fn retrieve_returns_empty_stub() {
        let tool = VertexAiRagRetrievalTool::new(VertexAiRagConfig {
            corpus: "test-corpus".into(),
            similarity_threshold: 0.5,
        });
        let results = tool.retrieve("test query", 5).await.unwrap();
        assert!(results.is_empty());
    }
}