Skip to content

Commit b5c613a

Browse files
Add URL context to google search
1 parent d2d3c13 commit b5c613a

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

docs/google-gemini-integration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ VERTEX_AI_RAG_STORE="projects/your-project/locations/global/collections/default_
176176
>
177177
> Future versions may extend these settings to also optimize generated images before upload/display.
178178
179-
## Grounding with Google search
179+
## Web search and access
180180

181-
Grounding with Google search is enabled/disabled with the `google_search_tool` feature, which can be switched on/off in a Filter.
181+
[Grounding with Google search](https://ai.google.dev/gemini-api/docs/google-search) together with the [URL context tool](https://ai.google.dev/gemini-api/docs/url-context) are enabled/disabled together via the `google_search_tool` feature, which can be switched on/off in a Filter.
182182

183-
For instance, the following [Filter (google_search_tool.py)](../filters/google_search_tool.py) will replace Open Web UI default web search function with google search grounding.
183+
For instance, the following [Filter (google_search_tool.py)](../filters/google_search_tool.py) will replace Open Web UI default web search function with Google search grounding + the URL context tool.
184184

185-
When enabled, sources and google queries used by Gemini will be displayed with the response.
185+
When enabled, sources and google queries from the search used by Gemini will be displayed with the response.
186186

187187
## Grounding with Vertex AI Search
188188

pipelines/google/google_gemini.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Intelligent grounding with Google search integration
2929
- Vertex AI Search grounding for RAG
3030
- Native tool calling support with automatic signature management
31+
- URL context grounding for specified web pages
3132
- Unified image processing with consolidated helper methods
3233
- Optimized payload creation for image generation models
3334
- Configurable image processing parameters (size, quality, compression)
@@ -1411,14 +1412,17 @@ def _configure_generation(
14111412
]
14121413
gen_config_params |= {"safety_settings": safety_settings}
14131414

1415+
# Add various tools to Gemini as required
14141416
features = __metadata__.get("features", {})
1417+
params = __metadata__.get("params", {})
1418+
tools = []
1419+
14151420
if features.get("google_search_tool", False):
14161421
self.log.debug("Enabling Google search grounding")
1417-
gen_config_params.setdefault("tools", []).append(
1418-
types.Tool(google_search=types.GoogleSearch())
1419-
)
1422+
tools.append(types.Tool(google_search=types.GoogleSearch()))
1423+
self.log.debug("Enabling URL context grounding")
1424+
tools.append(types.Tool(url_context=types.UrlContext()))
14201425

1421-
params = __metadata__.get("params", {})
14221426
if features.get("vertex_ai_search", False) or (
14231427
self.valves.USE_VERTEX_AI
14241428
and (self.valves.VERTEX_AI_RAG_STORE or os.getenv("VERTEX_AI_RAG_STORE"))
@@ -1429,26 +1433,34 @@ def _configure_generation(
14291433
or os.getenv("VERTEX_AI_RAG_STORE")
14301434
)
14311435
if vertex_rag_store:
1432-
self.log.debug(f"Enabling Vertex AI Search grounding: {vertex_rag_store}")
1433-
gen_config_params.setdefault("tools", []).append(
1436+
self.log.debug(
1437+
f"Enabling Vertex AI Search grounding: {vertex_rag_store}"
1438+
)
1439+
tools.append(
14341440
types.Tool(
14351441
retrieval=types.Retrieval(
1436-
vertex_ai_search=types.VertexAISearch(datastore=vertex_rag_store)
1442+
vertex_ai_search=types.VertexAISearch(
1443+
datastore=vertex_rag_store
1444+
)
14371445
)
14381446
)
14391447
)
14401448
else:
14411449
self.log.warning(
14421450
"Vertex AI Search requested but vertex_rag_store not provided in params, valves, or env"
14431451
)
1452+
14441453
if __tools__ is not None and params.get("function_calling") == "native":
14451454
for name, tool_def in __tools__.items():
14461455
if not name.startswith("_"):
14471456
tool = tool_def["callable"]
14481457
self.log.debug(
14491458
f"Adding tool '{name}' with signature {tool.__signature__}"
14501459
)
1451-
gen_config_params.setdefault("tools", []).append(tool)
1460+
tools.append(tool)
1461+
1462+
if tools:
1463+
gen_config_params["tools"] = tools
14521464

14531465
# Filter out None values for generation config
14541466
filtered_params = {k: v for k, v in gen_config_params.items() if v is not None}
@@ -1470,7 +1482,9 @@ def _format_grounding_chunks_as_sources(
14701482
"uri": getattr(context, "uri", None),
14711483
},
14721484
"document": [getattr(context, "chunk_text", None) or ""],
1473-
"metadata": [{"source": getattr(context, "title", None) or "Document"}],
1485+
"metadata": [
1486+
{"source": getattr(context, "title", None) or "Document"}
1487+
],
14741488
}
14751489
)
14761490
elif hasattr(chunk, "web") and chunk.web:

0 commit comments

Comments
 (0)