Use Grounding with Google Search or Vertex AI Search (Preview)
mainGrounding is a preview feature that connects model output to verifiable sources to reduce hallucinations. You can access these features via the vertexAI.preview namespace.
Google Search Grounding
Pass a googleSearchRetrieval tool to the generateContent method to enable Google Search grounding.
Vertex AI Search Grounding
Pass a retrieval tool containing a vertexAiSearch configuration with your specific datastore path to enable grounding against your own data stores.
// Google Search Grounding
const googleSearchRetrievalTool = {
googleSearchRetrieval: {
disableAttribution: false,
},
};
const result = await generativeModelPreview.generateContent({
contents: [{role: 'user', parts: [{text: 'Why is the sky blue?'}]}],
tools: [googleSearchRetrievalTool],
});
// Vertex AI Search Grounding
const vertexAIRetrievalTool = {
retrieval: {
vertexAiSearch: {
datastore: 'projects/.../locations/.../collections/.../dataStores/...',
},
disableAttribution: false,
},
};
const result = await generativeModelPreview.generateContent({
contents: [{role: 'user', parts: [{text: 'Why is the sky blue?'}]}],
tools: [vertexAIRetrievalTool],
});