Registry /
gcp / google-cloud-discoveryengine
Install & Compatibility
Where this runs
tested against v0.20.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 3.350s · 111.2MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 7.2s · import 1.800s · 109MB
112MB installed
● package 112MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SearchServiceClient
✓ from google.cloud.discoveryengine_v1beta import SearchServiceClient
✗ from google.cloud import discoveryengine_v1beta as discoveryengine
This quickstart demonstrates how to perform a basic search query using the Discovery Engine SearchServiceClient. It shows how to construct a request with a serving config and iterate through the search results. Remember to set up proper authentication and replace placeholder values with your specific Google Cloud project details. Discovery Engine often requires the project *number* instead of the project *ID* for resource paths.
import os
from google.cloud import discoveryengine_v1beta as discoveryengine
def search_discovery_engine(
project_id: str,
location_id: str,
data_store_id: str,
query: str,
):
# Construct the parent resource name for the serving config.
# Format: projects/{project_number}/locations/{location}/dataStores/{data_store_id}
# Note: Discovery Engine often expects project *number*, not project *ID*.
parent = (
f"projects/{project_id}/locations/{location_id}/dataStores/{data_store_id}"
)
client = discoveryengine.SearchServiceClient()
# The request body for a search operation.
request = discoveryengine.SearchRequest(
serving_config=(
f"{parent}/servingConfigs/default_config" # Or a custom serving config
),
query=query,
query_expansion_spec=discoveryengine.QueryExpansionSpec(
condition=discoveryengine.QueryExpansionSpec.Condition.AUTO
),
page_size=5 # Limit to 5 results for brevity
)
response = client.search(request=request)
print(f"\nSearch results for query: '{query}'")
if not response.results:
print("No results found.")
return
for result in response.results:
print(f"-" * 20)
print(f"Document ID: {result.document.id}")
if result.document.derived_struct:
# Derived_struct contains parsed content like title, link, snippets.
title = result.document.derived_struct.get('title')
link = result.document.derived_struct.get('link')
snippet = result.document.derived_struct.get('snippets')
print(f"Title: {title if title else 'N/A'}")
print(f"Link: {link if link else 'N/A'}")
if snippet:
print(f"Snippet: {snippet[0].get('snippet')}")
# Example usage:
if __name__ == "__main__":
# Replace with your actual Google Cloud Project Number, Location, and Data Store ID.
# Ensure your service account has 'Discovery Engine User' role.
project_number = os.environ.get("GCP_PROJECT_NUMBER", "YOUR_PROJECT_NUMBER")
location = os.environ.get("GCP_LOCATION", "global") # e.g., 'global', 'us-central1'
data_store_id = os.environ.get("DISCOVERY_ENGINE_DATA_STORE_ID", "YOUR_DATA_STORE_ID")
search_query = "Google Cloud AI solutions"
if "YOUR_PROJECT_NUMBER" in project_number or "YOUR_DATA_STORE_ID" in data_store_id:
print("Please set GCP_PROJECT_NUMBER, GCP_LOCATION, and DISCOVERY_ENGINE_DATA_STORE_ID environment variables ")
print("or replace the placeholder values in the quickstart code to run it.")
else:
search_discovery_engine(project_number, location, data_store_id, search_query)
Upgrade
Version history
0.20.2latest on PyPI · released Jul 16, 2026
Audit
Dependencies
google-api-corerequiredCore Google Cloud API utilities and infrastructure.
proto-plusrequiredProvides Pythonic wrappers for protobuf messages.
python-dateutilrequiredUtilities for parsing and manipulating dates.