Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion docs/grounding/grounding_with_search.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Grounding with Search for agents

<div class="language-support-tag">
<span class="lst-supported">Supported in ADK</span><span class="lst-python">Python v0.1.0</span><span class="lst-java">Java v0.1.0</span>
<span class="lst-supported">Supported in ADK</span><span class="lst-python">Python v0.1.0</span><span class="lst-java">Java v0.1.0</span><span class="lst-kotlin">Kotlin v0.1.0</span>
</div>

[Agent Search](/integrations/agent-search/) is a powerful tool for the Agent Development Kit (ADK) that enables AI agents to access information from your private enterprise documents and data repositories. By connecting your agents to indexed enterprise content, you can provide users with answers grounded in your organization's knowledge base.
Expand Down Expand Up @@ -70,6 +70,32 @@ To enable Grounding with Search, you include the search tool in your agent defin
.build();
```

=== "Kotlin"

```kotlin
import com.google.adk.kt.agents.Instruction
import com.google.adk.kt.agents.LlmAgent
import com.google.adk.kt.models.Gemini
import com.google.adk.kt.tools.VertexAiSearchTool

// Configuration
val DATASTORE_ID =
"projects/YOUR_PROJECT_ID/locations/global/collections/default_collection/dataStores/YOUR_DATASTORE_ID"

val rootAgent =
LlmAgent(
name = "vertex_search_agent",
model = Gemini(name = "gemini-flash-latest"),
instruction =
Instruction(
"Answer questions using Agent Search to find information from internal " +
"documents. Always cite sources when available.",
),
description = "Enterprise document search assistant with Agent Search capabilities",
tools = listOf(VertexAiSearchTool(dataStoreId = DATASTORE_ID)),
)
```

## How Grounding with Search works

Grounding with Search is the process that connects your agent to your organization's indexed documents and data, allowing it to generate accurate responses based on private enterprise content. When a user's prompt requires information from your internal knowledge base, the agent's underlying LLM intelligently decides to invoke the `VertexAiSearchTool` to find relevant facts from your indexed documents.
Expand Down Expand Up @@ -196,6 +222,22 @@ Since grounding metadata is provided, you can choose to implement citation displ
}
```

=== "Kotlin"

```kotlin
events.collect { event ->
if (event.isFinalResponse) {
println(event.content?.parts?.firstOrNull()?.text)

// Optional: Show source count
val chunks = event.groundingMetadata?.groundingChunks
if (!chunks.isNullOrEmpty()) {
println("\nBased on ${chunks.size} documents")
}
}
}
```

**Enhanced Citation Display (Optional):** You can implement interactive citations that show which documents support each statement. The grounding metadata provides all necessary information to map text segments to source documents.

### Implementation Considerations
Expand Down
Loading