Skip to content

Commit 8543716

Browse files
authored
Search grounding (#271)
* Add preliminary search grouding change without unittest. * Add support for stream generating content * Generate doc and change set. * Resolve comment
1 parent a6cf83f commit 8543716

File tree

53 files changed

+1175
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1175
-9
lines changed

.changeset/dirty-shrimps-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@google/generative-ai": minor
3+
---
4+
5+
Add search grounding feature to SDK.

.changeset/shy-panthers-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@google/generative-ai": minor
3+
---
4+
5+
Add support for search grounding

common/api-review/generative-ai-server.api.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,10 @@ export interface TextPart {
471471
text: string;
472472
}
473473

474+
// Warning: (ae-forgotten-export) The symbol "GoogleSearchRetrievalTool" needs to be exported by the entry point index.d.ts
475+
//
474476
// @public
475-
export type Tool = FunctionDeclarationsTool | CodeExecutionTool;
477+
export type Tool = FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool;
476478

477479
// @public
478480
export interface ToolConfig {

common/api-review/generative-ai.api.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ export interface CountTokensResponse {
155155
totalTokens: number;
156156
}
157157

158+
// @public
159+
export interface DynamicRetrievalConfig {
160+
dynamicThreshold?: number;
161+
mode?: DynamicRetrievalMode;
162+
}
163+
164+
// @public
165+
export enum DynamicRetrievalMode {
166+
// (undocumented)
167+
MODE_DYNAMIC = "MODE_DYNAMIC",
168+
// (undocumented)
169+
MODE_UNSPECIFIED = "MODE_UNSPECIFIED"
170+
}
171+
158172
// @public
159173
export interface EmbedContentRequest {
160174
// (undocumented)
@@ -378,6 +392,7 @@ export interface GenerateContentCandidate {
378392
finishMessage?: string;
379393
// (undocumented)
380394
finishReason?: FinishReason;
395+
groundingMetadata?: GroundingMetadata;
381396
// (undocumented)
382397
index: number;
383398
logprobsResult?: LogprobsResult;
@@ -517,6 +532,51 @@ export class GoogleGenerativeAIResponseError<T> extends GoogleGenerativeAIError
517532
response?: T;
518533
}
519534

535+
// @public
536+
export interface GoogleSearchRetrieval {
537+
dynamicRetrievalConfig?: DynamicRetrievalConfig;
538+
}
539+
540+
// @public
541+
export interface GoogleSearchRetrievalTool {
542+
googleSearchRetrieval?: GoogleSearchRetrieval;
543+
}
544+
545+
// @public
546+
export interface GroundingChunk {
547+
web?: GroundingChunkWeb;
548+
}
549+
550+
// @public
551+
export interface GroundingChunkWeb {
552+
title?: string;
553+
uri?: string;
554+
}
555+
556+
// @public
557+
export interface GroundingMetadata {
558+
groundingChuncks?: GroundingChunk[];
559+
groundingSupport?: GroundingSupport[];
560+
retrievalMetadata?: RetrievalMetadata;
561+
searchEntryPoint?: SearchEntryPoint;
562+
webSearchQueries: string[];
563+
}
564+
565+
// @public
566+
export interface GroundingSupport {
567+
confidenceScores?: number[];
568+
groundingChunckIndices?: number[];
569+
segment?: string;
570+
}
571+
572+
// @public
573+
export interface GroundingSupportSegment {
574+
endIndex?: number;
575+
partIndex?: number;
576+
startIndex?: number;
577+
text?: string;
578+
}
579+
520580
// @public
521581
export enum HarmBlockThreshold {
522582
// (undocumented)
@@ -641,6 +701,11 @@ export interface RequestOptions {
641701
export interface ResponseSchema extends Schema {
642702
}
643703

704+
// @public
705+
export interface RetrievalMetadata {
706+
googleSearchDynamicRetrievalScore?: number;
707+
}
708+
644709
// @public
645710
export interface SafetyRating {
646711
// (undocumented)
@@ -682,6 +747,12 @@ export enum SchemaType {
682747
STRING = "string"
683748
}
684749

750+
// @public
751+
export interface SearchEntryPoint {
752+
renderedContent?: string;
753+
sdkBlob?: string;
754+
}
755+
685756
// @public
686757
export interface SingleRequestOptions extends RequestOptions {
687758
signal?: AbortSignal;
@@ -735,7 +806,7 @@ export interface TextPart {
735806
}
736807

737808
// @public
738-
export type Tool = FunctionDeclarationsTool | CodeExecutionTool;
809+
export type Tool = FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool;
739810

740811
// @public
741812
export interface ToolConfig {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [DynamicRetrievalConfig](./generative-ai.dynamicretrievalconfig.md) &gt; [dynamicThreshold](./generative-ai.dynamicretrievalconfig.dynamicthreshold.md)
4+
5+
## DynamicRetrievalConfig.dynamicThreshold property
6+
7+
The threshold to be used in dynamic retrieval. If not set, a system default value is used.
8+
9+
**Signature:**
10+
11+
```typescript
12+
dynamicThreshold?: number;
13+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [DynamicRetrievalConfig](./generative-ai.dynamicretrievalconfig.md)
4+
5+
## DynamicRetrievalConfig interface
6+
7+
Specifies the dynamic retrieval configuration for the given source.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare interface DynamicRetrievalConfig
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [dynamicThreshold?](./generative-ai.dynamicretrievalconfig.dynamicthreshold.md) | | number | _(Optional)_ The threshold to be used in dynamic retrieval. If not set, a system default value is used. |
20+
| [mode?](./generative-ai.dynamicretrievalconfig.mode.md) | | [DynamicRetrievalMode](./generative-ai.dynamicretrievalmode.md) | _(Optional)_ The mode of the predictor to be used in dynamic retrieval. |
21+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [DynamicRetrievalConfig](./generative-ai.dynamicretrievalconfig.md) &gt; [mode](./generative-ai.dynamicretrievalconfig.mode.md)
4+
5+
## DynamicRetrievalConfig.mode property
6+
7+
The mode of the predictor to be used in dynamic retrieval.
8+
9+
**Signature:**
10+
11+
```typescript
12+
mode?: DynamicRetrievalMode;
13+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [DynamicRetrievalMode](./generative-ai.dynamicretrievalmode.md)
4+
5+
## DynamicRetrievalMode enum
6+
7+
The mode of the predictor to be used in dynamic retrieval.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare enum DynamicRetrievalMode
13+
```
14+
15+
## Enumeration Members
16+
17+
| Member | Value | Description |
18+
| --- | --- | --- |
19+
| MODE\_DYNAMIC | <code>&quot;MODE_DYNAMIC&quot;</code> | |
20+
| MODE\_UNSPECIFIED | <code>&quot;MODE_UNSPECIFIED&quot;</code> | |
21+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GenerateContentCandidate](./generative-ai.generatecontentcandidate.md) &gt; [groundingMetadata](./generative-ai.generatecontentcandidate.groundingmetadata.md)
4+
5+
## GenerateContentCandidate.groundingMetadata property
6+
7+
Search grounding metadata.
8+
9+
**Signature:**
10+
11+
```typescript
12+
groundingMetadata?: GroundingMetadata;
13+
```

docs/reference/main/generative-ai.generatecontentcandidate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface GenerateContentCandidate
2121
| [content](./generative-ai.generatecontentcandidate.content.md) | | [Content](./generative-ai.content.md) | |
2222
| [finishMessage?](./generative-ai.generatecontentcandidate.finishmessage.md) | | string | _(Optional)_ |
2323
| [finishReason?](./generative-ai.generatecontentcandidate.finishreason.md) | | [FinishReason](./generative-ai.finishreason.md) | _(Optional)_ |
24+
| [groundingMetadata?](./generative-ai.generatecontentcandidate.groundingmetadata.md) | | [GroundingMetadata](./generative-ai.groundingmetadata.md) | _(Optional)_ Search grounding metadata. |
2425
| [index](./generative-ai.generatecontentcandidate.index.md) | | number | |
2526
| [logprobsResult?](./generative-ai.generatecontentcandidate.logprobsresult.md) | | [LogprobsResult](./generative-ai.logprobsresult.md) | _(Optional)_ Log-likelihood scores for the response tokens and top tokens. |
2627
| [safetyRatings?](./generative-ai.generatecontentcandidate.safetyratings.md) | | [SafetyRating](./generative-ai.safetyrating.md)<!-- -->\[\] | _(Optional)_ |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GoogleSearchRetrieval](./generative-ai.googlesearchretrieval.md) &gt; [dynamicRetrievalConfig](./generative-ai.googlesearchretrieval.dynamicretrievalconfig.md)
4+
5+
## GoogleSearchRetrieval.dynamicRetrievalConfig property
6+
7+
Specifies the dynamic retrieval configuration for the given source.
8+
9+
**Signature:**
10+
11+
```typescript
12+
dynamicRetrievalConfig?: DynamicRetrievalConfig;
13+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GoogleSearchRetrieval](./generative-ai.googlesearchretrieval.md)
4+
5+
## GoogleSearchRetrieval interface
6+
7+
Retrieval tool that is powered by Google search.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare interface GoogleSearchRetrieval
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [dynamicRetrievalConfig?](./generative-ai.googlesearchretrieval.dynamicretrievalconfig.md) | | [DynamicRetrievalConfig](./generative-ai.dynamicretrievalconfig.md) | _(Optional)_ Specifies the dynamic retrieval configuration for the given source. |
20+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GoogleSearchRetrievalTool](./generative-ai.googlesearchretrievaltool.md) &gt; [googleSearchRetrieval](./generative-ai.googlesearchretrievaltool.googlesearchretrieval.md)
4+
5+
## GoogleSearchRetrievalTool.googleSearchRetrieval property
6+
7+
Google search retrieval tool config.
8+
9+
**Signature:**
10+
11+
```typescript
12+
googleSearchRetrieval?: GoogleSearchRetrieval;
13+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GoogleSearchRetrievalTool](./generative-ai.googlesearchretrievaltool.md)
4+
5+
## GoogleSearchRetrievalTool interface
6+
7+
Retrieval tool that is powered by Google search.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare interface GoogleSearchRetrievalTool
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [googleSearchRetrieval?](./generative-ai.googlesearchretrievaltool.googlesearchretrieval.md) | | [GoogleSearchRetrieval](./generative-ai.googlesearchretrieval.md) | _(Optional)_ Google search retrieval tool config. |
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GroundingChunk](./generative-ai.groundingchunk.md)
4+
5+
## GroundingChunk interface
6+
7+
Grounding chunk.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare interface GroundingChunk
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [web?](./generative-ai.groundingchunk.web.md) | | [GroundingChunkWeb](./generative-ai.groundingchunkweb.md) | _(Optional)_ Chunk from the web. |
20+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GroundingChunk](./generative-ai.groundingchunk.md) &gt; [web](./generative-ai.groundingchunk.web.md)
4+
5+
## GroundingChunk.web property
6+
7+
Chunk from the web.
8+
9+
**Signature:**
10+
11+
```typescript
12+
web?: GroundingChunkWeb;
13+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GroundingChunkWeb](./generative-ai.groundingchunkweb.md)
4+
5+
## GroundingChunkWeb interface
6+
7+
Chunk from the web.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare interface GroundingChunkWeb
13+
```
14+
15+
## Properties
16+
17+
| Property | Modifiers | Type | Description |
18+
| --- | --- | --- | --- |
19+
| [title?](./generative-ai.groundingchunkweb.title.md) | | string | _(Optional)_ Title of the chunk. |
20+
| [uri?](./generative-ai.groundingchunkweb.uri.md) | | string | _(Optional)_ URI reference of the chunk. |
21+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GroundingChunkWeb](./generative-ai.groundingchunkweb.md) &gt; [title](./generative-ai.groundingchunkweb.title.md)
4+
5+
## GroundingChunkWeb.title property
6+
7+
Title of the chunk.
8+
9+
**Signature:**
10+
11+
```typescript
12+
title?: string;
13+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [GroundingChunkWeb](./generative-ai.groundingchunkweb.md) &gt; [uri](./generative-ai.groundingchunkweb.uri.md)
4+
5+
## GroundingChunkWeb.uri property
6+
7+
URI reference of the chunk.
8+
9+
**Signature:**
10+
11+
```typescript
12+
uri?: string;
13+
```

0 commit comments

Comments
 (0)