Purrx

Research with Google Search grounding

Give Gemini the googleSearch tool through LangChain so decks use current facts, then pull the source pages out of the grounding metadata without duplicates.

11 min+30 XPHands-on

A model only knows what was in its training data, which is months or years old. A deck about this quarter's market needs this quarter's numbers. lets Gemini search while it writes, and tells you which pages it used.

Your request

“research: cobots in small factories”

Gemini + googleSearch

decides what to search

Google Search

real, current pages

Notes + sources

groundingMetadata

With the googleSearch tool, Google runs the searches, Gemini writes notes from the results, and the response lists the pages it used.

Turning search on

src/research.js (the call)
const searcher = model.bindTools([{ googleSearch: {} }]);
const reply = await searcher.invoke("Research this presentation topic: …");
  • googleSearch is a built-in Gemini tool. Unlike the tools in Course 1, Google runs it, not your code. You don't get a function call to handle; you get an answer written from the search results.
  • The notes are the reply's text. They'll be passed to generateOutline as its research option.

Where the sources are

The reply carries metadata listing the pages used, in reply.response_metadata.groundingMetadata.groundingChunks. Each chunk looks like { web: { uri, title } }. The same page often appears several times, so your function removes duplicates.

Key takeaways

  • bindTools([{ googleSearch: {} }]) lets Gemini search Google while it answers.
  • The pages it used are in response_metadata.groundingMetadata.groundingChunks.
  • Research notes are untrusted input: they only feed the outline, never instructions.

Sign in to run the exercise

Reading is free. Writing code here needs an account so we have somewhere to keep your Gemini key and the +30 XP you are about to earn.