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

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

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

  • डेटा निकालना: एक से ज़्यादा यूआरएल से खास जानकारी निकालें. जैसे, कीमतें, नाम या मुख्य नतीजे.
  • दस्तावेज़ों की तुलना करना: अंतरों का पता लगाने और रुझानों को ट्रैक करने के लिए, एक से ज़्यादा रिपोर्ट, लेख या PDF का विश्लेषण करें.
  • कॉन्टेंट बनाना और जानकारी इकट्ठा करना: सटीक जवाब, ब्लॉग पोस्ट या रिपोर्ट जनरेट करने के लिए, कई सोर्स यूआरएल से जानकारी इकट्ठा करें.
  • कोड और दस्तावेज़ों का विश्लेषण करना: कोड के बारे में जानकारी पाने, सेटअप करने के निर्देश जनरेट करने या सवालों के जवाब पाने के लिए, 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.8-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.8-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();

ऐप पर जाएं

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

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

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput(
                fmt.Sprintf("Compare the ingredients and cooking times from the recipes at %s and %s", url1, url2),
            ),
            Tools: []interactions.Tool{
                interactions.NewTool(interactions.URLContext{}),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    // Print the model's text response and its source annotations
    for _, step := range res.Interaction.Steps {
        if step.ModelOutputStep != nil {
            for _, contentBlock := range step.ModelOutputStep.Content {
                if contentBlock.TextContent != nil {
                    fmt.Println(contentBlock.TextContent.Text)
                    if len(contentBlock.TextContent.Annotations) > 0 {
                        fmt.Println("\nSources:")
                        for _, annotation := range contentBlock.TextContent.Annotations {
                            if annotation.URLCitation != nil {
                                fmt.Printf("  - %s: %s\n", annotation.URLCitation.GetTitle(), annotation.URLCitation.GetURL())
                            }
                        }
                    }
                }
            }
        }
    }
}

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.8-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.8-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.8-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();

ऐप पर जाएं

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput("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: []interactions.Tool{
                interactions.NewTool(interactions.URLContext{}),
                interactions.NewTool(interactions.GoogleSearch{}),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    for _, step := range res.Interaction.Steps {
        if step.ModelOutputStep != nil {
            for _, contentBlock := range step.ModelOutputStep.Content {
                if contentBlock.TextContent != nil {
                    fmt.Println(contentBlock.TextContent.Text)
                }
            }
        }
    }
}

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.8-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 चरण में "unsafe" का status दिखेगा.

टोकन की गिनती

आपके प्रॉम्प्ट में दिए गए यूआरएल से हासिल किए गए कॉन्टेंट को, इनपुट टोकन के तौर पर गिना जाता है. इंटरैक्शन के 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.8 Flash ✔️
Gemini 3.7 Flash ✔️
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 ✔️

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

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

सीमाएं

  • अनुरोध की सीमा: यह टूल, हर अनुरोध के लिए ज़्यादा से ज़्यादा 20 यूआरएल प्रोसेस कर सकता है.
  • यूआरएल के कॉन्टेंट का साइज़: किसी एक यूआरएल से लिए गए कॉन्टेंट का साइज़ 34 एमबी से ज़्यादा नहीं होना चाहिए.
  • सार्वजनिक तौर पर ऐक्सेस करने की सुविधा: यूआरएल ऐसे होने चाहिए जिन्हें कोई भी वेब पर ऐक्सेस कर सके. लोकलहोस्ट पते (जैसे, 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)
  • PDF (application/pdf)

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

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