Build an AI Search Engine in One Hour: A Technical Walkthrough
This article walks through building a one-hour prototype of an AI search engine that returns cited, synthesized answers instead of a list of links. It covers a decoupled frontend-backend architecture with orchestration, retrieval, and generation layers; a hybrid search strategy that combines a third-party search API with lightweight main-text extraction and cleaning; prompt constraints and a two-stage summarization approach to reduce hallucination, latency, and cost; and practical optimizations such as clickable citations, streaming output, caching, observability, and compliance checks. It also highlights common pitfalls and a path for evolving the prototype into a production system.
1. From Keyword Matching to Answer Generation: Redefining the Goal
A traditional search engine returns ten blue links, leaving users to filter, compare, and summarize the results themselves. An AI search engine returns a synthesized answer with citations. This shift changes the system goal from “retrieve relevant documents” to “retrieve + understand + organize an answer,” which adds at least three engineering stages: web retrieval, content cleaning and chunking, and LLM-based synthesis.
Given this, the goal of a one-hour prototype should be strictly scoped: validate that the pipeline works end to end, not to maximize recall or answer quality. Being explicit about this prevents over-engineering during architecture selection.
2. Overall Architecture: Frontend-Backend Separation and Clear Boundaries
The prototype uses a separated frontend and backend. The frontend is a single-page application that handles conversational interaction, streaming rendering, and citation display. The backend exposes stateless HTTP APIs and is split into four layers:
- Access layer: parameter validation, timeout control, rate limiting, and unified error codes;
- Orchestration layer: decides whether to search, how many retrieval rounds to run, and how to manage multi-turn context;
- Retrieval layer: calls the search service for candidate pages, extracts main text, and chunks it;
- Generation layer: calls the LLM to produce a cited answer from the retrieved snippets.
The key is clear boundaries: the retrieval layer only cares about “returning clean text snippets,” the generation layer only cares about “answering from the given material,” and the orchestration layer owns all the policy. As a result, replacing the implementation of any one layer does not affect the others.
3. Core Piece One: Implementing the Search Service
The central question in the original discussion—how to build the search service—can be abstracted into three general options:
- Call a mature third-party search API. It is stable and has broad coverage, but exposes few controllable fields.
- Build your own crawling and indexing pipeline. It offers the most control, but cannot be completed within a one-hour prototype and involves compliance and anti-scraping costs.
- A hybrid approach: use a search API as the primary source, supplemented by targeted fetching of specified sites to complete the main text.
The prototype recommends the third option. A search API returns a title, a link, and a snippet, but snippets are often too short and truncated. A lightweight main-text extraction pass is therefore needed, followed by length normalization and denoising (removing navigation, ads, and leftover scripts).
Illustrative interface design:
# Retrieval layer: returns only cleaned candidate snippetsasync def search(query: str, top_k: int = 6) -> list[dict]:raw = await search_client.query(query, count=top_k) # third-party search capabilitydocs = []for item in raw:text = await extract_main_text(item["url"]) # main-text extractionfor chunk in split_text(text, size=800, overlap=80):docs.append({"url": item["url"], "title": item["title"], "text": chunk})return docs[:top_k * 2]
Engineering details make or break the result: you must set an overall timeout budget (for example, 3 seconds for retrieval and 5 seconds for extraction), fall back to “answer using snippets only” on failure, and mark in the answer that the material is insufficient.
4. Core Piece Two: The LLM’s Role and Prompt Constraints
In this pipeline, the LLM is not a knowledge base but a “reading comprehension reader.” To suppress hallucination, the prompt must strongly enforce three things: answer only from the given material; tag each conclusion with a source number; and explicitly state when material conflicts or no answer exists.
You are a rigorous technical assistant. Answer only from the numbered material below; do not introduce knowledge outside the material.Requirements: 1) tag the source after each conclusion with [n]; 2) state clearly when the material is insufficient; 3) output in Chinese, in bullet points.Material: [1] ... [2] ...Question: {question}
For lower latency and cost, a two-stage approach of “extractive summarization first, then generation” can be used: the first stage uses a smaller model to compress each snippet, and the second stage uses a more capable model to synthesize the final answer. This pattern significantly reduces context length for long documents.
5. Trustworthiness and Experience Optimization
- Clickable citations: numbers in the answer map back to the original links and are rendered as superscripts on the frontend;
- Streaming output: the generation layer pushes increments, and time-to-first-token usually affects perceived speed more than total duration;
- Caching: short-term caching of retrieval results for identical queries greatly reduces repeated calls;
- Observability: log the number of retrieval hits, per-stage latency, and fallback counts for each request to locate bottlenecks;
- Security and compliance: verify source legitimacy before fetching, respect site terms, and filter sensitive information from content.
6. Common Pitfalls and Evolution
Three pitfalls are easiest to hit at the prototype stage: stuffing too much raw text into the context and losing control of cost; lacking a fallback path so the whole system becomes unusable when retrieval fails; and choosing a poor chunk size so answers get cut off mid-sentence.
Later evolution can proceed in order: introduce vector retrieval and reranking to improve relevance, add multi-turn query rewriting to handle references, and build an evaluation set to run regression on answer quality. If you use general cloud capabilities, you can deploy the stateless service on a container platform, store cache and logs in object storage, use a message queue for peak shaving, and cover latency and failure-rate metrics with monitoring and alerting.
7. Summary
Building an AI search engine in one hour is feasible, provided you break the problem down correctly: the retrieval layer solves “where information comes from,” the generation layer solves “how information is understood,” and the orchestration layer solves “when to retrieve and how to fall back.” Once the three are decoupled, replacing any one of them will not overturn the overall design, and the prototype has room to evolve smoothly into a production system.
