# Search for RAG pipelines

Retrieval decides what your model can say. MillionShort gives a RAG pipeline ranked passages from the web and specialist sources, with controls over which sites are allowed in.

A [RAG](https://millionshort.com/docs/glossary/what-is-rag) pipeline answers a question in two steps: it retrieves text, then a model writes from that text. The model can only be as good as what was retrieved. When the retrieval step is web search, three things usually go wrong.

## The problem

- **The passages are too short.** A one-line snippet tells the model a page exists, not what it says.
- **The same sites answer everything.** General search favors the most popular sites, so every answer cites the same handful of them, whatever the question.
- **Nothing says how far to trust a source.** A result list gives a title and a link. Your pipeline has to guess the rest.

## How MillionShort addresses it

- **Longer snippets.** `max_chars_per_result` sets the snippet length, up to 2,000 characters (the default is 800). That is usually enough for a model to quote and cite.
- **The right source for the question.** One call searches 1 to 5 of the [13 sources](https://millionshort.com/docs/search/sources) and returns one merged, ranked list. A medical question can search `medical` and `academic`; a question about a library can search `web`, `discussions` and `hn`. Every source costs the same.
- **Control over the site pool.** [`remove_top_sites`](https://millionshort.com/docs/search/remove-top-sites) removes results from the N most popular sites. The [lenses](https://millionshort.com/docs/search/lenses) do the rest: `include_domains` keeps only sites you name, `exclude_domains` blocks them, `boost_domains` and `bury_domains` change the order without filtering.
- **Kinds of page.** `page_types` and `topics` keep only matching results, for example documentation and tutorials. The slugs come from `GET /v1/sources`.
- **Signals on every result.** Each result carries [`popularity` and `risk`](https://millionshort.com/docs/search/popularity-and-risk) for its site, so your code can down-weight a source before the model sees it. `exclude_risky: true` drops every result whose site carries a risk label.
- **A reason for each result.** `explain: true` adds `why` and `signals` to each result, at no cost. It is useful when you are tuning retrieval and want to know why a passage was chosen.

## A retrieval call

This asks two sources for eight passages of up to 1,500 characters, keeps documentation and tutorials among the `web` results (the page-type filter acts on `web` and `news`, so the response names `discussions` in a `filter_not_applied` warning), drops results from sites with a risk label, and blocks one site:

```bash
curl https://api.millionshort.com/v1/search \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "rate limiting with a token bucket",
    "sources": ["web", "discussions"],
    "num_results": 8,
    "max_chars_per_result": 1500,
    "page_types": ["documentation", "tutorials"],
    "exclude_domains": ["example.com"],
    "exclude_risky": true
  }'
```

```python
import os

from millionshort import MillionShort

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

r = client.search(
    "rate limiting with a token bucket",
    sources=["web", "discussions"],
    num_results=8,
    max_chars_per_result=1500,
    page_types=["documentation", "tutorials"],
    exclude_domains=["example.com"],
    exclude_risky=True,
)

context = []
for hit in r.results:
    context.append(f'[{hit["position"]}] {hit["title"]} ({hit["url"]})\n{hit["snippet"]}')

prompt = "Answer from these sources and cite them by number.\n\n" + "\n\n".join(context)
print(r.usage.credits, "credits")
```

```ts
const res = await fetch('https://api.millionshort.com/v1/search', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "query": "rate limiting with a token bucket",
    "sources": [
      "web",
      "discussions"
    ],
    "num_results": 8,
    "max_chars_per_result": 1500,
    "page_types": [
      "documentation",
      "tutorials"
    ],
    "exclude_domains": [
      "example.com"
    ],
    "exclude_risky": true
  }),
});
if (!res.ok) throw new Error(`POST /v1/search failed: ${res.status}`);
const { data } = (await res.json()) as {
  data: { results: { position: number; title: string; url: string }[] };
};
for (const hit of data.results) console.log(hit.position, hit.title, hit.url);
```

The same call as a tool of the MCP server:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "search",
    "arguments": {
      "query": "rate limiting with a token bucket",
      "sources": [
        "web",
        "discussions"
      ],
      "num_results": 8,
      "max_chars_per_result": 1500,
      "page_types": [
        "documentation",
        "tutorials"
      ],
      "exclude_domains": [
        "example.com"
      ],
      "exclude_risky": true
    }
  }
}
```

The call searches two sources, so it costs 2 credits. The Python SDK is not published to a package registry yet; until it is, send the same request with any HTTP client.

## What it does not do

- **No live fetch in a search.** A snippet goes up to 2,000 characters. When that 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, as old as the day we captured it. Fetching a page as it is now is what [Extract](https://millionshort.com/docs/extract/parameters) is for, as a separate call.
- **No generated answers from a search.** A search returns results; your model writes the answer. For an answer written by us, [Agent](https://millionshort.com/docs/agent) is a separate, metered call: a written answer with a checked quote for every statement.
- **Keyword retrieval.** Queries that contain the words you expect on the page work well. A question phrased as a long sentence works better when your pipeline first turns it into a search query.
- **The web source is not continuously refreshed.** It is refreshed periodically and web results carry no date. For recent events, search `news`, `social` or `hn`. The date filters work on those sources; they are not applied to `web`, and the response says so. See [Freshness](https://millionshort.com/docs/search/freshness).

## Read next

- [RAG with MillionShort](https://millionshort.com/docs/search/guides/rag), the step-by-step guide.
- [Low-noise RAG](https://millionshort.com/docs/use-cases/low-noise-rag), when the problem is the quality of what comes back.
- Glossary: [What is RAG?](https://millionshort.com/docs/glossary/what-is-rag) and [What is RAG noise?](https://millionshort.com/docs/glossary/what-is-rag-noise)
- The [Search reference](https://millionshort.com/docs/search/parameters) lists every field.
