Build an AI Search Engine in One Hour: From Web Retrieval to Intelligent Summarization

    This article walks through a practical one-hour prototype of an AI search engine that combines a search API, a large language model, and an orchestration layer. It explains why AI chat is not AI search, outlines the frontend/backend architecture, and covers query rewriting, result filtering, prompt constraints, citation rendering, streaming UX, fallback handling, AI-assisted development, and a pre-launch checklist.

    1. Why “AI Chat” Is Not “AI Search”

    Many developers hit the same pitfall the first time they build a large language model application: they send the user’s question directly to the model and receive an answer that looks fluent but may be outdated or even wrong. The reason is simple. The model’s knowledge comes from training data. It knows nothing about events after its training cutoff, and it tends to fill gaps by inventing answers that look plausible.

    The core value of an AI search engine is web access. Its processing pipeline is:

    1. Receive the user’s question.
    2. Call an external search service to retrieve the latest web results.
    3. Pass the search results to the large language model as context.
    4. Have the model generate a synthesized answer with citations based on the retrieved content.
    5. Keep a traditional search-style result list so users can verify sources themselves.

    This pipeline separates generation capability from factual grounding. The model handles understanding, synthesis, and expression, while the search service provides fresh facts. This is also the general architectural approach used by many mainstream intelligent Q&A products today.

    2. Overall Architecture Design

    The project uses a frontend/backend separation:

    • Frontend: Built with a mainstream frontend framework. It handles search input, streaming answer rendering, citation annotations, and search result list display.
    • Backend: Uses a Python web framework to provide APIs and handle retrieval orchestration, prompt assembly, model invocation, and result aggregation.
    • Search service: Instead of crawling web pages or building an inverted index, it directly integrates an existing search API.
    • Large language model service: Uses a general-purpose model with long-context and tool-calling capabilities for synthesis and summarization.

    The internals of a traditional search engine are very complex: crawling, parsing, deduplication, indexing, and relevance ranking all rely on massive server infrastructure. For application-layer developers, however, these capabilities can be obtained through a search API. What we need to build is a Retrieval-Augmented Generation (RAG) orchestration layer on top of that API.

    A simplified backend flow looks like this:

    1. async def answer_question(question: str):
    2. # 1. Search the web for real-time information
    3. results = await search_service.query(question, top_k=5)
    4. # 2. Assemble context with citation numbers
    5. context = "\n\n".join(
    6. f"[{i+1}] {item['title']}\n{item['snippet']}\nSource: {item['url']}"
    7. for i, item in enumerate(results)
    8. )
    9. # 3. Build a system prompt that constrains the model to the context
    10. system_prompt = (
    11. "You are a rigorous search assistant. Answer the question using only the search materials below, "
    12. "and add citation numbers such as [1][2] after key claims. "
    13. "If the materials are insufficient to answer, state so clearly."
    14. )
    15. # 4. Stream the answer while returning structured search results
    16. answer_stream = llm.stream(system_prompt, question, context)
    17. return answer_stream, results

    3. Key Details in the Search Service Layer

    The search service determines the upper bound of answer quality. Several lessons are worth noting:

    1. Query rewriting. User questions are often conversational and long, which makes direct search less effective. You can have the large language model first rewrite the question into keyword combinations better suited for a search engine. For example, “How are EV prices lately?” can be rewritten as “2025 new energy vehicle price trends.”

    2. Result filtering and deduplication. Search API results vary in quality. Simple filtering by domain diversity and content relevance helps avoid multiple sources repeating the same press release, which would narrow the model’s view.

    3. Combining snippets and full text. Using only search snippets is fast but provides limited information. Fetching and truncating the full text of key results can significantly improve answer depth at the cost of higher latency. A layered strategy of “snippets first, full text as supplement” can be used.

    4. Timeliness annotation. Publication times in search results should be preserved, and the model should be required to reflect the time range in its answer, for example, “According to public information from the first half of 2025…”

    4. Model Invocation and Prompt Engineering

    Prompt design is key to answer quality. In practice, the system prompt should clearly state:

    • Answer only based on the provided materials. Do not use training knowledge to add facts.
    • Citations must be attached to specific sentences, not placed only at the end.
    • If the question cannot be answered, say so honestly. Do not fabricate.
    • When materials conflict, point out the disagreement instead of forcing a synthesis.

    To let users verify sources, the frontend needs to render [1], [2], and similar citation markers in the answer as clickable references. Hovering or clicking should show the source title and link. This is both a product experience and a trust design.

    Related question recommendations also depend on the model. After the main answer is complete, have the model generate 3 to 5 natural follow-up directions based on the “original question + retrieved materials + existing answer” to guide users toward deeper exploration. This step is low-cost but clearly improves retention and exploration depth.

    5. UX Optimization: Streaming Output and Fault Tolerance

    AI applications feel much slower than traditional applications, so streaming output is essential (SSE or WebSocket):

    • Keep first-token latency within 1 second so users immediately see that an answer is being generated.
    • Render the source list before the answer starts, creating the expectation that “the materials have already been found.”
    • Have fallback strategies for model or search service timeouts. For example, if search fails, prompt the user to retry instead of silently returning an error.
    • Validate citation numbers in the model output and remove references to non-existent sources to avoid hallucinated citations.

    6. Accelerating Development with AI Coding Tools

    The reason this project could reach a prototype in about one hour was a change in development workflow. My process was:

    1. Write requirements and the technical plan first: Describe the architecture, API contracts, and page structure clearly in natural language.
    2. Let AI coding tools generate the skeleton: Generate frontend and backend project structures, routes, components, and type definitions in one pass.
    3. Review and correct manually: Focus on prompt design, streaming handling, and error branches, which are prone to mistakes.
    4. Iterate during integration: Change only one clear point at a time and ask the tool for a complete, runnable modification.

    Humans make decisions and accept results; tools execute coding. With this division of labor, one person can maintain development momentum on both frontend and backend.

    7. Pre-Launch Checklist

    • Are the number of search results and source diversity reasonable?
    • Does the model answer strictly based on the materials? Spot-check claims without citations.
    • Do citation numbers correspond one-to-one with the source list?
    • Does streaming output survive network jitter?
    • Are edge cases such as sensitive queries, empty results, and API timeouts covered?
    • Are model and search API costs monitored and rate-limited?

    Conclusion

    An AI search engine is not mysterious. It is essentially a combination of a search API, a large language model, and an orchestration layer. What really determines success is retrieval quality, prompt constraints, and citation credibility. With these parts done solidly and AI coding tools improving engineering efficiency, a usable and trustworthy intelligent search product can be built by a single person in a very short time.