Bug: metadataFilter on File Search breaks retrieval entirely
Environment
- SDK: @google/genai (raw SDK, no AI SDK middleware)
- Model: gemini-2.5-pro (also tested with gemini-3-flash-preview)
- Runtime: Bun / Node.js
Setup
- Single fileSearchStore with 20 PDF documents
- Each document has customMetadata: [{ key: “partySigla”, stringValue: “” }]
- Store and metadata confirmed working via ai.fileSearchStores.documents.list()
Reproduction
- Without metadataFilter → works (2000+ chars, grounding metadata present):
const response = await ai.models.generateContent({
model: "gemini-2.5-pro",
contents: "¿Qué propone el PLN sobre educación?",
config: {
tools: [{
fileSearch: {
fileSearchStoreNames: [storeName],
},
}],
},
});
// ✅ 2303 chars, groundingMetadata with chunks from other parties
// ❌ BUT: PLN document is never retrieved despite being in the store
With metadataFilter → completely broken (empty response, no grounding):
const response = await ai.models.generateContent({
model: "gemini-2.5-pro",
contents: "¿Qué propone el PLN sobre educación?",
config: {
tools: [{
fileSearch: {
fileSearchStoreNames: [storeName],
metadataFilter: 'partySigla = "PLN"',
},
}],
},
});
// ❌ 188 chars: "I couldn't find information about PLN"
// ❌ groundingMetadata: undefined (zero grounding chunks)
Observed behavior
metadataFilterkills retrieval entirely — zero grounding chunks, model says it can’t find anything- Even without the filter, certain documents are never retrieved despite being confirmed present in the store with correct metadata
- Tested on a freshly created store (deleted and re-uploaded all 20 documents) — same result
Expected behavior
metadataFilter should filter the retrieval to matching documents, not return zero results
All indexed documents should be retrievable by the file search tool