Thank you for the follow-up. Here’s a brief recap and code snippets.
Issue recap:
When querying a File Search store, grounding_chunks in grounding_metadata don’t include title or uri (or fileUri) even though files are uploaded with display_name set to the original filename. This prevents identifying which file each chunk came from.
Environment:
Code snippets:
1. Upload to store (setting display_name):
static async uploadToStore(
storeId: string,
filePath: string,
displayName?: string
): Promise {
// Use provided displayName (original filename) or fallback
const fileName = displayName || filePath.split(/[/\]/).pop() || ‘document.pdf’;
const fileData = fs.readFileSync(filePath);
let fileObj: File | Readable;
if (typeof File !== ‘undefined’) {
fileObj = new File([fileData], fileName, { type: ‘application/pdf’ });
} else {
fileObj = Readable.from(fileData);
}
// Set display_name explicitly - this is critical for title/uri to appear in chunks
const operation = await genAI.fileSearchStores.uploadToFileSearchStore({
fileSearchStoreName: storeId,
file: fileObj,
display_name: fileName, // snake_case format
} as any);
// … polling operation status …
return fileId;
}
2. Query with File Search tool (parsing grounding_chunks):
static async queryGuidelines(
storeId: string,
query: string
): Promise {
// Generate content with File Search tool
const result = await genAI.models.generateContent({
model: ‘gemini-2.5-flash’,
contents: query,
config: {
systemInstruction: systemInstruction,
tools: [{
fileSearch: {
fileSearchStoreNames: [storeId],
},
}],
},
} as any);
const response = (result as any).response || result;
const candidate = response.candidates?.[0];
const groundingMetadata = candidate?.groundingMetadata as any;
const groundingChunks = groundingMetadata?.groundingChunks ||
groundingMetadata?.groundingChuncks || ;
// Extract citations from grounding chunks
const citations = groundingChunks.map((chunk: any) => {
const retrievedContext = chunk.retrievedContext || {};
const text = retrievedContext.text || chunk.text || ‘’;
// Try multiple locations for file identifier - none are populated
const fileUri = retrievedContext.fileUri ||
retrievedContext.title ||
retrievedContext.uri ||
chunk.fileUri ||
chunk.uri ||
chunk.title ||
null; // Always null in practice
const pageNumber = chunk.pageNumber ||
retrievedContext.pageNumber ||
chunk.metadata?.pageNumber ||
null;
return {
retrievedContext: {
text: text,
fileUri: fileUri, // Always null/undefined
pageNumber: pageNumber,
},
};
});
return {
text: response.text || /* extract from candidates */,
citations,
};
}
What we observe:
-
display_name is set during upload
-
grounding_chunks contain retrievedContext.text and pageNumber
-
retrievedContext.uri, retrievedContext.title, retrievedContext.fileUri, chunk.uri, chunk.title, etc. are missing
-
Only retrievedContext.fileSearchStore (store ID) is present, not individual file identifiers
Question:
Is this a known limitation, or is there a way to get the original filename (display_name) in the chunk metadata? If it’s a limitation, are there plans to add this?
Thanks for your help.