ADK using Vertex AI RAG
Using RAG with ADK engine, we need to setup our RAG engine corpus and tell our agent to use that as a point of reference. As you can see here RAG_CORPUS contains details of this endpoint.
Then we use a tool called VertexAiRagRetrieval
from google.adk.tools.retrieval.vertex_ai_rag_retrieval import (
VertexAiRagRetrieval,
)
Then we hook it up to our agent and make these knowledge accessible
# Initialize tools list
tools = []
# Only add RAG retrieval tool if RAG_CORPUS is configured
rag_corpus = os.environ.get("RAG_CORPUS")
if rag_corpus:
ask_vertex_retrieval = VertexAiRagRetrieval(
name="retrieve_rag_documentation",
description=(
"Use this tool to retrieve documentation and reference materials for the question from the RAG corpus,"
),
rag_resources=[
rag.RagResource(
# please fill in your own rag corpus
# here is a sample rag corpus for testing purpose
# e.g. projects/123/locations/us-central1/ragCorpora/456
rag_corpus=rag_corpus
)
],
similarity_top_k=10,
vector_distance_threshold=0.6,
)
tools.append(ask_vertex_retrieval)
with using_session(session_id=uuid.uuid4()):
root_agent = Agent(
model="gemini-2.5-flash",
name="ask_rag_agent",
instruction=return_instructions_root(),
tools=tools,
)
from google.adk.apps import App
app = App(root_agent=root_agent, name="rag")
Comments