Stop Using One Prompt for Every Photo! Local Image Classification Before Calling Firebase AI Logic GenerativeModel A developer built a client-side image classification step that runs before calling Firebase AI Logic's GenerativeModel, using the @mediapipe/tasks-decision library and the EmbeddingGemma 2 LiteRT model to sort uploads into people, general, or place categories. The classifier caches the model in the browser's CacheStorage, pulls its path from Firebase Remote Config, and routes each category to a matching prompt and model configuration so Gemini generates category-appropriate alt text. The approach replaces a single generic prompt with per-category prompts and schemas. I upload images of places, wrestlers, and general objects to the application. When uploading images of people, I want the Gemini model to generate alt text about their appearance, posture, and attire. When uploading images of places, I want the Gemini model to generate alt text with their official names, coordinates, and locations. To support this, I installed the @mediapipe/tasks-decision library, which uses the EmbeddingGemma 2 model embeddinggemma-2-text-vision-440m-litert-lm to classify the category of a picture people , general , or place . The category decides which Firebase AI Logic GenerativeModel and prompt generate the text response. ImageClassifierService checks the browser's CacheStorage decision-model-v1 for the EmbeddingGemma 2 model, downloads and caches it via HttpClient on a cache miss, and uses DecisionMaker with the provided choices to determine the image's category people , general , or place . AiModelOptions optional systemInstruction , response schema , and tools from CATEGORY MODEL CONFIGS . GenerativeModel Lookup & Content Generation VisionService passes options to AiModelFactory.getModel options to reuse or create the matching Firebase AI Logic generateContent prompt, imagePart with the category's prompt to generate the text response. php flowchart TD IMG "Selected Image File " -- PREP "preprocessImageForVision - imageBytes + base64" PREP -- CLS "ImageClassifierService.classifyImage imageBytes " CLS -- CACHE CHK{"Local model in CacheStorage?"} CACHE CHK -- "Miss" -- DL "HttpClient GET - cache.put - Blob URL" CACHE CHK -- "Hit" -- BLOB "cache.match - Blob URL" DL & BLOB -- DM "DecisionMaker.evaluateChoice imageBytes, IMAGE CATEGORY QUESTION " DM -- CAT{"Best Category"} CAT -- "people" -- CFG P "CATEGORY MODEL CONFIGS 'people' " CAT -- "general" -- CFG G "CATEGORY MODEL CONFIGS 'general' " CAT -- "place" -- CFG L "CATEGORY MODEL CONFIGS 'place' " CFG P & CFG G & CFG L -- FAC "AiModelFactory.getModel options " FAC -- GEN "aiModel.generateContent prompt, imagePart " @mediapipe/tasks-decision , Serving WASM Assets, and Adding decisionModelPath to Remote Config I installed the latest @mediapipe/tasks-decision package 1.2.3 , which provides the API to evaluate the category of an image input. npm install @mediapipe/tasks-decision angular.json The decision tasks require loading the WASM files at runtime. Instead of pointing to the WASM files on a CDN, I used the files installed in node modules/@mediapipe/tasks-decision/wasm . Since the service cannot load files directly from node modules in the browser, I configured angular.json to copy node modules/@mediapipe/tasks-decision/wasm to /wasm WASM PATH = '/wasm' so the application can access them. // angular.json projects.ng-firebase-tts.architect.build.options.assets { "glob": " / ", "input": "node modules/@mediapipe/tasks-decision/wasm", "output": "/wasm" } I added the decisionModelPath parameter to Firebase Remote Config and public/remote-config-defaults.json , defaulting to https://huggingface.co/litert-community/embeddinggemma-2-text-vision-440m-litert-lm/resolve/main/embeddinggemma-2-text-vision-440m.litertlm for on-device image classification. I also added the decisionModelPath property to AppRemoteConfig , which ConfigService updates when fetching the model path dynamically from Firebase Remote Config. // public/remote-config-defaults.json { "decisionModelPath": "https://huggingface.co/litert-community/embeddinggemma-2-text-vision-440m-litert-lm/resolve/main/embeddinggemma-2-text-vision-440m.litertlm", ... } // src/app/core/firebase/config.service.ts decisionModelPath in appConfig & fetchRemoteConfig appConfig: AppRemoteConfig = { ... decisionModelPath: remoteConfigDefaults.decisionModelPath, }; ... this. appConfig = { ... decisionModelPath: getValue rc, 'decisionModelPath' .asString , }; ImageClassifierService encapsulates the image-classification logic that VisionService uses in step one of the image-analysis pipeline: cachedModelPath decisionMakerPromise Promise