Skip to content

Commit a4ccd25

Browse files
authored
feat(ai): add support for grounding with google search (#9068)
1 parent ae976d0 commit a4ccd25

20 files changed

+660
-28
lines changed

.changeset/five-kids-grow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': minor
3+
'@firebase/ai': minor
4+
---
5+
6+
Add support for Grounding with Google Search.

common/api-review/ai.api.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ export interface GoogleAIGenerateContentResponse {
486486
usageMetadata?: UsageMetadata;
487487
}
488488

489+
// @public
490+
export interface GoogleSearch {
491+
}
492+
493+
// @public
494+
export interface GoogleSearchTool {
495+
googleSearch: GoogleSearch;
496+
}
497+
489498
// @public @deprecated (undocumented)
490499
export interface GroundingAttribution {
491500
// (undocumented)
@@ -498,16 +507,29 @@ export interface GroundingAttribution {
498507
web?: WebAttribution;
499508
}
500509

510+
// @public
511+
export interface GroundingChunk {
512+
web?: WebGroundingChunk;
513+
}
514+
501515
// @public
502516
export interface GroundingMetadata {
503517
// @deprecated (undocumented)
504518
groundingAttributions: GroundingAttribution[];
505-
// (undocumented)
519+
groundingChunks?: GroundingChunk[];
520+
groundingSupports?: GroundingSupport[];
521+
// @deprecated (undocumented)
506522
retrievalQueries?: string[];
507-
// (undocumented)
523+
searchEntryPoint?: SearchEntrypoint;
508524
webSearchQueries?: string[];
509525
}
510526

527+
// @public
528+
export interface GroundingSupport {
529+
groundingChunkIndices?: number[];
530+
segment?: Segment;
531+
}
532+
511533
// @public
512534
export enum HarmBlockMethod {
513535
PROBABILITY = "PROBABILITY",
@@ -857,14 +879,17 @@ export enum SchemaType {
857879
STRING = "string"
858880
}
859881

860-
// @public (undocumented)
882+
// @public
883+
export interface SearchEntrypoint {
884+
renderedContent?: string;
885+
}
886+
887+
// @public
861888
export interface Segment {
862-
// (undocumented)
863889
endIndex: number;
864-
// (undocumented)
865890
partIndex: number;
866-
// (undocumented)
867891
startIndex: number;
892+
text: string;
868893
}
869894

870895
// @public
@@ -901,7 +926,7 @@ export interface TextPart {
901926
}
902927

903928
// @public
904-
export type Tool = FunctionDeclarationsTool;
929+
export type Tool = FunctionDeclarationsTool | GoogleSearchTool;
905930

906931
// @public
907932
export interface ToolConfig {
@@ -961,5 +986,12 @@ export interface WebAttribution {
961986
uri: string;
962987
}
963988

989+
// @public
990+
export interface WebGroundingChunk {
991+
domain?: string;
992+
title?: string;
993+
uri?: string;
994+
}
995+
964996

965997
```

docs-devsite/_toc.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,18 @@ toc:
7676
path: /docs/reference/js/ai.generativemodel.md
7777
- title: GoogleAIBackend
7878
path: /docs/reference/js/ai.googleaibackend.md
79+
- title: GoogleSearch
80+
path: /docs/reference/js/ai.googlesearch.md
81+
- title: GoogleSearchTool
82+
path: /docs/reference/js/ai.googlesearchtool.md
7983
- title: GroundingAttribution
8084
path: /docs/reference/js/ai.groundingattribution.md
85+
- title: GroundingChunk
86+
path: /docs/reference/js/ai.groundingchunk.md
8187
- title: GroundingMetadata
8288
path: /docs/reference/js/ai.groundingmetadata.md
89+
- title: GroundingSupport
90+
path: /docs/reference/js/ai.groundingsupport.md
8391
- title: ImagenGCSImage
8492
path: /docs/reference/js/ai.imagengcsimage.md
8593
- title: ImagenGenerationConfig
@@ -130,6 +138,8 @@ toc:
130138
path: /docs/reference/js/ai.schemarequest.md
131139
- title: SchemaShared
132140
path: /docs/reference/js/ai.schemashared.md
141+
- title: SearchEntrypoint
142+
path: /docs/reference/js/ai.searchentrypoint.md
133143
- title: Segment
134144
path: /docs/reference/js/ai.segment.md
135145
- title: StartChatParams
@@ -150,6 +160,8 @@ toc:
150160
path: /docs/reference/js/ai.videometadata.md
151161
- title: WebAttribution
152162
path: /docs/reference/js/ai.webattribution.md
163+
- title: WebGroundingChunk
164+
path: /docs/reference/js/ai.webgroundingchunk.md
153165
- title: analytics
154166
path: /docs/reference/js/analytics.md
155167
section:

docs-devsite/ai.functiondeclaration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Structured representation of a function declaration as defined by the [OpenAPI 3
1515
<b>Signature:</b>
1616

1717
```typescript
18-
export declare interface FunctionDeclaration
18+
export interface FunctionDeclaration
1919
```
2020

2121
## Properties

docs-devsite/ai.functiondeclarationstool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A `FunctionDeclarationsTool` is a piece of code that enables the system to inter
1515
<b>Signature:</b>
1616

1717
```typescript
18-
export declare interface FunctionDeclarationsTool
18+
export interface FunctionDeclarationsTool
1919
```
2020

2121
## Properties

docs-devsite/ai.googlesearch.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# GoogleSearch interface
13+
Specifies the Google Search configuration.
14+
15+
Currently, this is an empty object, but it's reserved for future configuration options.
16+
17+
<b>Signature:</b>
18+
19+
```typescript
20+
export interface GoogleSearch
21+
```

docs-devsite/ai.googlesearchtool.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# GoogleSearchTool interface
13+
A tool that allows a Gemini model to connect to Google Search to access and incorporate up-to-date information from the web into its responses.
14+
15+
Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
16+
17+
<b>Signature:</b>
18+
19+
```typescript
20+
export interface GoogleSearchTool
21+
```
22+
23+
## Properties
24+
25+
| Property | Type | Description |
26+
| --- | --- | --- |
27+
| [googleSearch](./ai.googlesearchtool.md#googlesearchtoolgooglesearch) | [GoogleSearch](./ai.googlesearch.md#googlesearch_interface) | Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options. Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options.<!-- -->When using this feature, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
28+
29+
## GoogleSearchTool.googleSearch
30+
31+
Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options. Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options.
32+
33+
When using this feature, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
34+
35+
<b>Signature:</b>
36+
37+
```typescript
38+
googleSearch: GoogleSearch;
39+
```

docs-devsite/ai.groundingchunk.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# GroundingChunk interface
13+
Represents a chunk of retrieved data that supports a claim in the model's response. This is part of the grounding information provided when grounding is enabled.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface GroundingChunk
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [web](./ai.groundingchunk.md#groundingchunkweb) | [WebGroundingChunk](./ai.webgroundingchunk.md#webgroundingchunk_interface) | Contains details if the grounding chunk is from a web source. |
26+
27+
## GroundingChunk.web
28+
29+
Contains details if the grounding chunk is from a web source.
30+
31+
<b>Signature:</b>
32+
33+
```typescript
34+
web?: WebGroundingChunk;
35+
```

docs-devsite/ai.groundingmetadata.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

1212
# GroundingMetadata interface
13-
Metadata returned to client when grounding is enabled.
13+
Metadata returned when grounding is enabled.
14+
15+
Currently, only Grounding with Google Search is supported (see [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface)<!-- -->).
16+
17+
Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
1418

1519
<b>Signature:</b>
1620

@@ -23,13 +27,17 @@ export interface GroundingMetadata
2327
| Property | Type | Description |
2428
| --- | --- | --- |
2529
| [groundingAttributions](./ai.groundingmetadata.md#groundingmetadatagroundingattributions) | [GroundingAttribution](./ai.groundingattribution.md#groundingattribution_interface)<!-- -->\[\] | |
30+
| [groundingChunks](./ai.groundingmetadata.md#groundingmetadatagroundingchunks) | [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface)<!-- -->\[\] | A list of [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) objects. Each chunk represents a piece of retrieved content (for example, from a web page). that the model used to ground its response. |
31+
| [groundingSupports](./ai.groundingmetadata.md#groundingmetadatagroundingsupports) | [GroundingSupport](./ai.groundingsupport.md#groundingsupport_interface)<!-- -->\[\] | A list of [GroundingSupport](./ai.groundingsupport.md#groundingsupport_interface) objects. Each object details how specific segments of the model's response are supported by the <code>groundingChunks</code>. |
2632
| [retrievalQueries](./ai.groundingmetadata.md#groundingmetadataretrievalqueries) | string\[\] | |
27-
| [webSearchQueries](./ai.groundingmetadata.md#groundingmetadatawebsearchqueries) | string\[\] | |
33+
| [searchEntryPoint](./ai.groundingmetadata.md#groundingmetadatasearchentrypoint) | [SearchEntrypoint](./ai.searchentrypoint.md#searchentrypoint_interface) | Google Search entry point for web searches. This contains an HTML/CSS snippet that must be embedded in an app to display a Google Search entry point for follow-up web searches related to a model'sGrounded Response”. |
34+
| [webSearchQueries](./ai.groundingmetadata.md#groundingmetadatawebsearchqueries) | string\[\] | A list of web search queries that the model performed to gather the grounding information. These can be used to allow users to explore the search results themselves. |
2835

2936
## GroundingMetadata.groundingAttributions
3037

3138
> Warning: This API is now obsolete.
3239
>
40+
> Use [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) instead.
3341
>
3442

3543
<b>Signature:</b>
@@ -38,16 +46,53 @@ export interface GroundingMetadata
3846
groundingAttributions: GroundingAttribution[];
3947
```
4048

49+
## GroundingMetadata.groundingChunks
50+
51+
A list of [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) objects. Each chunk represents a piece of retrieved content (for example, from a web page). that the model used to ground its response.
52+
53+
<b>Signature:</b>
54+
55+
```typescript
56+
groundingChunks?: GroundingChunk[];
57+
```
58+
59+
## GroundingMetadata.groundingSupports
60+
61+
A list of [GroundingSupport](./ai.groundingsupport.md#groundingsupport_interface) objects. Each object details how specific segments of the model's response are supported by the `groundingChunks`<!-- -->.
62+
63+
<b>Signature:</b>
64+
65+
```typescript
66+
groundingSupports?: GroundingSupport[];
67+
```
68+
4169
## GroundingMetadata.retrievalQueries
4270

71+
> Warning: This API is now obsolete.
72+
>
73+
> Use [GroundingSupport](./ai.groundingsupport.md#groundingsupport_interface) instead.
74+
>
75+
4376
<b>Signature:</b>
4477

4578
```typescript
4679
retrievalQueries?: string[];
4780
```
4881

82+
## GroundingMetadata.searchEntryPoint
83+
84+
Google Search entry point for web searches. This contains an HTML/CSS snippet that must be embedded in an app to display a Google Search entry point for follow-up web searches related to a model'sGrounded Response”.
85+
86+
<b>Signature:</b>
87+
88+
```typescript
89+
searchEntryPoint?: SearchEntrypoint;
90+
```
91+
4992
## GroundingMetadata.webSearchQueries
5093

94+
A list of web search queries that the model performed to gather the grounding information. These can be used to allow users to explore the search results themselves.
95+
5196
<b>Signature:</b>
5297

5398
```typescript

docs-devsite/ai.groundingsupport.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# GroundingSupport interface
13+
Provides information about how a specific segment of the model's response is supported by the retrieved grounding chunks.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface GroundingSupport
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [groundingChunkIndices](./ai.groundingsupport.md#groundingsupportgroundingchunkindices) | number\[\] | A list of indices that refer to specific [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) objects within the [GroundingMetadata.groundingChunks](./ai.groundingmetadata.md#groundingmetadatagroundingchunks) array. These referenced chunks are the sources that support the claim made in the associated <code>segment</code> of the response. For example, an array <code>[1, 3, 4]</code> means that <code>groundingChunks[1]</code>, <code>groundingChunks[3]</code>, and <code>groundingChunks[4]</code> are the retrieved content supporting this part of the response. |
26+
| [segment](./ai.groundingsupport.md#groundingsupportsegment) | [Segment](./ai.segment.md#segment_interface) | Specifies the segment of the model's response content that this grounding support pertains to. |
27+
28+
## GroundingSupport.groundingChunkIndices
29+
30+
A list of indices that refer to specific [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) objects within the [GroundingMetadata.groundingChunks](./ai.groundingmetadata.md#groundingmetadatagroundingchunks) array. These referenced chunks are the sources that support the claim made in the associated `segment` of the response. For example, an array `[1, 3, 4]` means that `groundingChunks[1]`<!-- -->, `groundingChunks[3]`<!-- -->, and `groundingChunks[4]` are the retrieved content supporting this part of the response.
31+
32+
<b>Signature:</b>
33+
34+
```typescript
35+
groundingChunkIndices?: number[];
36+
```
37+
38+
## GroundingSupport.segment
39+
40+
Specifies the segment of the model's response content that this grounding support pertains to.
41+
42+
<b>Signature:</b>
43+
44+
```typescript
45+
segment?: Segment;
46+
```

0 commit comments

Comments
 (0)