URL কন্টেক্সট

URL কন্টেক্সট টুল আপনাকে URL-এর মাধ্যমে মডেলকে অতিরিক্ত কন্টেক্সট প্রদান করতে দেয়। আপনার অনুরোধে URL যোগ করার মাধ্যমে, মডেলটি সেইসব পৃষ্ঠা থেকে কন্টেন্ট অ্যাক্সেস করবে (যতক্ষণ না এটি এমন কোনও URL হয় যা সীমাবদ্ধতা বিভাগে তালিকাভুক্ত করা হয়েছে) যাতে মডেলটি উত্তর দিতে এবং তার উত্তরকে আরও উন্নত করতে পারে।

URL কন্টেক্সট টুল নিম্নলিখিত টাস্কের জন্য সহায়ক:

  • ডেটা এক্সট্র্যাক্ট করা: একাধিক URL থেকে দাম, নাম বা মূল ফলাফলের মতো নির্দিষ্ট তথ্য সংগ্রহ করা।
  • ডকুমেন্ট তুলনা করা: পার্থক্য শনাক্ত করতে এবং ট্রেন্ড ট্র্যাক করতে একাধিক রিপোর্ট, নিবন্ধ বা PDF বিশ্লেষণ করুন।
  • কন্টেন্ট সিন্থেসাইজ ও তৈরি করা: সঠিক সারসংক্ষেপ, ব্লগ পোস্ট বা রিপোর্ট তৈরি করতে একাধিক সোর্স URL থেকে তথ্য একত্রিত করুন।
  • কোড ও ডকুমেন্ট বিশ্লেষণ করা: কোড ব্যাখ্যা করতে, সেট-আপ সংক্রান্ত নির্দেশাবলী তৈরি করতে বা প্রশ্নের উত্তর দিতে, 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"}]
  }'

এটি কীভাবে কাজ করে

URL কন্টেক্সট টুল, স্পিড, খরচ ও ফ্রেশ ডেটা অ্যাক্সেস করার মধ্যে ব্যালেন্স বজায় রাখতে, দুটি ধাপের রিট্রিভাল প্রসেস ব্যবহার করে। আপনি কোনও URL দিলে, টুলটি প্রথমে ইন্টার্নাল ইন্ডেক্স ক্যাশে থেকে কন্টেন্ট ফেচ করার চেষ্টা করে। এটি খুবই অপ্টিমাইজ করা ক্যাশে হিসেবে কাজ করে। কোনও URL ইন্ডেক্সে উপলভ্য না থাকলে (যেমন, এটি খুব নতুন পৃষ্ঠা হলে), টুলটি অটোমেটিক লাইভ ফেচ করার বিকল্পে চলে যায়। এটি রিয়েল-টাইমে কন্টেন্ট পাওয়ার জন্য সরাসরি URL অ্যাক্সেস করে।

আরও শক্তিশালী ওয়ার্কফ্লো তৈরি করতে, আপনি URL প্রসঙ্গ টুলকে অন্যান্য টুলের সাথে একত্রিত করতে পারেন।

Gemini 3 মডেল কাস্টম টুলের (ফাংশন কলিং) সাথে বিল্ট-ইন টুল (যেমন URL কন্টেক্সট) একত্রিত করার সুবিধা দেয়। টুলের কম্বিনেশন পৃষ্ঠা থেকে আরও জানুন।

URL প্রসঙ্গ ও Google Search-এর মাধ্যমে গ্রাউন্ডিং, দু'টিই চালু করা থাকলে, মডেলটি অনলাইনে প্রাসঙ্গিক তথ্য খুঁজে পেতে সার্চ করার ক্ষমতা ব্যবহার করতে পারে এবং তারপরে, এটি যে পৃষ্ঠাগুলি খুঁজে পায় সেগুলির আরও গভীরভাবে বোঝার জন্য URL প্রসঙ্গ টুল ব্যবহার করতে পারে। এই পদ্ধতিটি সেইসব প্রম্পটের জন্য খুব উপযোগী যেগুলির জন্য নির্দিষ্ট পৃষ্ঠা সম্পর্কে বিস্তারিত সার্চ ও গভীর বিশ্লেষণ, দুটিই প্রয়োজন।

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 কনটেক্সট টুল ব্যবহার করলে, এর টেক্সট উত্তরে ইনলাইন url_citation অ্যানোটেশন সহ টেক্সট কন্টেন্ট ব্লক থাকে। প্রতিটি অ্যানোটেশন, উত্তরের টেক্সটের একটি সেগমেন্টকে (start_index এবং end_index-এর মাধ্যমে) সেই সোর্স URL-এর সাথে লিঙ্ক করে যেখান থেকে এটি নেওয়া হয়েছে। আপনার অ্যাপ্লিকেশনে উদ্ধৃতি দেখানোর এটিই প্রধান উপায় — কীভাবে সেগুলি এক্সট্র্যাক্ট করতে হয় তা জানতে উপরের মূল উদাহরণটি দেখুন।

এছাড়াও, উত্তরে প্রতিটি URL রিট্রিভ করার প্রচেষ্টা (স্ট্যাটাস, রিট্রিভ করা URL) সম্পর্কিত মেটাডেটা সহ url_context_resultটি ধাপ অন্তর্ভুক্ত থাকে। এটি মূলত ডিবাগিংয়ের জন্য সহায়ক।

নিরাপত্তা সংক্রান্ত পরীক্ষা

URL নিরাপত্তা সংক্রান্ত স্ট্যান্ডার্ড মেনে চলছে কিনা তা নিশ্চিত করতে সিস্টেম কন্টেন্ট মডারেশন চেক করে। কোনও URL এই চেক করতে না পারলে, সংশ্লিষ্ট url_context_result ধাপে status-এর "unsafe" চিহ্ন দেখানো হবে।

টোকেনের সংখ্যা

আপনার প্রম্পটে উল্লেখ করা URL থেকে পাওয়া কন্টেন্টকে ইনপুট টোকেনের অংশ হিসেবে গণনা করা হয়। আপনি ইন্টার‍্যাকশনের 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
}

টোকেন প্রতি দাম ব্যবহৃত মডেলের উপর নির্ভর করে, বিবরণের জন্য দাম পৃষ্ঠা দেখুন।

মানানসই মডেল

মডেল URL কন্টেক্সট
Gemini 3.8 Flash ✔️
Gemini 3.6 Flash ✔️
Gemini 3.5 Flash-Lite ✔️
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 ✔️

পেশাদার পদ্ধতি

  • নির্দিষ্ট URL দিন: সবচেয়ে ভাল ফলাফল পেতে, আপনি যে কন্টেন্ট মডেলকে বিশ্লেষণ করতে দিতে চান, সেটির সরাসরি URL দিন। মডেলটি শুধুমাত্র আপনার দেওয়া URL থেকে কন্টেন্ট রিট্রিভ করবে, নেস্ট করা লিঙ্ক থেকে কোনও কন্টেন্ট নয়।
  • অ্যাক্সেসিবিলিটি চেক করুন: আপনার দেওয়া URL যেন লগ-ইন করতে হয় বা পেওয়ালের পিছনে থাকে এমন কোনও পৃষ্ঠায় নিয়ে না যায় তা যাচাই করুন।
  • সম্পূর্ণ URL ব্যবহার করুন: প্রোটোকল সহ সম্পূর্ণ URL দিন (যেমন, শুধু google.com-এর পরিবর্তে https://www.google.com)।

সীমাবদ্ধতা

  • অনুরোধের সীমা: টুলটি প্রতিটি অনুরোধে সর্বাধিক ২০টি URL প্রসেস করতে পারে।
  • URL কন্টেন্টের সাইজ: কোনও একটি URL থেকে পাওয়া কন্টেন্টের সর্বাধিক সাইজ হল ৩৪ এমবি।
  • সর্বজনীন অ্যাক্সেসযোগ্যতা: URL-কে ওয়েবে সর্বজনীনভাবে অ্যাক্সেসযোগ্য হতে হবে। লোকালহোস্ট অ্যাড্রেস (যেমন, লোকালহোস্ট, 127.0.0.1), প্রাইভেট নেটওয়ার্ক এবং টানেলিং পরিষেবা (যেমন, ngrok, pinggy) কাজ করে না।

কাজ করে ও কাজ করে না এমন কন্টেন্টের ধরন

টুলটি নিম্নলিখিত কন্টেন্টের ধরন সহ URL থেকে কন্টেন্ট এক্সট্র্যাক্ট করতে পারে:

  • টেক্সট (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)

নিম্নলিখিত কন্টেন্টের ধরন কাজ করে না:

  • পেওয়াল কন্টেন্ট
  • YouTube ভিডিও (YouTube URL কীভাবে প্রসেস করতে হয় তা জানতে ভিডিও বোঝা দেখুন )
  • Google Docs বা স্প্রেডশিটের মতো Google Workspace ফাইল
  • ভিডিও ও অডিও ফাইল