In your web app, you can get answers to your questions in the form of streaming responses. This document shows you how to use the REST API to get answers. If you want to use the Gemini Enterprise web app, see Chat with the assistant.
StreamAssist overview
StreamAssist provides a powerful, interactive way to handle user queries. It operates in a streaming fashion, enabling real-time, back-and-forth interactions.
The key capabilities of the API include the following:
Maintaining conversational context: it uses sessions to maintain conversational context, ensuring it understands follow-up queries within the scope of previous interactions.
Incorporating provided files: it includes the attached files as context for more informed and relevant responses.
Seamless integration: it integrates with various agents and tools to fulfill a wide range of user requests.
Before you begin
Ensure that you have the following:
The Discovery Engine API enabled for your Google Cloud. You can enable it on the Discovery Engine API page in the Google Cloud console.
A Discovery Engine role that has the
discoveryengine.assistants.assistpermission assigned to it.An existing Gemini Enterprise app. To create an app, see Create an app.
Get search results
You can use the streamAssist
method to query and get answers from
Gemini Enterprise. The following curl command lists the mandatory fields.
REST
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://ENDPOINT_LOCATION-discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/collections/default_collection/engines/APP_ID/assistants/default_assistant:streamAssist" \
-d '
{
"query": {
"text": "QUERY_TEXT_1"
}
}'
Replace the following:
- ENDPOINT_LOCATION-: the multi-region for your API request. Assign one of the following
values:
us-for the US multi-regioneu-for the EU multi-regionglobal-for the Global location
- PROJECT_ID: the ID of your Google Cloud project.
- APP_ID: the unique identifier for the Gemini Enterprise app.
- LOCATION: the multi-region of your data store:
global,us, oreu - QUERY_TEXT_1: the search query text.
For more information on the fields and what is returned, see Response body.
Get search results using the same session
To continue a conversation and get answers from Gemini Enterprise within an
existing session, use the
streamAssist method. The following
code sample shows the mandatory fields:
REST
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://ENDPOINT_LOCATION-discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/collections/default_collection/engines/APP_ID/assistants/default_assistant:streamAssist" \
-d '
{
"session": "projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/sessions/SESSION_ID",
"query": {
"text": "QUERY_TEXT_2"
}
}'
Replace the following:
- ENDPOINT_LOCATION-: the multi-region for your API request. Assign one of the following
values:
us-for the US multi-regioneu-for the EU multi-regionglobal-for the Global location
- PROJECT_ID: the ID of your Google Cloud project.
- APP_ID: the unique identifier for the Gemini Enterprise app.
- LOCATION: the multi-region of your data store:
global,us, oreu - QUERY_TEXT_2: the search query text.
- SESSION_ID: the ID of a session from a previous conversation or query.
For more information on the fields and what is returned, see Response body.