Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion discoveryengine/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-discoveryengine==0.13.8
google-cloud-discoveryengine==0.13.11
10 changes: 5 additions & 5 deletions discoveryengine/session_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_session(
discoveryengine.Session: The newly created Session.
"""

client = discoveryengine.ConversationalSearchServiceClient()
client = discoveryengine.SessionServiceClient()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instantiating a new client for each function call is not a recommended practice for production applications. Google Cloud client libraries are designed to have their client instances reused to avoid the overhead of setting up new connections for each request.

While this pattern is acceptable for a self-contained sample where each function is independent, adding a comment to educate users about this best practice would be very helpful.

This feedback also applies to the other functions in this file where a client is instantiated (lines 74, 107, 141, and 181).

Suggested change
client = discoveryengine.SessionServiceClient()
# In real-world applications, a single client instance should be created and reused for better performance.
client = discoveryengine.SessionServiceClient()


session = client.create_session(
# The full resource name of the engine
Expand Down Expand Up @@ -71,7 +71,7 @@ def get_session(
session_id: The ID of the session.
"""

client = discoveryengine.ConversationalSearchServiceClient()
client = discoveryengine.SessionServiceClient()

# The full resource name of the session
name = f"projects/{project_id}/locations/{location}/collections/default_collection/engines/{engine_id}/sessions/{session_id}"
Expand Down Expand Up @@ -104,7 +104,7 @@ def delete_session(
session_id: The ID of the session.
"""

client = discoveryengine.ConversationalSearchServiceClient()
client = discoveryengine.SessionServiceClient()

# The full resource name of the session
name = f"projects/{project_id}/locations/{location}/collections/default_collection/engines/{engine_id}/sessions/{session_id}"
Expand Down Expand Up @@ -138,7 +138,7 @@ def update_session(
Returns:
discoveryengine.Session: The updated Session.
"""
client = discoveryengine.ConversationalSearchServiceClient()
client = discoveryengine.SessionServiceClient()

# The full resource name of the session
name = f"projects/{project_id}/locations/{location}/collections/default_collection/engines/{engine_id}/sessions/{session_id}"
Expand Down Expand Up @@ -178,7 +178,7 @@ def list_sessions(
discoveryengine.ListSessionsResponse: The list of sessions.
"""

client = discoveryengine.ConversationalSearchServiceClient()
client = discoveryengine.SessionServiceClient()

# The full resource name of the engine
parent = f"projects/{project_id}/locations/{location}/collections/default_collection/engines/{engine_id}"
Expand Down