Registry / gcp / google-cloud-discoveryengine

google-cloud-discoveryengine

JSON →
library0.20.2pypypi✓ verified 23d ago

The Google Cloud Discovery Engine API client library provides Python access to Google Cloud's AI-powered search and recommendations service. It enables developers to build rich, personalized search and browse experiences across various data sources, including websites, structured data, and media. The current version is 0.18.0, and it follows Google Cloud's frequent release cadence, often tied to API updates.

pip install google-cloud-discoveryengine
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-DISCO
G
google-cloud-discoveryengine
gcppythonv0.20.2
Install
7.2s avg
Import
2575ms
Disk
112MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 3.350s · 111.2MB
glibc
py 3.103.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)
Debug
Known issues
gotchaResource names often require the Google Cloud project *number* instead of the project *ID*. Ensure you retrieve and use the numeric project ID when constructing resource paths like `projects/{project_number}/locations/{location}/dataStores/{data_store_id}`.
fix
Use `gcloud projects describe <PROJECT_ID> --format='value(projectNumber)'` to get the project number, or ensure your environment variable provides the number.
affects: All versions
gotchaThe `google-cloud-discoveryengine` library currently primarily exposes the `discoveryengine_v1beta` module. Direct imports from `google.cloud.discoveryengine` might lack access to the latest APIs or features, leading to `AttributeError` or missing functionalities.
fix
Always import specific client modules using the version suffix, e.g., `from google.cloud import discoveryengine_v1beta as discoveryengine`.
affects: 0.1.0 - 0.18.0
gotchaAuthentication is crucial. Without proper Google Cloud credentials (e.g., via `gcloud auth application-default login`, `GOOGLE_APPLICATION_CREDENTIALS` environment variable, or service account key), API calls will fail with permission errors.
fix
Ensure your environment is correctly authenticated for Google Cloud APIs. Grant the service account the 'Discovery Engine User' role for basic operations.
affects: All versions
gotchaDiscovery Engine's search and recommendation features rely on 'Serving Configs'. If you don't specify a valid `serving_config` in your search or recommendation requests, operations will fail or return incomplete results.
fix
Verify your Data Store has a 'default_config' or provide the full resource name of a custom serving config, e.g., `projects/{project_number}/locations/{location}/dataStores/{data_store_id}/servingConfigs/default_config`.
affects: All versions
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.
Agent activity
54 hits · last 30 days
node
44
OpenAI (training)
1
Resources
google-cloud-discoveryengine — pip install google-cloud-discoveryengine · libregistry