I chunked the data and the metadata along with it. when retriving i need to show a key in the metadatas as response.
def ask_question(store_name, question):
print("\\n Asking Gemini...")
try:
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=question,
config=types.GenerateContentConfig(
tools=\[
types.Tool(
file_search=types.FileSearch(
file_search_store_names=\[store_name\]
)
)
\]
)
)
\# --------------------------
\# Print answer text
\# --------------------------
print("\\n Answer:\\n")
try:
print(response.text)
except:
print(" No answer text returned.")
\# --------------------------
\# Extract metadata of matched chunks
\# --------------------------
print("\\n Matched Metadata:\\n")
refs = None # ensure variable is defined
try:
gm = response.candidates\[0\].grounding_metadata
refs = gm.search_entry_point.retrieved_references
except:
print("⚠ No retrieved references.")
return
if not refs:
print("⚠ No retrieved references.")
return
\# DEBUG: print retrieved files
print("Retrieved files:")
for ref in refs:
title = getattr(ref.chunk, "title", "(no title)")
print(" •", title)
print()
except Exception as e:
print(f" Query error: {e}")
This do not seems to do the needful.