Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-common): Grounding with Google Search and Vertex AI Search #7280

Merged
merged 13 commits into from
Dec 14, 2024

Conversation

renathossain
Copy link
Contributor

We’ve implemented grounding with Google Search and Vertex AI Search. To use this feature, simply call .bindTools([searchRetrievalTool]) on the model and pass in the appropriate searchRetrievalTool object, as defined in the Google Cloud documentation on grounding, depending on the type of grounding you want to use.

Here are the implementation details:

  • We’ve added the necessary googleSearchRetrieval and retrieval parameters to GeminiTool.
  • convertToGeminiTools and formatTools previously supported only one tool type (functionDeclarations), but we’ve refactored them to handle these two new tools.
  • The structuredToolsToGeminiTools function has been removed; its logic is now consolidated within formatTools.

We've also added test cases and documentation changes.

Twitter handle: @renathossain

Fixes #5073

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 27, 2024
Copy link

vercel bot commented Nov 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Dec 14, 2024 5:49am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Dec 14, 2024 5:49am

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, and sorry for the delayed review!

See one comment but looks fine otherwise

tools.forEach((tool) => {
if (
"functionDeclarations" in tool &&
Array.isArray(tool.functionDeclarations)
) {
const funcs: GeminiFunctionDeclaration[] = tool.functionDeclarations;
geminiTools[0].functionDeclarations?.push(...funcs);
geminiTools.push({ functionDeclarations: [...funcs] });
Copy link
Collaborator

@jacoblee93 jacoblee93 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely remember this not working due to Google rejecting it - can you add a test using multiple traditional tools? And maybe one using search grounding alongside several tools as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @afirstenberg and @jacoblee93,

Thank you for the review! We’re glad to hear that you appreciate our code contribution. We’ll make sure to add the additional test cases as requested. Please note that libs/langchain-google-vertexai/src/tests/chat_models.int.test.ts already includes test cases for grounding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are some known bugs on Google's side about having multiple tools at once - but Google considers this a bug on their end. It should be possible to submit multiple tools at once and mixing functions and other tools.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this breaks multiple functions, will revert partially

@jacoblee93
Copy link
Collaborator

CC @afirstenberg for a peek as well!

@jacoblee93 jacoblee93 added question Further information is requested close PRs that need one or two touch-ups to be ready labels Dec 10, 2024
@@ -309,6 +309,8 @@ export interface GeminiContent {

export interface GeminiTool {
functionDeclarations?: GeminiFunctionDeclaration[];
googleSearchRetrieval?: object;
retrieval?: object;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have like to see these as actual types or classes rather than as object, but I don't think this should hold off on merging.

@afirstenberg
Copy link
Contributor

Generally looks good and I'm sorry I missed this two weeks ago.

I do suggest making actual types for the possible attributes for GeminiTool, but I don't think that should hold up a merge.

LGTM

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much!

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Dec 14, 2024
@jacoblee93 jacoblee93 changed the title google-common [Feature]: Grounding with Google Search and Vertex AI Search feat(google-common): Grounding with Google Search and Vertex AI Search Dec 14, 2024
@jacoblee93 jacoblee93 removed question Further information is requested close PRs that need one or two touch-ups to be ready labels Dec 14, 2024
@jacoblee93
Copy link
Collaborator

jacoblee93 commented Dec 14, 2024

Google has changed the field name for Gemini 2.0, fixing now

It's not supported yet from the look of it

@jacoblee93 jacoblee93 merged commit 84da383 into langchain-ai:main Dec 14, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases lgtm PRs that are ready to be merged as-is size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google-common [Feature]: Grounding with Google Search and Vertex AI Search
4 participants