Integrating Search and Document Understanding into Conversational Applications

    This article explains how to move retrieval, page reading, document and image parsing, speech transcription, and text-to-speech into server-side tools for conversational applications. It covers capability boundaries, protocol normalization, passing intermediate tool blocks back across turns, when sampling parameters stop applying, per-page billing and mode selection, frontend and gateway responsibilities, reliability and security controls, and a practical implementation order.

    Why Put the Full Toolset on the Server

    Many conversational products start with plain text completion: the user asks a question and the model generates an answer. Once the business requires verifiable answers, that capability boundary is no longer enough. Users send web links, scanned files, and screenshots of tables, and they ask the system to “search first, then answer.” If the client orchestrates all these steps, the application must decide whether to search, how many rounds to search, when to open a page, and when to change keywords. The state machine quickly becomes fragile.

    A more robust approach is to consolidate retrieval, page reading, document and image parsing, speech transcription, and text-to-speech into server-side tools that can be called by the model. The client submits only the question and necessary context, and the model decides the tool order and stopping conditions on the server according to the task. The benefits are direct: orchestration logic evolves together with model versions, and the client does not need a release for every “think while searching” path; citations, fetched snippets, and parsing results can be audited uniformly; secrets and outbound network policies are centralized on the server, reducing frontend leakage and abuse surface.

    The tradeoffs are equally clear. The application loses fine-grained control over single-step sampling and tool pacing. Multi-turn conversations must send intermediate blocks generated by the server back exactly as they were; otherwise the model will “forget” the page it just read. These constraints should be written into the interface contract before integration, not guessed from logs after launch.

    How to Divide Capabilities

    It is better to split capabilities into composable pieces based on user intent than to build one black-box “smart switch.”

    Web search discovers candidate sources, including web pages and reverse image search. It answers “where to look,” not “what the page says.” URL reading opens addresses provided by the user or returned by search, and extracts body text, titles, and key snippets. Document and image understanding handles files in local or object storage: plain text extraction is suitable for contracts, policies, and other materials with simple layouts; layout-aware parsing is suitable for scans, multi-column layouts, tables, and diagrams. It costs more but preserves reading order and structure. Speech transcription turns spoken language into searchable text, while text-to-speech turns answers into playable audio. These two are usually decoupled from text tools so that audio streams and tool state do not mix in the same message.

    A reference UI can be open sourced or shipped as a static package: the page only collects keys, displays reasoning and citations, and imports conversation history. Keys should still be short-lived credentials issued by the caller’s own gateway; do not put long-term keys in a static page. The value of history import is migration experience, not locking users into one conversational product. The import format should be validated and redacted, and executable content should be rejected.

    Protocols and Request Shapes

    Common conversational protocols generally fall into three categories: message lists, response-oriented streaming interfaces, and classic completion-style multi-turn messages. When integrating, do not bet that one protocol will dominate forever. Instead, normalize at the gateway: convert requests into an internal structure of “user message, assistant message, tool result,” then map them to the upstream service.

    The pseudocode below expresses responsibilities only and does not correspond to any vendor-specific fields:

    1. request:
    2. model: a chat model that supports tool calling
    3. messages: history + current user input
    4. tools: [web_search, read_url, parse_document]
    5. tool_choice: auto
    6. stream: true

    With search and URL reading attached, the model can search first and then open specific pages to verify numbers. For a question such as comparing the heights of two landmarks, a reasonable path is to obtain candidate sources, enter official or authoritative pages to retrieve the data, and search again within the page when fields are missing, rather than giving an integer from memory. The server should set a limit on tool calls in a single turn, for example forcing closure after on the order of ten to twenty calls and explaining that the evidence is insufficient, to prevent loops of fetching.

    In streaming output, reasoning snippets, search queries, page summaries, and final answers should be separated into different event types. The frontend renders by type, and the gateway logs by type, but the type must not be dropped when returning the stream.

    Passing Intermediate Blocks Back Is Required for Correctness

    The reasoning, search, and page-fetch results returned by the server are evidence for the next round of inference, not decoration for display only. The next request must put these blocks back into context exactly as they were. If a self-built gateway filters them out to “save bandwidth” or “redact data,” the request may still succeed, but the model can only see the user’s original words. As a result, it may repeat searches, citations may disappear, and even numbers may contradict each other.

    In practice:

    • Persist the complete event sequence, and trim only in the display layer; display trimming must not be written back to storage.
    • Apply sensitive-word filtering only to user-visible text. Filtering tool evidence requires a whitelist strategy, and after filtering, insert an explicit marker such as “some evidence has been omitted” so the model does not assume the evidence does not exist.
    • Use the session identifier to associate large document parsing results in object storage. Put only summaries and traceable pointers in messages, avoiding stuffing the entire layout tree into every turn.
    • Make replay idempotent: the same tool call ID is executed only once, and retries do not cause duplicate charges or duplicate fetches.

    When Sampling Parameters Stop Applying

    Once tool calling is enabled, titles are generated automatically, or safety policy is elevated to a level managed by the server, the server usually decides the sampling rhythm itself. At that point, parameters such as temperature and nucleus sampling in the request are ignored. This is not a defect being silently swallowed; tool loops need more stable stopping and format constraints. When temperature is too high, the model is more likely to switch queries mid-course or output tool arguments that cannot be parsed.

    Therefore, configure by mode. For pure chat scenarios that need stylistic variation, you can disable tools and keep sampling parameters. For answers that must be verifiable, accept server-default sampling and move quality control into prompts, tool limits, citation formats, and post-validation rather than tuning temperature. During integration, compare the two modes with a fixed question set, and log an explicit warning when parameters are not applied, so business teams do not mistakenly believe they have already controlled diversity through temperature.

    Billing and Mode Selection for Documents and Images

    Files billed per page typically include layout documents and images. There should be at least two modes: plain text extraction is cheaper and has lower latency, suitable for copyable text; layout parsing preserves heading hierarchy, table cells, and image regions, suitable for scans and complex layouts. Do not enable the expensive mode by default. Run a cheap probe first: whether a text layer exists, the page count, and whether the file is scanned; then decide whether to upgrade.

    Page counts should be calculated at upload time and reported to the caller, so long documents do not cause a cost surprise in the middle of a conversation. Large files should be placed in object storage, and the conversational service should receive only short-term read permission. Parsing results should be cached per page; asking the same question about the same file hash should not trigger repeated parsing. Reverse image search and image text recognition are different cost items and should be authorized separately in the interface.

    The same applies to speech: transcription is billed by audio duration, and text-to-speech by characters or audio duration. Do not mix these with document page fees in one unexplained billing category.

    Division of Responsibilities Between Frontend and Gateway

    The reference frontend can be kept thin: open a local page or hosted address, enter a short-term key issued by the enterprise gateway, and start testing. It is suitable for demonstrating interleaved reasoning and citations, and for importing a history archive and continuing the conversation. In production, the browser should not connect directly to the model provider.

    The recommended path is: the browser accesses only the company’s own business gateway; the gateway handles authentication, quotas, redaction, and assembly of returned blocks, then accesses models and tools. The gateway records tool query terms and source links, but by default does not record full document bodies. Bodies remain in controlled storage with a retention period. If automatic title generation triggers server-side sampling, it should be an independent switch rather than being enabled by default with search.

    Reliability and Security

    Tool loops need timeouts, maximum call counts, and domain policies. URL reading should restrict internal addresses and redirects to prevent the server from being used to probe private networks. Search results are only candidate evidence. The final answer should include sources and clearly state when evidence is insufficient, rather than filling gaps with fluent sentences.

    High security levels further tighten available tools and sampling, which is suitable for external customer service. Internal research scenarios can relax search domains but should still audit query terms. The logging service records input and output summaries for each tool and the associated session. Monitoring and alerts should cover timeout rate, average tool count, parsing failure rate, and sudden cost spikes per user.

    Model versions must also be evaluated separately. Tool calling, long-context return, and document parsing are often first available on a speed-optimized model tier, and stronger models may not support all of them at the same time. The integration layer should use capability detection or configuration switches instead of assuming that “all models from the same brand behave the same.” Capabilities mentioned in reviews and announcements should be verified against the model documentation actually available to the current account.

    Implementation Order

    In the first step, connect only search and URL reading. Use a fixed question-and-answer set to verify whether citations are returned and whether filtering intermediate blocks causes forgetting. In the second step, add per-page documents, starting with text and then layout parsing, with hash-based caching. In the third step, add speech and the reference frontend. At every step, keep protocol adaptation inside the gateway, and let the client depend only on stable event types. In this way, search, URL reading, and document understanding become operable product capabilities rather than a one-off demo.