הכלי "הקשר של כתובת URL" מאפשר לכם לספק למודל הקשר נוסף בצורה של כתובות URL. המודל יכול לגשת לתוכן מכתובות ה-URL האלה כדי לשפר את התשובה שלו.
היתרונות של URL Context:
חילוץ נתונים: אפשר לבקש מידע ספציפי כמו מחירים, שמות או ממצאים עיקריים ממאמר או מכמה כתובות URL.
להשוות מידע: לנתח כמה דוחות, מאמרים או קובצי PDF כדי לזהות הבדלים ולעקוב אחרי מגמות.
לסנתז וליצור תוכן: לשלב מידע מכמה כתובות URL של מקורות כדי ליצור סיכומים מדויקים, פוסטים בבלוג, דוחות או שאלות למבחנים.
לנתח קוד ותוכן טכני: אתם יכולים לספק כתובות URL למאגר ב-GitHub או למסמכי תיעוד טכניים כדי להסביר קוד, ליצור הוראות הגדרה או לענות על שאלות.
חשוב לעיין בשיטות המומלצות ובמגבלות כשמשתמשים בכלי URL Context.
מודלים נתמכים
gemini-4-argon-
gemini-3.8-flash(והגרסאות הישנות יותרgemini-3.7-flash,gemini-3.6-flashו-gemini-3.5-flash) -
gemini-3.5-flash-lite(והגרסה הישנה יותרgemini-3.1-flash-lite)
גם המודלים gemini-3.1-pro-preview ו-Gemini 2.5 לשימוש כללי (שיצאו משימוש) תומכים ביכולת הזו.
שפות נתמכות
השפות הנתמכות במודלים של Gemini.
שימוש בכלי URL Context
יש שתי דרכים עיקריות להשתמש בכלי "הקשר של כתובת URL":
רק הכלי "הקשר של כתובת URL"
|
כדי לראות תוכן וקוד שספציפיים לספק, לוחצים על הספק Gemini API בדף הזה. |
כשיוצרים את המכונה של GenerativeModel, צריך לספק את UrlContext ככלי.
אחר כך, מזינים ישירות בהנחיה את כתובות ה-URL הספציפיות שרוצים שהמודל ייגש אליהן וינתח אותן.
בדוגמה הבאה אפשר לראות איך להשוות בין שני מתכונים מאתרים שונים:
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` instance with a model that supports your use case.
let model = ai.generativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools: [.urlContext()]
)
// Specify one or more URLs for the tool to access.
let url1 = "FIRST_RECIPE_URL"
let url2 = "SECOND_RECIPE_URL"
// Provide the URLs in the prompt sent in the request.
let prompt = "Compare the ingredients and cooking times from the recipes at \(url1) and \(url2)"
// Get and handle the model's response.
let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools = listOf(Tool.urlContext())
)
// Specify one or more URLs for the tool to access.
val url1 = "FIRST_RECIPE_URL"
val url2 = "SECOND_RECIPE_URL"
// Provide the URLs in the prompt sent in the request.
val prompt = "Compare the ingredients and cooking times from the recipes at $url1 and $url2"
// Get and handle the model's response.
val response = model.generateContent(prompt)
print(response.text)
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("GEMINI_MODEL_NAME",
null,
null,
// Enable the URL context tool.
List.of(Tool.urlContext(new UrlContext())));
// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Specify one or more URLs for the tool to access.
String url1 = "FIRST_RECIPE_URL";
String url2 = "SECOND_RECIPE_URL";
// Provide the URLs in the prompt sent in the request.
String prompt = "Compare the ingredients and cooking times from the recipes at " + url1 + " and " + url2 + "";
ListenableFuture response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(
ai,
{
model: "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools: [{ urlContext: {} }]
}
);
// Specify one or more URLs for the tool to access.
const url1 = "FIRST_RECIPE_URL"
const url2 = "SECOND_RECIPE_URL"
// Provide the URLs in the prompt sent in the request.
const prompt = `Compare the ingredients and cooking times from the recipes at ${url1} and ${url2}`
// Get and handle the model's response.
const result = await model.generateContent(prompt);
console.log(result.response.text());
Dart
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
// Enable the URL context tool.
tools: [
Tool.urlContext(),
],
);
// Specify one or more URLs for the tool to access.
final url1 = "FIRST_RECIPE_URL";
final url2 = "SECOND_RECIPE_URL";
// Provide the URLs in the prompt sent in the request.
final prompt = "Compare the ingredients and cooking times from the recipes at $url1 and $url2";
// Get and handle the model's response.
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a model that supports your use case.
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools: new[] { new Tool(new UrlContext()) }
);
// Specify one or more URLs for the tool to access.
var url1 = "FIRST_RECIPE_URL";
var url2 = "SECOND_RECIPE_URL";
// Provide the URLs in the prompt sent in the request.
var prompt = $"Compare the ingredients and cooking times from the recipes at {url1} and {url2}";
// Get and handle the model's response.
var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");
איך בוחרים מודל שמתאימים לתרחיש לדוגמה ולאפליקציה.
URL Context בשילוב עם עיגון בעזרת Google Search
|
כדי לראות תוכן וקוד שספציפיים לספק, לוחצים על הספק Gemini API בדף הזה. |
אפשר להפעיל גם את URL Context וגם את Grounding with
אם גם Grounding with
הנה כמה תרחישים לדוגמה:
אתם מספקים כתובת URL בהנחיה כדי לעזור ביצירת חלק מהתשובה. עם זאת, כדי ליצור תשובה מתאימה, המודל עדיין צריך עוד מידע על נושאים אחרים, ולכן הוא משתמש בכלי Grounding with
Google Search .הנחיה לדוגמה:
Give me a three day event schedule based on YOUR_URL. Also what do I need to pack according to the weather?אתם לא מספקים כתובת URL בהנחיה בכלל. כדי ליצור תשובה מתאימה, המודל משתמש בכלי "ביסוס בעזרת
Google Search " כדי למצוא כתובות URL רלוונטיות, ואז משתמש בכלי "הקשר של כתובת URL" כדי לנתח את התוכן שלהן.הנחיה לדוגמה:
Recommend 3 beginner-level books to learn about the latest YOUR_SUBJECT.
בדוגמה הבאה מוסבר איך להפעיל את שני הכלים (URL Context ו-Grounding עם
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` instance with a model that supports your use case.
let model = ai.generativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools: [
.urlContext(),
.googleSearch()
]
)
// Specify one or more URLs for the tool to access.
let url = "YOUR_URL"
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
let prompt = "Give me a three day event schedule based on \(url). Also what do I need to pack according to the weather?"
// Get and handle the model's response.
let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools = listOf(Tool.urlContext(), Tool.googleSearch())
)
// Specify one or more URLs for the tool to access.
val url = "YOUR_URL"
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
val prompt = "Give me a three day event schedule based on $url. Also what do I need to pack according to the weather?"
// Get and handle the model's response.
val response = model.generateContent(prompt)
print(response.text)
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("GEMINI_MODEL_NAME",
null,
null,
// Enable both the URL context tool and Google Search tool.
List.of(Tool.urlContext(new UrlContext()), Tool.googleSearch(new GoogleSearch())));
// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Specify one or more URLs for the tool to access.
String url = "YOUR_URL";
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
String prompt = "Give me a three day event schedule based on " + url + ". Also what do I need to pack according to the weather?";
ListenableFuture response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(
ai,
{
model: "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools: [{ urlContext: {} }, { googleSearch: {} }],
}
);
// Specify one or more URLs for the tool to access.
const url = "YOUR_URL"
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
const prompt = `Give me a three day event schedule based on ${url}. Also what do I need to pack according to the weather?`
// Get and handle the model's response.
const result = await model.generateContent(prompt);
console.log(result.response.text());
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Dart
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp.
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
// Enable both the URL context tool and Google Search tool.
tools: [
Tool.urlContext(),
Tool.googleSearch(),
],
);
// Specify one or more URLs for the tool to access.
final url = "YOUR_URL";
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
final prompt = "Give me a three day event schedule based on $url. Also what do I need to pack according to the weather?";
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a model that supports your use case.
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools: new[] { new Tool(new GoogleSearch()), new Tool(new UrlContext()) }
);
// Specify one or more URLs for the tool to access.
var url = "YOUR_URL";
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
var prompt = $"Give me a three day event schedule based on {url}. Also what do I need to pack according to the weather?";
// Get and handle the model's response.
var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
איך בוחרים מודל שמתאימים לתרחיש לדוגמה ולאפליקציה.
איך פועל הכלי "הקשר של כתובת URL"
כדי לאזן בין מהירות, עלות וגישה לנתונים עדכניים, כלי ההקשר של כתובות ה-URL משתמש בתהליך אחזור דו-שלבי.
שלב 1: כשאתם מזינים כתובת URL ספציפית, הכלי מנסה קודם לאחזר את התוכן ממטמון אינדקס פנימי. הוא פועל כמטמון שעבר אופטימיזציה ברמה גבוהה.
שלב 2: אם כתובת URL לא זמינה באינדקס (לדוגמה, אם מדובר בדף חדש מאוד), הכלי עובר באופן אוטומטי לאחזור בזמן אמת. הכלי ניגש ישירות לכתובת ה-URL כדי לאחזר את התוכן שלה בזמן אמת.
שיטות מומלצות
לספק כתובות URL ספציפיות: כדי לקבל את התוצאות הטובות ביותר, ספקו כתובות URL ישירות לתוכן שאתם רוצים שהמודל ינתח. המודל ישלוף תוכן רק מכתובות ה-URL שסיפקתם, ולא תוכן מקישורים בתצוגת עץ.
בודקים את הנגישות: מוודאים שכתובות ה-URL שציינתם לא מובילות לדפים שדורשים התחברות או נמצאים מאחורי חומת תשלום.
להשתמש בכתובת ה-URL המלאה: צריך לספק את כתובת ה-URL המלאה, כולל הפרוטוקול (לדוגמה,
https://www.example.comבמקום רקexample.com).
הסבר על התשובה
התשובה של המודל תתבסס על התוכן שהוא אחזר מכתובות ה-URL.
אם המודל אחזר תוכן מכתובות URL, התשובה תכלול את url_context_metadata. התגובה עשויה להיראות כך (חלקים מהתגובה הושמטו כדי לקצר):
{
"candidates": [
{
"content": {
"parts": [
{
"text": "... \n"
}
],
"role": "model"
},
...
"url_context_metadata":
{
"url_metadata":
[
{
"retrieved_url": "https://www.example.com",
"url_retrieval_status": "URL_RETRIEVAL_STATUS_SUCCESS"
},
{
"retrieved_url": "https://www.example.org",
"url_retrieval_status": "URL_RETRIEVAL_STATUS_SUCCESS"
},
]
}
}
]
}
בדיקות בטיחות
המערכת מבצעת בדיקת ניהול תוכן בכתובת ה-URL כדי לוודא שהיא עומדת בתקני הבטיחות. אם כתובת ה-URL שסיפקתם לא תעבור את הבדיקה הזו, תקבלו url_retrieval_status של URL_RETRIEVAL_STATUS_UNSAFE.
מגבלות
הנה כמה מגבלות של הכלי "הקשר של כתובת URL":
שילוב עם קריאה להפעלת פונקציות: אי אפשר להשתמש בכלי URL Context בבקשה שכוללת גם קריאה להפעלת פונקציות.
מגבלת כתובות ה-URL לכל בקשה: המספר המקסימלי של כתובות URL לכל בקשה הוא 20.
מגבלת גודל התוכן של כתובת URL: הגודל המקסימלי של תוכן שאפשר לאחזר מכתובת URL אחת הוא 34MB.
עדכניות: הכלי לא מאחזר גרסאות פעילות של דפי אינטרנט, ולכן יכולות להיות בעיות שקשורות לעדכניות או למידע שעשוי להיות לא עדכני.
גישה ציבורית לכתובת ה-URL: כתובות ה-URL שציינתם צריכות להיות נגישות לכולם באינטרנט. אין תמיכה בפריטים הבאים: תוכן שזמין רק לאחר תשלום, תוכן שדורש כניסה של משתמש, רשתות פרטיות, כתובות של מארח מקומי (כמו
localhostאו127.0.0.1) ושירותי מנהור (כמו ngrok או pinggy).
סוגי תוכן נתמכים ולא נתמכים
נתמך: הכלי יכול לחלץ תוכן מכתובות URL עם סוגי התוכן הבאים:
טקסט (
text/html,application/json,text/plain,text/xml,text/css,text/javascript,text/csv,text/rtf)תמונה (
image/png,image/jpeg,image/bmp,image/webp)PDF (
application/pdf)
לא נתמך: הכלי לא תומך בסוגי התוכן הבאים:
סרטונים ב-YouTube (במקום זאת, עיינו במאמר בנושא ניתוח סרטונים)
קובצי וידאו ואודיו (במקום זאת, ראו ניתוח סרטונים או ניתוח אודיו)
קבצים של Google Workspace, כמו מסמכים או גיליונות אלקטרוניים של Google
(אם משתמשים ב-Agent Platform Gemini API (formerly Vertex AI)) כתובות URL מסוג Cloud Storage
אין תמיכה בכתובות URL מהסוגים האלה ב-Gemini Developer API, לא משנה איך ניגשים אליהן.תוכן שלא נגיש לציבור. אין תמיכה ב: תוכן שזמין רק לאחר תשלום, תוכן שדורש כניסה של משתמש, רשתות פרטיות, כתובות מארח מקומי (כמו
localhostאו127.0.0.1) ושירותי מנהור (כמו ngrok או pinggy).
תמחור וספירת טוקנים של כלים
תוכן שאוחזר מכתובות URL נספר כאסימוני קלט.
אפשר לראות את מספר האסימונים בהנחיה ואת השימוש בכלים באובייקט usage_metadata של הפלט מהמודל. הפלט הבא הוא דוגמה:
'usage_metadata': {
'candidates_token_count': 45,
'prompt_token_count': 27,
'prompt_tokens_details': [{'modality': <MediaModality.TEXT: 'TEXT'>,
'token_count': 27}],
'thoughts_token_count': 31,
'tool_use_prompt_token_count': 10309,
'tool_use_prompt_tokens_details': [{'modality': <MediaModality.TEXT: 'TEXT'>,
'token_count': 10309}],
'total_token_count': 10412
}
מגבלת הקצב והתמחור מבוססים על המודל שבו משתמשים. מידע נוסף על התמחור של הכלי URL Context זמין במסמכי התיעוד של ספק Gemini API שבחרתם: Gemini Developer API | Agent Platform Gemini API (formerly Vertex AI).