-
Notifications
You must be signed in to change notification settings - Fork 297
fix(genai): extract and include metadata #941
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
fix(genai): extract and include metadata #941
Conversation
✅ Example Codefrom google.ai.generativelanguage_v1beta.types import Tool as GenAITool
from langchain_google_genai import ChatGoogleGenerativeAI
# Define the LLM with Gemini 2.5 Flash preview model
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash-preview-04-17")
# Invoke the LLM with Google Search Tool enabled
resp = llm.invoke(
"When is the next total solar eclipse in US?",
tools=[GenAITool(google_search={})],
)
print(resp) 🔎 Before My ChangeThe model returned a response without grounded sources :
🚀 After My ChangeAfter enabling the
|
@SYED-M-HUSSAIN please resolve lint and conflicts |
@SYED-M-HUSSAIN do you have any insight into why the original |
needed to still add to `generation_info`
floating point precision
addressed some regressions. note the floating point rounding being done - not sure why this was failing; I suspect issues on Google's end |
PR Description
This pull request fixes an issue where grounding metadata from the Google search tool responses was not preserved. It ensures that fields such as
grounding_supports
,grounding_chunks
, andweb_search_queries
are extracted and included inresponse_metadata
, enabling citation tracking and improved traceability in search-augmented responses.Relevant issues
Fixes #907
Type
🐛 Bug Fix
Changes (optional)
_extract_grounding_metadata()
helper function to safely extract grounding data._response_to_result()
to includegrounding_supports
,grounding_chunks
, andweb_search_queries
inresponse_metadata
.Testing (optional)
Note (optional)
This fix improves the reliability of citations and source tracking in responses using Google search, supporting downstream systems relying on structured grounding metadata.