گوگل مجموعه گستردهای از مدلها و APIهای هوش مصنوعی پیشرو در صنعت را برای استنتاج مبتنی بر ابر و روی دستگاه ارائه میدهد. استنتاج ترکیبی به شما امکان میدهد تا به طور یکپارچه حجم کار هوش مصنوعی را بین دستگاه محلی و ابر متعادل کنید و عملکرد، هزینه و در دسترس بودن را بهینه کنید.
Hybrid inference provides two primary advantages for your Android app:
- حداکثر دسترسی : مدلهای ابری به عنوان یک جایگزین حیاتی عمل میکنند، زمانی که مدلهای روی دستگاه، مانند Gemini Nano، به دلیل محدودیتهای سختافزاری دستگاه یا سیستمعامل در دسترس نیستند. این امر به تضمین عملکرد صحیح ویژگیهای هوش مصنوعی شما در طیف وسیعی از دستگاههای کاربر کمک میکند.
- هزینه و قابلیتهای آفلاین : مدلهای روی دستگاه به شما اطمینان میدهند که ویژگیهای هوش مصنوعی شما حتی زمانی که کاربر آفلاین است، به طور یکپارچه کار میکنند. علاوه بر این، انتقال وظایف روتین به دستگاه محلی به کاهش هزینههای استنتاج ابری کمک میکند.

گزینههای پیادهسازی
You can implement hybrid inference using the following approaches:
رابط برنامهنویسی ترکیبی فایربیس هوش مصنوعی و منطق
The Firebase AI Logic Hybrid API provides a single, unified interface for splitting inference between cloud and on-device environments.
It includes a onDeviceConfig parameter providing simple controls to define the inference mode and manage the routing:
-
PREFER_ON_DEVICE: attempt to use the on-device model, automatically falling back to the cloud-hosted model if the on-device model is unavailable or unsupported for the request. -
PREFER_IN_CLOUD: attempts to use the cloud-hosted model when the device is online and the model is available, falling back to the on-device model only if the device is offline. -
ONLY_ON_DEVICE: attempts to use the on-device model, but throws an exception if it is unavailable or unsupported for the request. -
ONLY_IN_CLOUD: attempts to use the cloud-hosted model when the device is online and the model is available, throwing an exception in all other cases.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-2.5-flash",
onDeviceConfig = OnDeviceConfig(mode = InferenceMode.PREFER_ON_DEVICE)
)
val response = model.generateContent("Write a story about a green robot.")
print(response.text)
For implementation details, review the Firebase documentation and explore the Hybrid AI sample in the AI catalog .
مسیریابی سفارشی
If your app has specific business or UX requirements, you can also implement custom routing logic. This lets you dynamically determine the inference path based on real-time factors, such as:
- تأخیر شبکه
- Device system health (for example battery levels and processor load)
- پیچیدگی پرس و جوی کاربر
This custom hybrid inference approach is used by leading apps that implemented their own custom routing to deliver reliable AI experiences, including:
GBoard : Gboard uses custom hybrid inference to power the writing tools such as proofread and rewrite.
کاکائو موبیلیتی : کاکائو موبیلیتی با استفاده از استنتاج ترکیبی سفارشی، ابزاری برای استخراج موجودیتها برای سرویس تحویل بسته خود ساخته است که به طور خودکار نام، آدرس و شماره تلفن گیرنده را از پیامهای زبان طبیعی استخراج میکند تا فرمهای سفارش را سادهسازی کند.