URL context

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

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

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

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

Python

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

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

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-2.5-flash",
    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-2.5-flash: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

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

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

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

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

Python

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

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

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-2.5-flash",
    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-2.5-flash: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
  }

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

इन मॉडल के साथ काम करता है

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

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

सीमाएं

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

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

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

  • टेक्स्ट (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 या स्प्रेडशीट
  • वीडियो और ऑडियो फ़ाइलें

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