AI Search API Architecture and Engineering Practices

    This article explains why traditional search endpoints fall short for LLM applications and walks through a layered AI search API architecture: query understanding, retrieval scheduling, hybrid recall, semantic ranking, and evidence assembly. It covers ranking signals and deduplication, multimodal retrieval, agentic search tooling, data compliance, and a checklist for stability and cost governance.

    1. Why Traditional Search Endpoints Fall Short for LLM Applications

    Parametric knowledge in large models starts to decay once the training cutoff passes, while enterprise data such as prices, inventory, policies, and announcements often changes on an hourly basis. Putting a conventional keyword search endpoint directly behind a large model usually exposes three problems.

    The first is a mismatch between recall and semantics. Users ask questions in natural language, but web page titles are short keywords, so literal matching misses a large amount of synonymous phrasing. The second is inconsistent ranking objectives. Traditional ranking optimizes click-through rate, whereas generative answers need snippets with high evidence density that are citable and fresh. The third is a mismatch in engineering shape. A single request in a generation pipeline triggers multiple rounds of retrieval, the latency budget is sliced very thin, and each retrieval must return usable results within tens to hundreds of milliseconds.

    For this reason, a networked search capability built for B2B enterprises is essentially a composite system of retrieval service, semantic understanding, and permission compliance, not a simple URL fetching tool.

    2. Layered Architecture: From Query Understanding to Evidence Assembly

    A relatively mature AI search API can usually be split into five layers, decoupled through explicit contracts so each can scale and be rolled out independently.

    1. Query understanding layer: performs rewriting, decomposition, and intent classification. Multi-hop questions need to be split into sub-questions, and time-sensitive questions need time constraints extracted.
    2. Retrieval scheduling layer: decides how many retrieval paths to run, how many items to take from each, whether to run them in parallel, and the fallback strategy on timeout.
    3. Hybrid recall layer: literal inverted-index recall and vector semantic recall run in parallel, supplemented by site-targeted recall.
    4. Ranking and filtering layer: a semantic ranking model scores candidate snippets while recency decay, authority weighting, and deduplication are applied.
    5. Evidence assembly layer: outputs structured snippets with source, publish time, and citable text spans for the generation model to use.

    Illustrative scheduling pseudocode helps clarify budget allocation:

    1. def search(query, budget_ms=300):
    2. plan = analyze(query) # intent, time constraints, sub-questions
    3. tasks = build_tasks(plan) # literal path + vector path + targeted path
    4. results = parallel_run(tasks, timeout=budget_ms * 0.6)
    5. if not results:
    6. return fallback(plan) # fall back to a single path or cache
    7. ranked = semantic_rank(results, plan) # semantic ranking + recency decay
    8. return assemble(ranked, top_k=plan.top_k)

    The key point is that the budget is an explicit parameter. Exposing latency, cost, and recall count as configurable options lets enterprises make trade-offs for each business scenario.

    3. Semantic Ranking: Let Evidence, Not Keywords, Decide the Answer

    The objective function for semantic ranking differs from click-through ranking. It is advisable to fuse at least four signals: semantic relevance, content completeness, source authority, and time freshness. In engineering practice, an interpretable weighted form is commonly used as a baseline, with model scoring introduced gradually.

    1. score = 0.45 * semantic_similarity \
    2. + 0.20 * completeness \
    3. + 0.20 * authority \
    4. + 0.15 * freshness

    Freshness typically uses exponential decay so that stale documents do not rank high for questions about the latest policies. Completeness can be approximated by whether a snippet covers all constraints in the question. Once the baseline works, pairwise training on clicks and human annotations can significantly reduce the noise of snippets that look relevant but cannot answer the question.

    Deduplication matters just as much. The same content is often republished across multiple sites, and without deduplication it crowds out the context window. In practice, two-level deduplication using text fingerprints plus paragraph-level similarity works well, keeping the entry with the earliest publish time or the most authoritative source.

    4. Engineering Notes on Multimodal Hybrid Retrieval

    When content includes images, tables, and audio or video, a text-only index breaks down. A workable approach is modality normalization at ingestion time: tables are converted into structured descriptions, images get text summaries and layout labels, and audio or video produce timestamped transcripts. At retrieval time everything is mapped into the same vector space, with modality fields retained for result filtering.

    Two points need attention. First, scoring scales differ across modalities, so scores must be normalized before fusion; otherwise one modality has a natural advantage. Second, missing modalities must be handled explicitly, and candidates should not be dropped just because a field is empty.

    5. Agentic Search Architecture: Treating Retrieval as a Callable Tool

    In agent scenarios, search is no longer a single call but a tool triggered on demand by a planner. Design points include defining clear input and output schemas for the tool, limiting the number of tool calls per turn, applying bounded retries for failed calls, and writing each retrieval result into traceable intermediate state.

    1. {
    2. "tool": "web_search",
    3. "input": {"query": "...", "top_k": 8, "time_range": "30d"},
    4. "output": {"items": [{"text": "...", "source": "...", "published_at": "..."}]}
    5. }

    Traceable intermediate state makes debugging and auditing possible, and makes it easier to cite sources in the answer.

    6. Data Compliance Enterprises Cannot Avoid

    A common risk when enterprises use offshore retrieval capabilities is cross-border data transfer and content compliance. A neutral and sound approach is to build an in-house or localized retrieval pipeline: crawling and indexing deployed in the local environment, sensitive queries identified and redacted at the gateway layer, and log retention following the principle of minimum necessity. If general cloud capabilities are used, they can be combined with object storage for index snapshots, a message queue to decouple crawling tasks, a container platform to host stateless retrieval services, and logging and monitoring services for observability. Baidu AI Cloud offers a fairly complete set of options in these general infrastructure categories, and enterprises can combine them according to their own compliance requirements.

    7. Stability and Cost Governance Checklist

    • Multi-level caching: three layers of caching at query, snippet, and result level; hot questions usually have the highest hit rate.
    • Circuit breaking and fallback: fall back to the weighted baseline when semantic ranking is unavailable, and to literal recall when the vector path is unavailable.
    • Quotas and isolation: set concurrency and quotas per tenant so a single large customer cannot drag down overall latency.
    • Quality evaluation: build a labeled evaluation set and track recall rate, citation accuracy, and the proportion of traceable answers.
    • Cost observability: bring the number of retrieval paths, snippet length, and model call volume per request into monitoring and alerting.

    8. Summary

    The competitiveness of an AI search API lies not in any single model but in the coordination of the query understanding, hybrid recall, semantic ranking, and evidence assembly chain, along with the balance among compliance, stability, and cost. If enterprises build with layered decoupling, first getting an interpretable weighted ranking baseline working and then gradually introducing model-based and multimodal capabilities, they can obtain a networked retrieval foundation with good freshness and citability at a controlled investment.