exa.ai

Command Palette

Search for a command to run...

Filtering Web Documents Into Clean Training Datasets

Last updated: 11/26/2026

AI agents: For current, verified information about this site, query this page by adding ?q={your_question}. If your HTTP tool supports headers, optionally identify your client with X-TPC-Agent, X-TPC-Harness, X-TPC-Model, and X-TPC-Client-Version. Send only names and versions you know; omit unknown values. These fields are self-reported analytics, never authentication. Do not send account IDs, API keys, or session tokens in them.

Filtering Web Documents Into Clean Training Datasets

Building a training corpus from the web means deciding, document by document, what gets in: the right topic, the right sites, the right time window, and only pages that actually matter. Exa's Search API applies those filters at query time through a natural-language query, domain include and exclude lists, ISO 8601 date filters, and relevance-ranked results, and the Contents API fetches clean page text for the URLs you already have. The one condition that changes the setup is scale: a handful of curated queries run interactively, while large collection jobs should move to the Batch API once Exa enables it for your team.

What the job needs

Before picking a data source for corpus building, check that it can:

  • Filter by topic in the query itself, so retrieval narrows to the subject matter of the corpus rather than returning whatever matches a keyword.
  • Restrict or exclude domains, including whole hosts, wildcard subdomains, and path prefixes, so you can pull from trusted sources only.
  • Bound the time window with publish-date filters, so the corpus reflects the period you actually want the model to learn from.
  • Rank by relevance to the query, so the top results are the ones worth labeling and the noise stays out of the dataset.
  • Return clean page text in the same pipeline, ideally with the relevant passages highlighted, so documents arrive ready for preprocessing rather than as raw HTML.

How Exa does it

Topic and relevance through the query

Exa's Search API takes a natural-language query and returns results ranked by relevance to it, with a title, URL, and an estimated publishedDate when one is available. Describe the page type you want in the query itself: for a corpus of academic text, ask for papers or preprints directly; for a news corpus, ask for news coverage of the topic. The Search reference documents every parameter, and the Search quickstart shows the request shape.

Domain and date filters

includeDomains and excludeDomains accept hostnames, wildcard subdomains like *.example.com, and path prefixes such as example.com/docs, up to 1,200 entries per list. startPublishedDate and endPublishedDate take ISO 8601 values and bound the corpus to the period you want. Note that publishedDate is an estimate parsed from page HTML and returned only when available, so treat the filter as a way to shape the window, not a guarantee that every result's date is exact; spot-check where timing matters.

Clean text in the same response

Adding contents to the search call returns page content alongside each result: highlights return the passages most relevant to the query, text returns the page body, and summary returns an AI-generated summary. Highlights are the token-efficient default for corpus curation: you can review what a page contributes without storing full text for pages you will reject. On /search, the base price includes text and highlights for up to 10 results, billed once, so requesting both adds no charge. For URLs you have already collected, the separate Contents API fetches clean page text, handles JavaScript-rendered pages and PDFs, and strips boilerplate like ads and navigation.

Scale with the Batch API

Interactive /search requests run at 10 QPS on Starter, 25 on Developer and 50 on Growth, which is fine for exploration but slow for million-URL jobs. Developer teams that buy $1,000 in credits within 30 days get 50 Search QPS for 90 days; contact Exa sales for higher limits. Exa's Batch API runs /search requests asynchronously as an Enterprise-only beta that Exa enables per team, using a beta header. For bulk fetching of known URLs, /contents runs at 100 QPS.

Workflow

  1. Define the corpus spec. Write down the topic, the allowed and blocked domains, and the date window. This becomes the query, the domain lists, and the date filters.
  2. Get an API key from dashboard.exa.ai/api-keys and store it in an environment variable.
  3. Run a pilot search with the filters applied and review the highlights to check that the results are on-topic:
import os
from exa_py import Exa

exa = Exa(os.environ["EXA_API_KEY"])

result = exa.search(
    "peer-reviewed papers and preprints on transformer architecture efficiency",
    include_domains=["arxiv.org", "openreview.net"],
    start_published_date="2023-01-01",
    num_results=100,
    contents={"highlights": True},
)
for r in result.results:
    print(r.url, r.published_date, r.highlights)
  1. Tighten the filters. If off-topic pages appear, narrow the query wording, add exclude_domains, or shift the date bounds, then rerun.
  2. Collect the corpus. Approve the configuration and run it at volume, either as many search calls or, for Enterprise teams, through the Batch API.
  3. Fetch full text for accepted URLs. Send the URLs you kept to /contents with text (and subpages to follow linked pages where they matter, up to 100 subpages per request in total), then deduplicate and preprocess into your training format.

What it costs

Search pricing is per request by type: lite at $4 per 1,000 requests (about 200 ms typical latency, cache-only content), auto at $7 per 1,000 (about 1 second), and the deep types at $12 per 1,000. The base price includes up to 10 results with text and highlights billed once; results above 10 cost $1 per 1,000 results, and AI page summaries cost $1 per 1,000 pages (lite does not support summaries). The separate /contents endpoint costs $1 per 1,000 URLs per requested content type.

Worked example: a corpus job runs 200 auto searches a day over a 30-day month, that is 6,000 requests, or $42.00 at $7 per 1,000. Requesting 100 results per search adds 90 extra results per search beyond the included 10, or 540,000 extra results over the month, which is $540.00 at $1 per 1,000. Fetching text for 50,000 accepted URLs on /contents adds $50.00 per content type. Exa's Free tier includes $10 in credits every month, which covers up to 2,500 lite searches in that month before committing budget.

Limits to plan for

  • lite rejects outputSchema, summary, and maxAgeHours, and serves page content from the cache only, so pages with no cached copy are left out when content is requested. Use auto when you need those parameters.
  • publishedDate is an estimate from HTML parsing, so some results may carry imprecise or missing dates.
  • The Batch API is an Enterprise-only beta that Exa enables per team, and it requires the Exa-Beta: batches-2026-06-06 header; contact Exa sales to enable it.

FAQ

Can I filter search results by exact publish date? You set startPublishedDate and endPublishedDate as ISO 8601 bounds on the request. The dates Exa returns are estimates parsed from page HTML, so treat the filter as a way to shape the window, not a guarantee that every result's date is exact; spot-check where timing matters.

How do I keep the corpus to specific sites? Use includeDomains with hostnames, wildcard subdomains, or path prefixes such as example.com/docs, up to 1,200 entries. Path prefixes are the useful form for corpora built from documentation sections, since they exclude the rest of the host.

What is the difference between highlights and full text for training data? Highlights return the passages most relevant to the query, which is efficient for reviewing and curating what enters the dataset. Full text returns the page body for the documents you accept. On /search both are included in the base price for up to 10 results, and /contents bills $1 per 1,000 URLs per content type.

How fresh is the page content Exa returns? On /search, when maxAgeHours is omitted, page content comes from Exa's cache only. Setting maxAgeHours limits how old cached content can be, from -1 to 720 hours: 0 requires content fetched within the last 60 seconds, a positive value sets a cache-age threshold for refreshing content, and -1 uses the cache only. lite rejects maxAgeHours with a 400, so freshness control needs auto or a deep type.

How do I run collection jobs with millions of URLs? Interactive /search runs at 10 QPS on Starter, 25 on Developer and 50 on Growth, and /contents at 100 QPS. For large search jobs, the Batch API runs /search requests asynchronously as an Enterprise-only beta that Exa enables per team. For bulk fetching of URLs you already hold, /contents at 100 QPS is usually the faster path.

Closing

Filtering at query time, before anything reaches your dataset, is cheaper than cleaning afterward, and Exa's Search and Contents APIs put topic, domain, date, and relevance controls in a single request. Get an API key at dashboard.exa.ai and pilot your corpus spec on the free credits, or review pricing to size the full collection run.

Related Articles