Integrating External Retrieval Services into an AI Agent Platform: A Practical Guide

    This guide explains why built-in retrieval in visual agent platforms often feels inaccurate and how to decouple retrieval from generation by connecting a dedicated external retrieval service. It covers the overall architecture, server-side preparation such as port planning and resource estimation, chunking and parsing strategies, assistant-side configuration, and how to call the retrieval API from an orchestration platform with proper timeouts, fallbacks, and citations. It also outlines a low-cost troubleshooting order for tuning answer quality.

    1. Why Built-In Retrieval Often Falls Short

    On visual agent orchestration platforms, the most common complaint about knowledge Q&A is that “retrieval is not accurate.” In practice, this single phrase mixes three distinct problems. Separating them is the first step; otherwise, optimization efforts lose focus.

    The first is document parsing. Real enterprise documents are full of tables, scanned pages, multi-level headings, headers and footers, and paragraphs that span page breaks. If parsing breaks the structure into short, semantically meaningless fragments, no amount of downstream retrieval tuning can recover the lost meaning.

    The second is chunking and indexing. Fixed-length chunking cuts across semantic boundaries. Chunks that are too small lack sufficient context, while chunks that are too large introduce noise and dilute the vector representation.

    The third is generation. The retrieved fragments may be correct, but differences in the reasoning model’s summarization ability, temperature settings, and prompt templates lead to differences in the readability and accuracy of the final answer. The “slightly different answers from two entry points” observed in the original text most likely belongs to this category rather than a fault in the retrieval layer.

    The conclusion is clear: retrieval quality and generation quality should be decoupled. Assigning retrieval to a service dedicated to deep document understanding and retrieval, while leaving orchestration, tool invocation, and final generation to the agent platform, is a more controllable engineering division of labor.

    2. Overall Architecture

    The end-to-end flow can be abstracted into four layers:

    1. Document ingestion layer: uploads private documents to the retrieval service and triggers parsing and vectorization.
    2. Index storage layer: managed by the retrieval service itself, typically including a full-text search engine, a relational database, object storage, cache, and task queues.
    3. Retrieval API layer: exposes HTTP endpoints so external systems can query by session or dataset.
    4. Orchestration and generation layer: the agent platform calls the retrieval API through an external knowledge base or tool node, assembles the recalled fragments into a prompt, and lets the LLM produce the answer.

    The key benefit of this architecture is that the retrieval service can be upgraded, scaled, and re-indexed independently without affecting workflow definitions on the agent side.

    3. Server-Side Preparation

    A typical deep retrieval service depends on several components. A common combination is a full-text and vector search engine, a relational database, object storage, a cache service, and the main application itself. Keep the following points in mind when deploying.

    Port planning. Such services usually expose a web access port, an encrypted access port, and an API service port, each with a different responsibility. Only the API port should be integrated with external systems. Confirm this clearly in the documentation and avoid exposing the admin interface to the public internet. You can verify the actual mappings with a container listing command:

    1. docker ps --format "table {{.Names}}\t{{.Ports}}"

    Resource estimation. Vectorization and parsing are compute-intensive. CPU and memory peaks during the first bulk import are noticeably higher than during steady-state queries. Schedule parsing jobs and online queries in separate time windows, or set a separate resource limit for parsing workers on your container orchestration platform.

    Persistence and backup. Original files, parsing artifacts, and index data live on different storage media, so backup strategies must be defined separately. Indexes can be rebuilt from the original files, so the original files and the database are the parts that must be protected first.

    Model configuration. The server side needs two types of models: an embedding model that converts text into vectors, and a reasoning model that generates answers in the retrieval service’s own chat interface. Once the embedding model changes, historical vectors and new vectors cannot be mixed, and a full re-index is mandatory. Make this explicit in change reviews.

    4. Building the Knowledge Base and Parsing Strategy

    When creating a dataset, the two decisions that actually matter are the embedding model and the parsing method (chunk template).

    The parsing method determines the chunking logic. A general mode for common documents suits most explanatory text and manuals, while templates tailored to Q&A pairs, tables, resumes, papers, and books usually fit those scenarios better. The guiding principle is to align chunk boundaries with the document’s natural semantic boundaries, not with word counts.

    After import, run three spot checks:

    • Randomly pick 5 to 10 chunks and confirm they are semantically complete with no cross-page breaks;
    • Query an obscure question whose answer you know exists and see whether it lands in the top three recalls;
    • Query a question that does not exist in the documents and observe whether the system tends to “fabricate,” which indicates whether a refusal constraint is needed later.

    Single-file parsing suits quick iteration during validation, while batch parsing suits the formal import. Determine the template with a small sample first, then run the full set, so a wrong template does not pollute the entire index and force a rebuild.

    5. Configuring the Retrieval Service’s Chat Side

    Most such services provide three configuration areas on the application side: basic assistant settings, a prompt engine, and model settings.

    In the basic settings, the most critical items are the assistant name and the bound dataset. A wrong binding is the most common cause of “no content retrieved.” The prompt engine constrains answer style and citation format; if no reranking model is available, it can be left empty and rely only on hybrid vector and keyword recall. Model settings require selecting an available reasoning model; if only pure retrieval is needed, this layer can be bypassed entirely during integration.

    6. Connecting External Retrieval on the Orchestration Platform

    Agent platforms usually offer two integration options: an external knowledge base or a custom tool node. Both are essentially the same, wrapping a single HTTP request into a data source the platform recognizes.

    The invocation pattern can be abstracted as:

    1. import requests
    2. def external_retrieve(query: str, dataset_ids: list[str], top_k: int = 5) -> list[dict]:
    3. resp = requests.post(
    4. "https://<retrieval-service-host>:<api-port>/api/v1/retrieval",
    5. headers={"Authorization": "Bearer <API_KEY>"},
    6. json={
    7. "question": query,
    8. "dataset_ids": dataset_ids,
    9. "page": 1,
    10. "page_size": top_k,
    11. "similarity_threshold": 0.2,
    12. },
    13. timeout=15,
    14. )
    15. resp.raise_for_status()
    16. data = resp.json()
    17. return data.get("data", {}).get("chunks", [])

    Four engineering details must be covered:

    1. Timeouts and retries. Retrieval is a synchronous blocking call. Always set both connect and read timeouts, and retry only on network errors to avoid amplifying failures.
    2. Empty-result fallback. When recall is empty, do not let the model improvise; fall back to a fixed “no supporting evidence found” response.
    3. Traceable citations. Attach the source file name and chunk position, and append the sources after the answer for manual verification.
    4. Permissions and keys. Store the API key in the platform’s environment variables or secret manager rather than hardcoding it into the workflow; reach the service over an internal network or encrypted channel.

    When filling the prompt, prefer structured assembly over plain string concatenation:

    1. [Retrieved Fragments]
    2. [1] Source: xxx.pdf, chunk 3
    3. <content>
    4. [2] ...
    5. [Answer Requirements]
    6. Answer only based on the fragments above; if the fragments are insufficient, state clearly what is missing and do not speculate.

    7. Attributing Differences and Tuning Order

    When external retrieval and built-in retrieval produce different answers, troubleshoot in the following order for the lowest cost:

    1. Binding and parameters: is the dataset bound correctly, and are top_k and the similarity threshold reasonable;
    2. Parsing quality: check sampled chunks for breaks and excessive header/footer noise;
    3. Recall strategy: is hybrid keyword and vector recall enabled, and is reranking introduced;
    4. Generation parameters: lowering temperature usually improves factual consistency significantly, and the prompt should reinforce “answer only based on the fragments”;
    5. Model capability: run a controlled experiment with a model that has stronger summarization ability under the same prompt.

    8. Summary

    Separating the retrieval layer and letting a dedicated document parsing and retrieval service handle “finding it” and “finding it accurately,” while the orchestration platform handles “explaining it clearly,” is a practical path around the accuracy ceiling of built-in retrieval. Three things matter in implementation: matching the parsing template to the document type, giving API calls proper timeouts and fallbacks, and keeping traceable citations in answers. To further reduce operational overhead, containerized deployment, object storage, and logging, monitoring, and alerting can all be obtained as general cloud products on Baidu AI Cloud, letting you focus on data quality and prompt engineering itself.