Q&A via Search API and HyDE Re-ranking
Build RAG on top of an external Search API (NewsAPI): model-generated query variants via Structured Outputs, article retrieval, HyDE (Hypothetical Document Embeddings) re-ranking, streamed answer with source citations. Plus a comparison with the built-in web_search and file_search tools in the Responses API.
Architecture: Search → Re-rank → Answer
Instead of a vector database, we use an external Search API. The pipeline has three steps:
- Search — the model generates multiple query variants
- Re-rank — filter by semantic similarity using HyDE
- Answer — generate a response with source links
The code below uses the Responses API, which OpenAI recommends for new projects; Chat Completions is still supported. gpt-6-luna is the most cost-efficient model in OpenAI's current lineup ($0.10 per 1M input tokens). For harder questions, swap in gpt-6.2-sol.
The rest of this lesson opens after a free sign-up
Sign up with email or Google: the first two lessons of every course stay open for good, and the whole catalog is open for 7 days. No card needed.


