Tiered Web Search and Fetching: Compute Scheduling for LLM Online Capabilities

    This article breaks down the cost structure of web-enabled LLM question answering, explains the logic behind tiered free and paid provisioning, and presents five application-side controls: search gating, result caching, fetch limits, tiered quotas, and context compression. It also lists monitoring metrics for production deployment.

    1. Background: Why Web Access Becomes a Cost Focus

    A large model originally answers only from training data. After web access is added, one Q&A request is split into multiple steps: deciding whether external information is needed, generating search terms, calling the search API, fetching candidate pages, cleaning body text, filtering relevant passages, assembling the results into context, and finally entering model inference. Each step consumes resources, so web-enabled Q&A costs noticeably more than plain text generation.

    Web access costs come mainly from three areas: external API call quotas, the compute overhead of network transfer and page parsing, and the increased GPU memory usage and latency during inference as the input context grows. Together, these make web access a cost item that both service providers and application developers need to treat seriously.

    2. Breaking Down the Cost Structure

    The table below lists the main resources and cost characteristics of each stage in the web-enabled pipeline.

    Stage Main resources Cost characteristics
    Retrieval call External API quota Usually metered by call count; cost grows approximately linearly as concurrency rises
    Page fetching Bandwidth, connections, wait time Slow sites hold connections for long periods
    Content cleaning CPU, memory Larger pages take longer to parse
    Context injection Input tokens More injected content makes each inference heavier
    Model inference GPU memory and compute time As context grows, GPU memory usage and latency increase together

    Specific values depend on the deployment environment and service terms; they should be based on actual load-test data and the provider’s published billing documentation. The table shows that web access cost is not fixed. It is determined jointly by query frequency, the number of pages fetched per query, and average page size. If any one of these increases, total cost rises noticeably.

    3. The Logic of Free and Paid Tiers

    Compute is a shared resource, and user experience depends on peak concurrency rather than average load. When many low-frequency but high-consumption requests arrive at the same time, the service provider must make scheduling trade-offs. Common approaches fall into three categories:

    1. Open basic capabilities to all users and set quotas for high-cost capabilities.
    2. Assign priority queues by user tier, so higher-tier requests are processed first.
    3. Introduce payment or usage-based billing for high-cost features.

    Whether a capability is suitable for free access can be evaluated along three dimensions: the marginal cost per request, demand elasticity (how much usage drops when price or quota changes), and the capability’s impact on core experience.

    One view in public discussion is that after free quotas are tightened, paying users can obtain more available resources. This inference has some plausibility, but causality cannot be verified externally. How resources are allocated and where released compute is used require provider disclosure before they can be judged. Technical staff should separate two questions: whether a scheduling policy is engineering-feasible, and whether pricing is commercially reasonable. The former can be judged through analysis and testing; the latter depends on disclosure.

    4. Application-Side Cost Control Options

    Application developers cannot decide the provider’s pricing, but they can reduce unnecessary web calls in their systems. The following five measures can be used in combination.

    4.1 Determine Whether Web Search Is Needed First

    Not every question needs external information. Concept explanations, grammar notes, and general algorithms usually rely only on the model’s own knowledge. Retrieval is worth triggering for time-sensitive questions such as news, prices, and version releases.

    Rule-based judgment is suitable for a first version; in production it can be replaced by a lightweight classifier.

    1. TIME_SENSITIVE_HINTS = ("最新", "今天", "实时", "近期", "当前")
    2. def needs_web_search(question: str) -> bool:
    3. """Roughly determine whether a question depends on real-time information."""
    4. return any(hint in question for hint in TIME_SENSITIVE_HINTS)

    4.2 Cache Search Results

    The same question being asked multiple times within a short period is common. Normalizing queries before caching results can significantly reduce duplicate calls. Normalization includes lowercasing and collapsing whitespace.

    1. import hashlib
    2. import time
    3. CACHE_TTL_SECONDS = 600
    4. _cache: dict[str, tuple[float, list]] = {}
    5. def _cache_key(query: str) -> str:
    6. normalized = " ".join(query.lower().split())
    7. return hashlib.sha256(normalized.encode("utf-8")).hexdigest()
    8. def search_with_cache(query: str, search_fn) -> list:
    9. key = _cache_key(query)
    10. entry = _cache.get(key)
    11. if entry and time.time() - entry[0] < CACHE_TTL_SECONDS:
    12. return entry[1]
    13. results = search_fn(query)
    14. _cache[key] = (time.time(), results)
    15. return results

    Cache TTL should be set according to how fast the information changes. News content should have a shorter TTL, while encyclopedia-like content can have a longer one. Cache capacity also needs an upper bound to avoid unbounded memory growth.

    4.3 Limit the Fetching Scope

    Fetching pages usually consumes more resources than retrieval itself. Set the following limits:

    • Maximum number of pages fetched per query.
    • Timeout for a single page request.
    • Maximum bytes read per page.
    • Number of concurrent connections.
    1. MAX_PAGES_PER_QUERY = 3
    2. FETCH_TIMEOUT_SECONDS = 5
    3. MAX_BYTES_PER_PAGE = 512 * 1024

    Pages that time out or exceed the size limit should be skipped directly, not retried indefinitely. After skipping, the system can continue with successfully fetched results and state in the answer that sources are limited.

    4.4 Rate Limit by User Tier

    Use token buckets or daily counters to set web quotas for users by tier. When quota is exhausted, the system should fall back to model-only answers and explicitly tell the user that web access was not enabled this time, rather than failing silently.

    1. from dataclasses import dataclass
    2. QUOTA_BY_TIER = {"free": 5, "paid": 100}
    3. @dataclass
    4. class SearchQuota:
    5. daily_limit: int
    6. used: int = 0
    7. def try_consume(self) -> bool:
    8. if self.used >= self.daily_limit:
    9. return False
    10. self.used += 1
    11. return True

    Counters need to reset by natural day or rolling window. If a user’s requests within a day concentrate in certain periods, combine quota limits with concurrency limits to prevent spikes from overwhelming the backend.

    4.5 Compress the Injected Context

    Fetched body text usually contains navigation bars, ads, and irrelevant paragraphs. Keep only snippets relevant to the question, take the top segments by relevance, and attach source identifiers. This reduces input tokens and lowers noise interference in model answers.

    5. Monitoring Metrics

    After web access is launched, continuously observe the following metrics:

    • Web trigger rate: the proportion of questions judged to need retrieval among all questions.
    • Cache hit rate: reflects the scale of duplicate queries and whether the cache strategy is effective.
    • Average latency and P95 latency: measure user-perceived delay.
    • Input token increment per request: measures the inference cost caused by context injection.
    • Quota exhaustion ratio: counted separately by user tier.
    • Fetch failure rate