Building an AI Search Engine in One Hour: Architecture and Retrieval-Augmented Generation in Practice
This article presents a practical approach to building a minimal AI search engine prototype in about one hour. It distinguishes prototype scope from production requirements, describes a six-layer architecture for retrieval-augmented generation, and explains how to implement search aggregation, query understanding, content extraction, evidence selection, context construction, answer generation, citation validation, engineering observability, and compliance. The goal is to show how search services and large language models can be combined into an observable, controllable, and evaluable pipeline that produces evidence-based answers with citations.
An AI search engine is not simply a matter of sending a question directly to a large language model. Large language models can understand and summarize language, but their knowledge has limitations in timeliness, coverage, and factual consistency. Search services can retrieve the latest information, but they cannot directly produce structured, readable, and comprehensive answers. Combining the two requires an observable, controllable, and evaluable retrieval-augmented generation pipeline. This article focuses on the goal of building a prototype in one hour and discusses a neutral, general, and engineering-oriented implementation approach, with emphasis on how to implement the search service and how to make the model generate citable answers based on evidence.
1. Define the Boundaries: A Prototype Is Not a Production System
“One hour” is better understood as defining a minimum viable prototype: users can enter a question, and the system completes query understanding, web retrieval, body extraction, evidence selection, context construction, and answer generation, with cited sources. It does not aim to cover every web page, build a large-scale index, or promise production-grade availability. A production system also needs to consider concurrency, caching, rate limiting, circuit breaking, content safety, copyright compliance, evaluation sets, and canary releases.
Therefore, the design should first clarify its boundaries. In the prototype stage, three things should be validated first. First, can the search service reliably return candidate web pages relevant to the question? Second, can body extraction and evidence selection turn “web page snippets” into “citable evidence”? Third, can the large language model generate a concise answer within the given evidence and correctly mark citations? Only after these three things work does it make sense to optimize indexing, ranking models, and multi-turn dialogue.
2. Overall Architecture: Frontend-Backend Separation and a Retrieval-Augmented Pipeline
A frontend-backend separated architecture can be used. The frontend handles the input box, streaming output, citation display, and feedback buttons. The backend web framework provides query APIs, session management, authentication, and logging. The model orchestration layer handles calls to search services, web page extraction, reranking, and large language model services. The architecture can be divided into six layers:
- Interaction layer: receives natural language questions and displays answers, citation lists, and loading states.
- Query understanding layer: identifies intent, entities, time sensitivity, and language, and generates retrieval queries.
- Search aggregation layer: calls one or more compliant search sources, normalizes results, deduplicates them, and performs initial ranking.
- Content extraction layer: fetches web page bodies, cleans navigation, ads, and scripts, and splits content into paragraphs.
- Evidence selection layer: ranks by relevance, timeliness, source credibility, and information density, and compresses context.
- Generation and validation layer: constrains the large language model to answer based on evidence, validates citation numbers, and handles cases where an answer cannot be given.
The key to this pipeline is not a single model, but the closed loop of “retrieval, extraction, selection, generation, and validation.” The search service is the entry point, and evidence quality determines the upper limit of answer quality. The generation layer is only the last mile.
3. Implementing the Search Service: Three Approaches and a Hybrid Strategy
The search service is the real core of an AI search engine. There are three common implementation approaches.
The first is to integrate compliant general web search APIs. The advantages are fast integration, broad coverage, and suitability for prototype validation. The disadvantages are that results are less controllable, may be subject to quotas and rate limits, and body quality varies. During implementation, a unified adapter layer should be created to normalize returned fields such as title, summary, link, publication time, source domain, and ranking score, and to set timeouts, retries, and fallbacks.
The second is to build your own crawling and indexing. Web pages are acquired through seed sites, sitemaps, and link discovery, followed by body extraction, deduplication, inverted indexing, and vector indexing. The advantages are controllability, customization, and support for vertical domains. The disadvantages are a long build cycle and the need to handle crawling frequency, robots.txt, copyright, privacy, and content safety.
The third is a hybrid strategy: use general search APIs for recall and a self-built index for vertical enhancement, or perform general recall first and then supplement with a domain knowledge base. For the prototype stage, a lightweight version of the hybrid approach is recommended: rely mainly on general search APIs, add result deduplication, source credibility scoring, and body extraction, and introduce domain indexes later.
A runnable pseudo-code example for search aggregation is as follows:
function search_and_collect(query, top_k):candidates = []for source in enabled_sources:resp = source.search(query, limit=top_k, timeout=3000)candidates.extend(normalize_result(resp))candidates = dedupe_by_canonical_link(candidates)candidates = score_source_trust(candidates)return rank_candidates(candidates, query)
Three points should be emphasized here. First, unify timeouts and concurrency so that a single search source does not slow down the entire system. Second, normalize links for deduplication to prevent the same content from entering through multiple URLs. Third, retain source metadata for later citation and credibility scoring.
4. Query Understanding: Turning User Questions into Retrievable Queries
User questions are often conversational and contain implicit conditions. The query understanding layer needs to perform intent classification, entity recognition, time range determination, and sub-query generation. For example, “What has changed recently in a certain technical approach?” should be identified as a time-sensitive question and generate queries with time terms. “Compare A and B” should be split into multiple sub-queries for separate retrieval, and the evidence should then be merged.
In the prototype stage, complex models are not necessary. Rules plus lightweight models can be used: first extract keywords, time, and entities, then generate two to four query variants. Each query is retrieved independently, and the results are merged and deduplicated. Query expansion should be restrained to avoid irrelevant semantic drift. For questions that cannot be determined, the system should proactively narrow the scope or prompt the user to provide additional conditions.
5. Body Extraction and Evidence Selection: The Key to Answer Quality
Search result summaries are usually not enough to support an answer, so web page bodies must be fetched. The extraction layer should do three things: clean scripts, navigation, and ads; identify the main body; and split by paragraph while preserving heading hierarchy. The granularity should not be too fine, because paragraph-level evidence is more suitable for citation. It should also not be too long, otherwise the context budget will be consumed by low-density content.
Evidence selection can use multi-signal fusion: query relevance, paragraph information density, source credibility, publication time, whether it contains specific facts or data, and whether it duplicates existing evidence. For conflicting evidence, do not simply take the first item. Instead, keep the conflict in the context and let the model explain the uncertainty. In the prototype stage, keyword matching plus vector similarity can be used for initial filtering, followed by small-batch reranking with a large language model.
6. Context Construction and Generation: Let the Model Answer with Evidence
Context construction is not about concatenating all web pages. It is about packaging evidence by citation number. Each piece of evidence includes the source title, link, publication time, and body snippet. The context should be kept within the model budget, prioritizing highly relevant, credible, and timely evidence. The prompt should clearly constrain the model: answer only based on the given evidence; state that it cannot confirm when evidence is insufficient; mark citation numbers for each key conclusion; and do not fabricate links or facts.
After generation, citation validation must be performed: check whether citation numbers exist in the evidence list, whether key sentences have corresponding evidence, and whether there are “unsupported assertions.” For questions that cannot be answered, returning “current evidence is insufficient” is more credible than forcing a generation. Streaming output can improve the experience, but citation validation should be performed after the complete answer is generated.
7. Engineering and Compliance: What Must Be Added After the Prototype
For engineering, at minimum you need request-level tracing, search source latency statistics, extraction failure rates, evidence hit rates, and user feedback. Caching can be divided into two layers: query result caching and web page body caching, with reasonable expiration times. Concurrency control should include search source rate limiting, crawling frequency control, and circuit breaking for model calls. For evaluation, build a small question set, manually label relevance, citation accuracy, and answer completeness, and run continuous regression tests.
For compliance, crawling should respect robots.txt and site terms, respect copyright and privacy, and avoid collecting sensitive personal information. Rate limits should be set for search sources. Generated content should be filtered for safety. Citations should be clear and traceable. Only by incorporating compliance and observability into the design can an AI search engine have a foundation for moving from a prototype to a business system.
In summary, an AI search engine skeleton can be built in one hour, but real competitiveness comes from the quality of the search service, the strategy for evidence selection, and the rigor of citation validation. With retrieval-augmented generation as the main line, splitting search, extraction, selection, generation, and validation into replaceable modules enables rapid iteration and gradual progress toward production readiness.
