Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions js/plugins/google-genai/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ export function isGoogleSearchRetrievalTool(
);
}

/**
* The FileSearch tool that retrieves knowledge from Semantic Retrieval corpora.
* Files are imported to Semantic Retrieval corpora using the ImportFile API
*/
export declare interface FileSearchTool {
fileSearch: FileSearch;
}

export declare interface FileSearch {
/**
* The names of the fileSearchStores to retrieve from.
* Example: fileSearchStores/my-file-search-store-123
*/
fileSearchStoreNames: string[];
/**
* Metadata filter to apply to the semantic retrieval documents and chunks.
*/
metadataFilter?: string;
/**
* The number of semantic retrieval chunks to retrieve.
*/
topK?: number;
}
export function isFileSearchTool(tool: Tool): tool is FileSearchTool {
return (tool as FileSearchTool).fileSearch !== undefined;
}

/**
* Grounding support.
*/
Expand Down Expand Up @@ -905,6 +932,7 @@ export declare type Tool =
| RetrievalTool // Vertex AI Only
| GoogleMapsTool // Vertex AI Only
| CodeExecutionTool // Google AI Only
| FileSearchTool // Google AI Only
| GoogleSearchRetrievalTool;

/**
Expand Down
28 changes: 28 additions & 0 deletions js/plugins/google-genai/src/googleai/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
'Retrieve public web data for grounding, powered by Google Search.'
)
.optional(),
fileSearch: z
.object({
fileSearchStoreNames: z
.array(z.string())
.describe(
'The names of the fileSearchStores to retrieve from. ' +
'Example: fileSearchStores/my-file-search-store-123'
),
metadataFilter: z
.string()
.optional()
.describe(
'Metadata filter to apply to the semantic retrieval documents and chunks.'
),
topK: z
.number()
.optional()
.describe('The number of semantic retrieval chunks to retrieve.'),
})
.passthrough()
.optional(),
temperature: z
.number()
.min(0)
Expand Down Expand Up @@ -539,6 +560,7 @@ export function defineModel(
version: versionFromConfig,
functionCallingConfig,
googleSearchRetrieval,
fileSearch,
tools: toolsFromConfig,
...restOfConfigOptions
} = requestOptions;
Expand All @@ -561,6 +583,12 @@ export function defineModel(
} as GoogleSearchRetrievalTool);
}

if (fileSearch) {
tools.push({
fileSearch,
});
}

let toolConfig: ToolConfig | undefined;
if (functionCallingConfig) {
toolConfig = {
Expand Down
10 changes: 9 additions & 1 deletion js/plugins/google-genai/tests/googleai/gemini_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ describe('Google AI Gemini', () => {
config: {
codeExecution: true,
googleSearchRetrieval: {},
fileSearch: {
fileSearchStoreNames: ['foo'],
},
},
};
await model.run(request);
Expand All @@ -279,11 +282,16 @@ describe('Google AI Gemini', () => {
fetchStub.lastCall.args[1].body
);
assert.ok(Array.isArray(apiRequest.tools));
assert.strictEqual(apiRequest.tools?.length, 3);
assert.strictEqual(apiRequest.tools?.length, 4);
assert.deepStrictEqual(apiRequest.tools?.[1], { codeExecution: {} });
assert.deepStrictEqual(apiRequest.tools?.[2], {
googleSearch: {},
});
assert.deepStrictEqual(apiRequest.tools?.[3], {
fileSearch: {
fileSearchStoreNames: ['foo'],
},
});
});

it('uses baseUrl and apiVersion from call config', async () => {
Expand Down
Loading