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

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

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

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

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

Python

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-flash-preview",
    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

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

const client = new GoogleGenAI({});

async function main() {
  const interaction = await client.interactions.create({
    model: "gemini-3-flash-preview",
    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

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-flash-preview",
      "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

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    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

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

const client = new GoogleGenAI({});

async function main() {
  const interaction = await client.interactions.create({
    model: "gemini-3-flash-preview",
    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

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-flash-preview",
      "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.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 ✔️

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

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

सीमाएं

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

इस्तेमाल किए जा सकने वाले और इस्तेमाल न किए जा सकने वाले कॉन्टेंट टाइप

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

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

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

  • Paywall की गई सामग्री
  • YouTube वीडियो (YouTube यूआरएल प्रोसेस करने का तरीका जानने के लिए, वीडियो को समझना लेख पढ़ें)
  • Google Workspace की फ़ाइलें, जैसे कि Google Docs या स्प्रेडशीट
  • वीडियो और ऑडियो फ़ाइलें