Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Vertex AI Search with citations

Hello,
I used to have a search functionality with LLM response where the citations were included in-line and when clicked pointed to a result from search results like so:
"example [1]" 
Now, however, Google has changed it (in the search preview too) to have clickable link icons that expand and show the sources like so:

dosmac_0-1727362398801.png

My question is, how can I achieve the same functionality? The LLM response now is a string without any source numbers, references, or anything else, just a plain response

Thank you so much for your time and any help provided 

 

Solved Solved
1 2 1,002
1 ACCEPTED SOLUTION

Hi @dosmac,

Welcome to Google Cloud Community!

You’d like your LLM responses to include citations for greater transparency and to easily track sources.

Here's how to achieve that using Google Search's API:

1. Request Citations in Your Search: When submitting your search request, include the following parameters in your contentSearchSpec.summarySpec:

  • includeCitations: true: This tells the API to include citation numbers in the summary.
  • summaryResultCount (optional): Specify how many top results you want the summary to be generated from (maximum 5).
  • maxExtractiveAnswerCount (optional): Controls how many "extractive answers" (direct snippets from the source) are included per search result.

2.  Access the Citations in the Response: The API response will contain the following information:

  • summaryText: The generated search summary, with citation numbers within square brackets.
  • citations: This array provides metadata for each cited sentence, including:
  • >> startIndex and endIndex: The start and end positions of the cited sentence in the text.
  • >> sources: A list of the source indices (referenceIndex) for each reference used in the sentence.
  • >>references: An array with metadata about each cited source, such as title, document name, and URL.

Additional considerations: 

  • By default, search summaries returned by the API don't include citations. For detailed information on using Google Search's API and obtaining citations, refer to the official documentation.
  • The citation numbers in the summary refer to the order of the results returned in the search response. For example, "[1]" means the sentence is taken from the first result.

I hope the above information is helpful.

View solution in original post

2 REPLIES 2

Hi @dosmac,

Welcome to Google Cloud Community!

You’d like your LLM responses to include citations for greater transparency and to easily track sources.

Here's how to achieve that using Google Search's API:

1. Request Citations in Your Search: When submitting your search request, include the following parameters in your contentSearchSpec.summarySpec:

  • includeCitations: true: This tells the API to include citation numbers in the summary.
  • summaryResultCount (optional): Specify how many top results you want the summary to be generated from (maximum 5).
  • maxExtractiveAnswerCount (optional): Controls how many "extractive answers" (direct snippets from the source) are included per search result.

2.  Access the Citations in the Response: The API response will contain the following information:

  • summaryText: The generated search summary, with citation numbers within square brackets.
  • citations: This array provides metadata for each cited sentence, including:
  • >> startIndex and endIndex: The start and end positions of the cited sentence in the text.
  • >> sources: A list of the source indices (referenceIndex) for each reference used in the sentence.
  • >>references: An array with metadata about each cited source, such as title, document name, and URL.

Additional considerations: 

  • By default, search summaries returned by the API don't include citations. For detailed information on using Google Search's API and obtaining citations, refer to the official documentation.
  • The citation numbers in the summary refer to the order of the results returned in the search response. For example, "[1]" means the sentence is taken from the first result.

I hope the above information is helpful.

Thanks for your reply!