यूआरएल का कॉन्टेक्स्ट

यूआरएल कॉन्टेक्स्ट टूल की मदद से, मॉडल को यूआरएल के फ़ॉर्म में अतिरिक्त कॉन्टेक्स्ट दिया जा सकता है. अपने अनुरोध में यूआरएल शामिल करने पर, मॉडल उन पेजों से कॉन्टेंट ऐक्सेस करेगा. हालांकि, ऐसा तब ही होगा, जब वह यूआरएल, सीमाओं वाले सेक्शन में शामिल न हो. इससे मॉडल को जवाब देने और उसे बेहतर बनाने में मदद मिलेगी.

यूआरएल कॉन्टेक्स्ट टूल, इन जैसे टास्क के लिए काम का है:

  • डेटा एक्सट्रैक्ट करना: कई यूआरएल से, कीमत, नाम या अहम जानकारी जैसी खास जानकारी पाना.
  • दस्तावेजों की तुलना करना: अलग-अलग रिपोर्ट, लेख या PDF का विश्लेषण करके, उनमें अंतर की पहचान करना और रुझानों को ट्रैक करना.
  • कॉन्टेंट को आपस में जोड़ना और कॉन्टेंट बनाना: सटीक खास जानकारी, ब्लॉग पोस्ट या रिपोर्ट जनरेट करने के लिए, कई सोर्स यूआरएल से मिली जानकारी को आपस में जोड़ना.
  • कोड और दस्तावेज़ों का विश्लेषण करना: कोड के बारे में बताने, सेटअप के निर्देश जनरेट करने या सवालों के जवाब देने के लिए, GitHub रिपॉज़िटरी या तकनीकी दस्तावेज़ की ओर इशारा करना.

यहां दिए गए उदाहरण में, अलग-अलग वेबसाइटों से मिली दो रेसिपी की तुलना करने का तरीका बताया गया है.

Python

from google import genai
from google.genai.types import Tool, GenerateContentConfig

client = genai.Client()
model_id = "gemini-3-flash-preview"

tools = [
  {"url_context": {}},
]

url1 = "https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592"
url2 = "https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/"

response = client.models.generate_content(
    model=model_id,
    contents=f"Compare the ingredients and cooking times from the recipes at {url1} and {url2}",
    config=GenerateContentConfig(
        tools=tools,
    )
)

for each in response.candidates[0].content.parts:
    print(each.text)

# For verification, you can inspect the metadata to see which URLs the model retrieved
print(response.candidates[0].url_context_metadata)

JavaScript

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-3-flash-preview",
    contents: [
        "Compare the ingredients and cooking times from the recipes at https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592 and https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/",
    ],
    config: {
      tools: [{urlContext: {}}],
    },
  });
  console.log(response.text);

  // For verification, you can inspect the metadata to see which URLs the model retrieved
  console.log(response.candidates[0].urlContextMetadata)
}

await main();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "contents": [
          {
              "parts": [
                  {"text": "Compare the ingredients and cooking times from the recipes at https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592 and https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/"}
              ]
          }
      ],
      "tools": [
          {
              "url_context": {}
          }
      ]
  }' > result.json

cat result.json

यह कैसे काम करता है

यूआरएल कॉन्टेक्स्ट टूल, रफ़्तार, लागत, और नए डेटा को ऐक्सेस करने की सुविधा के बीच बैलेंस बनाए रखने के लिए, दो चरणों वाली प्रोसेस का इस्तेमाल करता है. यूआरएल देने पर, टूल सबसे पहले इंटरनल इंडेक्स कैश से कॉन्टेंट फ़ेच करने की कोशिश करता है. यह, बेहतर तरीके से ऑप्टिमाइज़ की गई कैश के तौर पर काम करता है. अगर कोई यूआरएल इंडेक्स में उपलब्ध नहीं है (उदाहरण के लिए, अगर वह नया पेज है), तो टूल, लाइव फ़ेच करने के लिए अपने-आप फ़ॉल बैक हो जाता है. इससे, रीयल टाइम में कॉन्टेंट पाने के लिए, यूआरएल को सीधे ऐक्सेस किया जाता है.

बेहतर वर्कफ़्लो बनाने के लिए, यूआरएल कॉन्टेक्स्ट टूल को अन्य टूल के साथ इस्तेमाल किया जा सकता है.

Gemini 3 मॉडल, बिल्ट-इन टूल (जैसे, यूआरएल कॉन्टेक्स्ट) को कस्टम टूल (फ़ंक्शन कॉलिंग) के साथ इस्तेमाल करने की सुविधा देते हैं. ज़्यादा जानने के लिए, टूल के कॉम्बिनेशन वाला पेज देखें.

अगर यूआरएल कॉन्टेक्स्ट और Google Search की मदद से, ज़्यादा जानकारी पाने की सुविधा दोनों चालू हैं, तो मॉडल, ऑनलाइन काम की जानकारी ढूंढने के लिए, अपनी खोज की सुविधाओं का इस्तेमाल कर सकता है. इसके बाद, यूआरएल कॉन्टेक्स्ट टूल का इस्तेमाल करके, उसे मिलने वाले पेजों के बारे में ज़्यादा जानकारी पा सकता है. यह तरीका उन प्रॉम्प्ट के लिए काम का है जिनमें ब्रॉड सर्चिंग और खास पेजों का डीप विश्लेषण, दोनों की ज़रूरत होती है.

Python

from google import genai
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch, UrlContext

client = genai.Client()
model_id = "gemini-3-flash-preview"

tools = [
      {"url_context": {}},
      {"google_search": {}}
  ]

response = client.models.generate_content(
    model=model_id,
    contents="Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.",
    config=GenerateContentConfig(
        tools=tools,
    )
)

for each in response.candidates[0].content.parts:
    print(each.text)
# get URLs retrieved for context
print(response.candidates[0].url_context_metadata)

JavaScript

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-3-flash-preview",
    contents: [
        "Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.",
    ],
    config: {
      tools: [
        {urlContext: {}},
        {googleSearch: {}}
        ],
    },
  });
  console.log(response.text);
  // To get URLs retrieved for context
  console.log(response.candidates[0].urlContextMetadata)
}

await main();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "contents": [
          {
              "parts": [
                  {"text": "Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute."}
              ]
          }
      ],
      "tools": [
          {
              "url_context": {}
          },
          {
              "google_search": {}
          }
      ]
  }' > result.json

cat result.json

जवाब को समझना

जब मॉडल, यूआरएल कॉन्टेक्स्ट टूल का इस्तेमाल करता है, तो जवाब में url_context_metadata ऑब्जेक्ट शामिल होता है. इस ऑब्जेक्ट में उन यूआरएल की सूची होती है जिनसे मॉडल ने कॉन्टेंट पाया है. साथ ही, इसमें हर बार कॉन्टेंट पाने की कोशिश की स्थिति भी दिखती है. यह जानकारी, पुष्टि करने और डीबग करने के लिए काम की है.

यहां जवाब के उस हिस्से का एक उदाहरण दिया गया है. जवाब के कुछ हिस्सों को छोटा करने के लिए हटाया गया है:

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "... \n"
          }
        ],
        "role": "model"
      },
      ...
      "url_context_metadata": {
        "url_metadata": [
          {
            "retrieved_url": "https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592",
            "url_retrieval_status": "URL_RETRIEVAL_STATUS_SUCCESS"
          },
          {
            "retrieved_url": "https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/",
            "url_retrieval_status": "URL_RETRIEVAL_STATUS_SUCCESS"
          }
        ]
      }
    }
  ]
}

इस ऑब्जेक्ट के बारे में पूरी जानकारी के लिए , UrlContextMetadata एपीआई के बारे में जानकारी देखें.

सुरक्षा जांच

सिस्टम, यूआरएल पर कॉन्टेंट मॉडरेशन की जांच करता है, ताकि यह पक्का किया जा सके कि वे सुरक्षा के मानकों के मुताबिक हैं. अगर आपके दिए गए यूआरएल इस जांच में पास नहीं होते हैं, तो आपको url_retrieval_status की वैल्यू URL_RETRIEVAL_STATUS_UNSAFE मिलेगी.

टोकन की संख्या

आपके प्रॉम्प्ट में बताए गए यूआरएल से फ़ेच किए गए कॉन्टेंट को, इनपुट टोकन के तौर पर गिना जाता है. मॉडल के आउटपुट के 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
  }

हर टोकन की कीमत, इस्तेमाल किए गए मॉडल पर निर्भर करती है. ज़्यादा जानकारी के लिए, कीमत वाला पेज देखें.

काम करने वाले मॉडल

मॉडल यूआरएल का कॉन्टेक्स्ट
Gemini 3.1 Pro का प्रीव्यू ✔️
Gemini 3.1 Flash-Lite ✔️
Gemini 3.1 Flash-Lite का प्रीव्यू ✔️
Gemini 3 Flash का प्रीव्यू ✔️
Gemini 2.5 Pro ✔️
Gemini 2.5 Flash ✔️
Gemini 2.5 Flash-Lite ✔️

सबसे सही तरीके

  • खास यूआरएल देना: शानदार नतीजे पाने के लिए, उस कॉन्टेंट के डायरेक्ट यूआरएल दें जिसका विश्लेषण मॉडल से कराना है. मॉडल, सिर्फ़ आपके दिए गए यूआरएल से कॉन्टेंट फ़ेच करेगा. वह नेस्ट किए गए लिंक से कोई कॉन्टेंट फ़ेच नहीं करेगा.
  • ऐक्सेस की जांच करना: पुष्टि करें कि आपके दिए गए यूआरएल, ऐसे पेजों पर न ले जाएं जिनके लिए लॉगिन करना ज़रूरी हो या जो Paywall के पीछे हों.
  • पूरा यूआरएल इस्तेमाल करना: पूरा यूआरएल दें, जिसमें प्रोटोकॉल भी शामिल हो . जैसे, सिर्फ़ google.com के बजाय https://www.google.com.

सीमाएं

  • फ़ंक्शन कॉलिंग: फ़िलहाल, फ़ंक्शन कॉलिंग के साथ टूल (यूआरएल कॉन्टेक्स्ट, Google Search की मदद से, ज़्यादा जानकारी पाना वगैरह) का इस्तेमाल नहीं किया जा सकता.
  • अनुरोध की सीमा: टूल, हर अनुरोध में ज़्यादा से ज़्यादा 20 यूआरएल प्रोसेस कर सकता है.
  • यूआरएल के कॉन्टेंट का साइज़: किसी एक यूआरएल से फ़ेच किए गए कॉन्टेंट का ज़्यादा से ज़्यादा साइज़ 34 एमबी हो सकता है.
  • सार्वजनिक तौर पर ऐक्सेस की सुविधा: यूआरएल, वेब पर सार्वजनिक तौर पर ऐक्सेस किए जा सकने चाहिए. Localhost पते (जैसे, localhost, 127.0.0.1), निजी नेटवर्क, और टनलिंग सेवाएं (जैसे, ngrok, pinggy) काम नहीं करती हैं.
  • सिर्फ़ Gemini API: यूआरएल कॉन्टेक्स्ट, सिर्फ़ Gemini API में उपलब्ध है. यह Gemini Enterprise एजेंट प्लैटफ़ॉर्म के ज़रिए उपलब्ध नहीं है.

कॉन्टेंट के वे टाइप जिनके लिए यह सुविधा काम करती है और जिनके लिए नहीं

टूल, इन कॉन्टेंट टाइप वाले यूआरएल से कॉन्टेंट एक्सट्रैक्ट कर सकता है:

  • टेक्स्ट (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)

कॉन्टेंट के इन टाइप के लिए, यह सुविधा काम नहीं करती:

आगे क्या करना है