Skip to content

Commit 9e0cda5

Browse files
committed
Update ADK doc according to issue #63 - 1
1 parent 7773037 commit 9e0cda5

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/tools/built-in-tools.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,56 @@ They are packaged in the toolset `BigQueryToolset`.
153153
--8<-- "examples/python/snippets/tools/built-in-tools/bigquery.py"
154154
```
155155

156+
### Spanner
157+
158+
The `SpannerToolset` provides a set of tools for interacting with Spanner databases. The main tool in this toolset is `similarity_search`.
159+
160+
* **`similarity_search`**: Performs a vector similarity search in Spanner. This tool embeds a text query, then uses the embedding vector to find similar items in a Spanner table.
161+
162+
To use the `similarity_search` tool, your Spanner table must contain a column with pre-calculated embeddings. The tool uses a configured embedding service to convert the input text query into a vector for the search.
163+
164+
```py
165+
from google.adk.tools.spanner import SpannerToolset
166+
167+
# Initialize the Spanner toolset
168+
spanner_toolset = SpannerToolset(
169+
project_id="my-project",
170+
instance_id="my-instance",
171+
database_id="my-database",
172+
)
173+
174+
# Example of using similarity_search in an agent
175+
from google.adk.agents import LlmAgent
176+
177+
spanner_agent = LlmAgent(
178+
name="spanner_agent",
179+
model="gemini-2.0-flash",
180+
instruction="You are an expert in Spanner similarity search.",
181+
tools=[spanner_toolset],
182+
)
183+
184+
# The agent can now use the similarity_search tool
185+
# to answer questions that require vector search.
186+
# For example:
187+
# "Find products similar to 'eco-friendly cleaning supplies'."
188+
```
189+
190+
The `similarity_search` tool takes the following parameters:
191+
192+
* `table_name`: The name of the table to search.
193+
* `query`: The text query to search for.
194+
* `embedding_column_to_search`: The name of the column containing the embeddings.
195+
* `columns`: A list of other columns to return in the results.
196+
* `embedding_options`: A dictionary specifying the embedding model to use.
197+
* `spanner_embedding_model_name`: For GoogleSQL dialect databases, the name of the embedding model registered in Spanner.
198+
* `vertex_ai_embedding_model_endpoint`: For PostgreSQL dialect databases, the endpoint of the Vertex AI embedding model.
199+
* `additional_filter` (optional): A SQL `WHERE` clause to further filter the results.
200+
* `search_options` (optional): A dictionary for search customization:
201+
* `top_k`: The number of results to return (default: 4).
202+
* `distance_type`: The distance metric to use (e.g., `COSINE_DISTANCE`, `EUCLIDEAN_DISTANCE`).
203+
* `nearest_neighbors_algorithm`: The search algorithm to use (`EXACT_NEAREST_NEIGHBORS` or `APPROXIMATE_NEAREST_NEIGHBORS`).
204+
* `num_leaves_to_search`: For approximate search, the number of leaves to search in the vector index.
205+
156206
## Use Built-in tools with other tools
157207

158208
The following code sample demonstrates how to use multiple built-in tools or how

0 commit comments

Comments
 (0)