Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Creating auto-session for VertexAI search/answer endpoints

Hi,

I am trying to create an "auto-session" id and get it back in the search/answer endpoints response so that I can pass it back in the subsequent request but I am unable to create one and keep running into 404 error. From the documentation, under the field "session",  (https://cloud.google.com/generative-ai-app-builder/docs/reference/rest/v1/projects.locations.dataSto...), I see we need to add "/sessions" in the url but it does not seem to work regardless of where I put it. For example, I see a successful response coming back when I hit the below endpoint (Marked project name and dataStore names with ** as they are internal information)

https://discoveryengine.googleapis.com/v1alpha/projects/**/locations/global/collections/default_coll...

 

But when I add "/sessions in the url, it does not work like the below -

https://discoveryengine.googleapis.com/v1alpha/projects/**/sessions/locations/global/collections/def...

 

Any thoughts?

 

Solved Solved
0 2 430
1 ACCEPTED SOLUTION

Hi @Ravi9,

Welcome to Google Cloud Community!

While the concept of appending sessions to the endpoint URL is a common practice in some APIs, it appears the Discovery Engine API handles session management differently.

Be guided that there is a dedicated endpoint for creating sessions. Here's the corrected information:

Creating Sessions

POST /v1alpha/{parent=projects/*/locations/*/collections/*/dataStores/*}/sessions

 

  • Request Body:

The request body should include a sessionId field for the session. If you don't provide one, the API will generate a unique ID for you.

 

  • Example Request Body:
{
  "sessionId": "my-custom-session-id"
}

 

  • Response:

The response will include the created session in the body, containing the session ID.

Using Sessions in Search Requests

 

 

  • Endpoint:

POST /v1alpha/{parent=projects/*/locations/*/collections/*/dataStores/*/servingConfigs/*}:search

 

  • Request Body:

Within the search request body, you'll include a "session" field with the session ID you want to use.

 

 

  • Example Request Body:
{
  "servingConfig": "projects/*/locations/global/collections/default_collection/dataStores/*/servingConfigs/default_search",
  "session": {
    "sessionId": "your-generated-session-id" 
  },
  "query": "blue jeans",
  "pageSize": 10 
}

Key Points:

  • You must create a session before using it in search requests.
  • When using an existing session, make sure to use the correct session ID in the search request.
  • POST Request: To create a new session, you'll need to use a POST request to this endpoint.
  • Session ID: The response to your POST request will include the newly created session ID, which you can then use in subsequent requests to maintain session context.

Additional Notes:

  • Ensure you are using the correct authorization credentials to access the Discovery Engine API and IAM permissions to create sessions.
  • Consult the official Discovery Engine API documentation for more details on creating sessions and working with session-based search/answer requests.

By following these steps and ensuring the correct endpoint structure, you should be able to create sessions and retrieve session IDs for your Vertex AI search/answer endpoints.

I hope the above information is helpful.

 

 

View solution in original post

2 REPLIES 2

Hi @Ravi9,

Welcome to Google Cloud Community!

While the concept of appending sessions to the endpoint URL is a common practice in some APIs, it appears the Discovery Engine API handles session management differently.

Be guided that there is a dedicated endpoint for creating sessions. Here's the corrected information:

Creating Sessions

POST /v1alpha/{parent=projects/*/locations/*/collections/*/dataStores/*}/sessions

 

  • Request Body:

The request body should include a sessionId field for the session. If you don't provide one, the API will generate a unique ID for you.

 

  • Example Request Body:
{
  "sessionId": "my-custom-session-id"
}

 

  • Response:

The response will include the created session in the body, containing the session ID.

Using Sessions in Search Requests

 

 

  • Endpoint:

POST /v1alpha/{parent=projects/*/locations/*/collections/*/dataStores/*/servingConfigs/*}:search

 

  • Request Body:

Within the search request body, you'll include a "session" field with the session ID you want to use.

 

 

  • Example Request Body:
{
  "servingConfig": "projects/*/locations/global/collections/default_collection/dataStores/*/servingConfigs/default_search",
  "session": {
    "sessionId": "your-generated-session-id" 
  },
  "query": "blue jeans",
  "pageSize": 10 
}

Key Points:

  • You must create a session before using it in search requests.
  • When using an existing session, make sure to use the correct session ID in the search request.
  • POST Request: To create a new session, you'll need to use a POST request to this endpoint.
  • Session ID: The response to your POST request will include the newly created session ID, which you can then use in subsequent requests to maintain session context.

Additional Notes:

  • Ensure you are using the correct authorization credentials to access the Discovery Engine API and IAM permissions to create sessions.
  • Consult the official Discovery Engine API documentation for more details on creating sessions and working with session-based search/answer requests.

By following these steps and ensuring the correct endpoint structure, you should be able to create sessions and retrieve session IDs for your Vertex AI search/answer endpoints.

I hope the above information is helpful.

 

 

Thank you @ruthseki