Hi @blackdiamond,
Welcome to Google Cloud Community!
Gemini doesn’t have a direct “Reference ID” parameter within its batch prompt request structure. Gemini’s BatchPrompt API focuses on processing multiple prompts efficiently. It doesn’t inherently have a mechanism to track individual requests with a custom ID. The API primarily returns an array of responses corresponding to the order of your prompts.
With regard to your proposal which is embedding request IDs in the prompt, this is a viable approach.
If you include a unique identifier (like a UUID or a custom ID) within the text part of the prompt, the generated output will inherently contain that ID, providing a reliable way to link back to the original request. It’s relatively straightforward to implement this on the request creation side. You can include other metadata in the text part too, although it might impact the model’s processing.
On the other side, injecting IDs into prompts can potentially affect the model’s output. While likely minor, it might slightly influence the text generation if not handled correctly. You’ll need to parse the output text to extract the injected ID, adding a processing step after getting the responses. This assumes that the language model will retain the ID in output. You’ll need to consider the impact of added characters on prompt length limits. If the model changes or we want to change model later then there can be a breaking change in the prompt parsing.
Here are other approaches that you may consider to try:
1. File Naming Conventions:
If your input media is stored in a location where you control file naming, you can encode request ID info there. For example, if your input files are in Cloud Storage, you can name the file something like request-id-123_image.jpg. With this, it can keep the prompt clean and avoids introducing noise. However, it may require an infrastructure change if your files are not already named with IDs. You’ll need to parse filenames in your output.
2. Database/Lookup Table:
Before making the batch requests, create a lookup table (e.g., in a database, data store) that maps a sequential ID to the actual request payload. Use these sequential IDs in the prompt. You then use the ID to query the lookup table for original requests. The advantage of this is that it is robust and allows storing additional metadata besides just request contents. On the other hand, it may require an additional database or datastore and adds overhead.
3. Post-Processing with Error Handling:
Relying on the original order while making sure to implement robust error handling and tracking. It is the simplest method in terms of not adding additional logic. However, it can be error prone, partial failures will skew output and can be tricky to debug.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.