Rebuilding Search Infrastructure for AI Agents

    This article explains why retrieval quality, not model capability, is often the bottleneck for AI agents, and how to design a unified retrieval layer. It covers four core requirements—multi-source coverage, structured output, provenance, and low latency—along with a vendor-neutral layered architecture, a sample response schema, and engineering practices for evaluation, context compression, fallback, security, and observability. It also lists common pitfalls to avoid when connecting retrieval to automated agent workflows.

    1. The Problem: Retrieval Is the Last Mile for Agent Capability

    Around 2026, agents with autonomous planning and tool-calling capabilities have taken over a substantial share of work in code generation, research report writing, and security audit assistance. Yet a recurring pattern shows up in real engineering: the model’s reasoning is strong enough, but the quality of its conclusions is dragged down by the input information.

    There are three typical failure modes:

    • When querying a company’s ownership structure, the agent only gets marketing-style summaries from official websites, with no verifiable registration data.
    • When it needs production-grade code snippets, results skew toward beginner tutorials and lack boundary conditions and engineering constraints.
    • When it performs threat assessment on a suspicious network address, it mostly gets educational articles rather than machine-readable intelligence fields.

    The common thread is not “retrieval is too slow.” It is limited retrieval visibility. Traditional web indexes mainly cover publicly crawlable static pages. Large amounts of content living in structured APIs, community discussions, code hosting, financial market data, and academic libraries are not effectively indexed. On top of that, unstructured web text is hard for an agent to consume directly and requires extra extraction and normalization.

    Once the underlying need is abstracted, a retrieval infrastructure built for agents should have four core capabilities.

    2.1 Coverage

    Retrieval must expand beyond “the web” to multiple data source types: structured data APIs, code hosting content, community Q&A, public datasets, and market and metrics data. Coverage determines whether an agent can reach real-world state.

    2.2 Structure

    Results should be typed field sets, not paragraph text. Examples include entity, time, source, confidence, and original locator, so the model can reason and run secondary calculations directly.

    2.3 Provenance

    Every conclusion should carry a source identifier and retrieval time, supporting traceback and verification. High-confidence output without provenance is essentially unusable in compliance and audit scenarios.

    2.4 Latency and Reliability

    Agents often call retrieval many times inside a loop, so a single call’s latency is amplified several times over. The retrieval layer therefore needs caching, concurrent scheduling, and fallback strategies.

    3. Reference Architecture: A Practical Unified Retrieval Layer

    Below is a vendor-neutral layered design that maps directly onto common capabilities available on mainstream clouds.

    1. Agent Runtime
    2. │ (Unified retrieval protocol: query + filters + response schema)
    3. Retrieval Gateway ── Auth / Quota / Audit logs
    4. │
    5. Router ── Classify query intent → select data source combination
    6. │
    7. Adapters: Web Index | Structured API | Code Host | Community | Market Data
    8. │
    9. Normalizer ── Field mapping / unit unification / dedup / entity alignment
    10. │
    11. Validator ── Source trust scoring / freshness check / conflict resolution
    12. │
    13. Cache & Rate Limiter

    Key responsibilities of each layer:

    • Gateway layer: unified authentication and quotas. All calls are written to a logging service for later auditing and cost accounting.
    • Router layer: decides the data source combination based on query intent, avoiding the latency amplification caused by hitting every source on every query.
    • Adapter layer: wraps heterogeneous data sources behind a unified interface, so adding a new source does not change upper-layer logic.
    • Normalizer layer: handles field mapping, unit and time format unification, cross-source entity alignment, and deduplication.
    • Validator layer: scores result trustworthiness and resolves conflicts, outputting conclusions with sources attached.

    4. Interface Design Example: Making Results Directly Consumable by the Model

    The design principles are: a stable schema, self-explanatory fields, and mandatory source information.

    1. {
    2. "query": "Ownership structure of a manufacturing entity",
    3. "results": [
    4. {
    5. "type": "organization_shareholder",
    6. "entity": "Example Manufacturing Co., Ltd.",
    7. "attributes": {
    8. "shareholder": "Example Holding Platform",
    9. "ratio": 0.62,
    10. "currency": null
    11. },
    12. "source": {
    13. "kind": "structured_registry",
    14. "retrieved_at": "2026-05-18T08:12:00Z",
    15. "confidence": 0.93
    16. }
    17. }
    18. ],
    19. "warnings": ["Missing fields: registered_capital"]
    20. }

    Three additional conventions are recommended in engineering: pagination and cursor mechanisms; explicit field-level missing markers rather than silent omission; and a warnings channel to express uncertainty. This lets the model clearly distinguish “no data” from “data is zero” during reasoning.

    5. Engineering Practices

    5.1 Evaluate Retrieval Quality on Two Dimensions

    Looking at accuracy alone hides experience problems. It is recommended to measure both result hit rate / field completeness and end-to-end latency percentiles (P50/P95), and run regressions on a fixed question set to avoid hidden degradation across version iterations.

    5.2 Context Budget and Compression

    Agent context is limited, so the retrieval layer should support field trimming and tiered summary returns: give a lightweight summary first, and fetch the full text only when the model decides it needs detail. This significantly reduces token consumption.

    5.3 Failure Fallback Chain

    1. async def search(query, filters, timeout=1.2):
    2. try:
    3. return await primary_route(query, filters, timeout=timeout)
    4. except TimeoutError:
    5. cached = await cache.get(query)
    6. if cached:
    7. return cached.mark(degraded=True)
    8. return await fallback_route(query, filters, timeout=timeout)

    Degraded results must be explicitly marked, so upper layers do not treat stale data as real-time fact.

    5.4 Security and Compliance

    Filter prompt injection in returned content (an “instruction” inside external text must not be promoted to a system instruction), mask sensitive fields, and keep full audit of the call chain. All three must be completed before connecting retrieval to automated workflows.

    5.5 Observability

    For every retrieval, log the query, the routing decision, per-source latency, and reasons for hits and drops, together with monitoring and alerting. When quality declines, you can quickly determine whether a data source changed or a normalization rule broke.

    6. Common Pitfalls

    • Treating “found a web page” as “got the fact”: web text often lacks key fields and needs structured sources to fill the gaps.
    • Chasing a single large source: multiple sources complement each other to cover the long tail; a single source inevitably has blind spots.
    • Ignoring freshness labels: conclusions without timestamps are unusable in audit scenarios.
    • Reimplementing normalization in the application layer: it should be pushed down into the retrieval layer to keep consistency across business lines.

    7. Conclusion

    The next stage of agent competition is less about model parameters and more about the quality of the channel through which agents perceive the real world. Building retrieval as infrastructure with multi-source coverage, structured output, provenance, and low latency—hosted on common cloud capabilities such as object storage, message queues, container platforms, logging, and monitoring—lets developers sharply reduce the gap between “the model is strong but the answer is wrong.” Baidu AI Cloud’s capabilities in general cloud infrastructure and data governance can serve as one of the underlying options for deploying such a retrieval layer.