When engineers first build retrieval-augmented generation (RAG) pipelines, they usually start by wrapping a search engine API to gather web context. If a user asks a question, the application queries the web, downloads the top pages, and passes the text to the LLM.

If you wrap a traditional keyword engine like Google or Bing, you quickly hit two problems: link filtering and DOM extraction. Standard search engines return page links and brief, disjointed search snippets. To get the actual content, your application must fetch the raw HTML, strip out navigation bars, headers, and footer scripts, and parse the remaining text into clean paragraphs. This extraction complexity is a major reason why web snippets fail in production workloads.

This is a maintenance burden. To bypass it, developers are moving to APIs designed specifically to feed LLMs.


1. Traditional Keyword Search (Google Custom Search JSON API)

The Google Custom Search API returns search listings based on traditional PageRank and keyword matching.

  • How it works: You send a search query via HTTP GET and receive a list of titles, URLs, and text snippets.
  • The Payload:
    {
      "title": "Astro Documentation",
      "link": "https://docs.astro.build",
      "snippet": "Astro is a web framework designed for speed..."
    }
    
  • The Trade-off: Google has the most complete index of the web. But you only get links. If you want the page contents, you must write your own fetcher and DOM scraper.

2. RAG-Optimized Search (Tavily)

Tavily is a search engine built specifically to feed LLMs clean, pre-parsed content.

  • How it works: Instead of returning just links, Tavily’s API searches the web, extracts the raw text from the top pages, strips out HTML clutter, and returns clean, sliced text chunks.
  • TypeScript Integration:
    import { tavily } from '@tavily/core';
    
    const tvly = tavily({ apiKey: process.env.TAVILY_API_KEY });
    const response = await tvly.search("Explain Astro hydration patterns", {
      searchDepth: "advanced",
      maxResults: 5
    });
    
    // Output contains cleaned, pre-sliced text context:
    console.log(response.results[0].content);
    
  • The Trade-off: It reduces token usage by cleaning the DOM before returning it. However, you rely on Tavily’s internal parsing and slicing algorithms, giving you less control over how the text is chunked.

Exa (formerly Metaphor) uses a custom transformer model to predict links based on natural language queries, bypassing keyword matching entirely.

  • How it works: Exa searches using embeddings. You can query it using natural, conversational prompts (e.g., “Here is a great guide on circuit breakers:”) rather than keyword chains.
  • TypeScript Integration:
    import Exa from 'exa-js';
    
    const exa = new Exa(process.env.EXA_API_KEY);
    const result = await exa.searchAndContents("resilient parallel queries in TypeScript", {
      type: "neural",
      useAutoprompt: true,
      numResults: 3,
      text: { maxCharacters: 1000 }
    });
    
    console.log(result.results[0].text);
    
  • The Trade-off: Exa is excellent for finding high-quality, relevant source URLs that keyword matchers miss. But its neural search can sometimes bypass specific, niche technical terms if they don’t map to the semantic embedding space.

4. DOM-to-Markdown Ingestion (Firecrawl)

Firecrawl converts entire websites or subpages into clean, structured Markdown in a single API call.

  • The Trade-off: Firecrawl is the best tool for ingesting large, specific documentation hubs or product sites. However, it is an crawler, not a real-time search index. You must already know the root URL you want to scrape. For a deeper look at hosting local browsers vs using cloud scraping APIs, read our comparison of open source vs. hosted scrapers.

The Grounding Decision Matrix

Choose your grounding API based on your operational constraints:

ObjectiveRecommended ToolCore Advantage
Query a massive, general web indexGoogle Custom SearchMost complete indexing of surface web links
Get clean, pre-sliced text snippets quicklyTavilyMinimizes token overhead in basic RAG pipelines
Find semantically related technical resourcesExaNeural link prediction outperforms keyword matching
Scrape specific domains into clean MarkdownFirecrawlHandles proxy rotation and headless DOM rendering automatically