Menu

Guides

RAG with MillionShort

Retrieve passages from the web for a language model, keep the noise out, and cite what you used.

Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)

Retrieval-augmented generation has three steps: find passages, put them in the prompt, and have the model answer from them with citations. This guide covers the first two with MillionShort, and stops where your model begins.

What you get from a search is a ranked list of results, each with a snippet: the passage of the page that matches the query, up to 2,000 characters. That is the text you retrieve by default. When a snippet is not enough, include_content: true adds the text of the page as we hold it to web and news results, for 1 credit a call (up to 10 results). It is our stored copy, not a live fetch; to fetch a page as it is now, use Extract.

1. Search with long snippets

Ask for the longest snippets when the results are going into a prompt. The default is 800 characters.

Example
Shell
curl https://api.millionshort.com/v1/search \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "how does a heat pump work in cold climates",
    "num_results": 10,
    "max_chars_per_result": 2000
  }'

2. Take the noise out before it reaches the model

A model cannot ignore what is in its context. Four controls keep weak pages out of it, and all four are free:

Then, in your own code, keep at most two results per site, so one site cannot fill the context.

3. Build the context

Number the passages, and carry the URL with each one so the model can cite it.

Example
Python
import os

from millionshort import MillionShort

client = MillionShort(api_key=os.environ["MILLIONSHORT_API_KEY"])


def retrieve(question, limit=6):
    r = client.search(
        question,
        num_results=20,
        remove_top_sites=1000,
        exclude_risky=True,
        max_chars_per_result=2000,
    )
    passages, per_site = [], {}
    for hit in r.results:
        if not hit["snippet"]:
            continue
        per_site[hit["site"]] = per_site.get(hit["site"], 0) + 1
        if per_site[hit["site"]] > 2:
            continue
        passages.append(hit)
        if len(passages) == limit:
            break
    return passages, r.usage.credits


def build_prompt(question, passages):
    blocks = [
        f"[{n}] {hit['title']}\n{hit['url']}\n{hit['snippet']}"
        for n, hit in enumerate(passages, start=1)
    ]
    return (
        "Answer the question using only the numbered passages. "
        "Cite passages as [n]. If they do not contain the answer, say so.\n\n"
        + "\n\n".join(blocks)
        + f"\n\nQuestion: {question}"
    )


question = "how does a heat pump work in cold climates"
passages, credits = retrieve(question)
print(build_prompt(question, passages)[:400])
print(len(passages), "passages for", credits, "credits")

Send the prompt to the model of your choice. Nothing here depends on which one.

4. Ask the right experts

A question about this week needs a current source; a question about a paper needs academic. One call can ask up to five sources, and each result says which it came from, so you can label passages for the model: "[3] (news, 2026-11-06) ...".

Questionsources
General knowledge, how-to["web"]
Current events["news", "web"]
A scientific claim["academic", "web"], or ["medical"] for clinical questions
Opinions and experience["discussions", "smallweb"]
A company's own statements["finance", "news"]

Dated sources let you tell the model how old a passage is, and time_range or start_date and end_date keep only the passages from the days you want. web results have no date, so a date filter is not applied to them; see Freshness.

5. Cite honestly

6. Control the cost

What this does not do

Next

This page as Markdown ยท llms.txt