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

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

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

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

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

Python

# This will only work for SDK newer than 2.0.0
from google import genai

client = genai.Client()

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

interaction = client.interactions.create(
    model="gemini-3.6-flash",
    input=f"Compare the ingredients and cooking times from the recipes at {url1} and {url2}",
    tools=[{"type": "url_context"}]
)

# Print the model's text response and its source annotations
for step in interaction.steps:
    if step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print(content_block.text)
                if content_block.annotations:
                    print("\nSources:")
                    for annotation in content_block.annotations:
                        if annotation.type == "url_citation":
                            print(f"  - {annotation.title}: {annotation.url}")

JavaScript

// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

async function main() {
  const interaction = await client.interactions.create({
    model: "gemini-3.6-flash",
    input: "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: [{ type: "url_context" }]
  });

  // Print the model's text response and its source annotations
  for (const step of interaction.steps) {
    if (step.type === 'model_output') {
      for (const contentBlock of step.content) {
        if (contentBlock.type === 'text') {
          console.log(contentBlock.text);
          if (contentBlock.annotations) {
            console.log("\nSources:");
            for (const annotation of contentBlock.annotations) {
              if (annotation.type === 'url_citation') {
                console.log(`  - ${annotation.title}: ${annotation.url}`);
              }
            }
          }
        }
      }
    }
  }
}

await main();

REST

# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "model": "gemini-3.6-flash",
      "input": "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": [{"type": "url_context"}]
  }'

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

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

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

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

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

Python

# This will only work for SDK newer than 2.0.0
from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.6-flash",
    input="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=[
        {"type": "url_context"},
        {"type": "google_search"}
    ]
)

for step in interaction.steps:
    if step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print(content_block.text)

JavaScript

// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

async function main() {
  const interaction = await client.interactions.create({
    model: "gemini-3.6-flash",
    input: "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: [
      { type: "url_context" },
      { type: "google_search" }
    ]
  });

  for (const step of interaction.steps) {
    if (step.type === 'model_output') {
      for (const contentBlock of step.content) {
        if (contentBlock.type === 'text') console.log(contentBlock.text);
      }
    }
  }
}

await main();

REST

# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "model": "gemini-3.6-flash",
      "input": "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": [
          {"type": "url_context"},
          {"type": "google_search"}
      ]
  }'

जवाब को समझना

जब मॉडल, यूआरएल कॉन्टेक्स्ट टूल का इस्तेमाल करता है, तो उसके टेक्स्ट वाले जवाब में, टेक्स्ट कॉन्टेंट ब्लॉक पर इनलाइन url_citation एनोटेशन शामिल होते हैं. हर एनोटेशन, जवाब के टेक्स्ट के किसी सेगमेंट को (start_index और end_index के ज़रिए) उस सोर्स यूआरएल से लिंक करता है जिससे वह जानकारी ली गई है. आपके ऐप्लिकेशन में साइटेशन दिखाने का यह मुख्य तरीका है. इन्हें एक्सट्रैक्ट करने का तरीका जानने के लिए, ऊपर दिया गया मुख्य उदाहरण देखें.

जवाब में, url_context_result चरण भी शामिल होता है. इसमें, हर यूआरएल को फ़ेच करने की कोशिश के बारे में मेटाडेटा (स्थिति, फ़ेच किया गया यूआरएल) शामिल होता है. यह मुख्य रूप से डीबग करने के लिए काम का है.

सुरक्षा जांच

सिस्टम, यूआरएल पर कॉन्टेंट मॉडरेशन की जांच करता है. इससे यह पक्का किया जाता है कि वे सुरक्षा के स्टैंडर्ड के मुताबिक हों. अगर कोई यूआरएल इस जांच में पास नहीं होता है, तो उससे जुड़े url_context_result चरण में status "unsafe" दिखेगा.

टोकन की गिनती

आपके प्रॉम्प्ट में बताए गए यूआरएल से फ़ेच किए गए कॉन्टेंट को, इनपुट टोकन के तौर पर गिना जाता है. इंटरैक्शन के usage ऑब्जेक्ट में, टोकन की गिनती देखी जा सकती है. यहां एक उदाहरण दिया गया है:

'usage': {
  'output_tokens': 45,
  'input_tokens': 27,
  'input_tokens_details': [{'modality': 'TEXT', 'token_count': 27}],
  'thoughts_tokens': 31,
  'tool_use_input_tokens': 10309,
  'tool_use_input_tokens_details': [{'modality': 'TEXT', 'token_count': 10309}],
  'total_tokens': 10412
}

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

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

मॉडल यूआरएल कॉन्टेक्स्ट
Gemini 3.6 Flash ✔️
Gemini 3.5 Flash-Lite ✔️
Gemini 3.5 Flash ✔️
Gemini 3.1 Pro का प्रीव्यू ✔️
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).

सीमाएं

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

काम करने वाले और काम न करने वाले कॉन्टेंट टाइप

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

  • टेक्स्ट (text/html, application/json, text/plain, text/xml, text/css, text/javascript , text/csv, text/rtf)
  • इमेज (image/png, image/jpeg, image/bmp, image/webp)
  • पीडीएफ़ (application/pdf)

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