{"id":2050,"library":"google-cloud-discoveryengine","title":"Google Cloud Discovery Engine","description":"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.","status":"active","version":"0.18.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-discoveryengine","tags":["google-cloud","discoveryengine","search","recommendations","ai","gen-ai","cloud-api"],"install":[{"cmd":"pip install google-cloud-discoveryengine","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core Google Cloud API utilities and infrastructure.","package":"google-api-core","optional":false},{"reason":"Provides Pythonic wrappers for protobuf messages.","package":"proto-plus","optional":false},{"reason":"Utilities for parsing and manipulating dates.","package":"python-dateutil","optional":false}],"imports":[{"note":"The API is currently in v1beta; ensure you import from discoveryengine_v1beta for the most current features and classes. Direct import from `discoveryengine` might point to an older or empty module.","wrong":"from google.cloud import discoveryengine","symbol":"SearchServiceClient","correct":"from google.cloud import discoveryengine_v1beta as discoveryengine\nclient = discoveryengine.SearchServiceClient()"},{"symbol":"CompletionServiceClient","correct":"from google.cloud import discoveryengine_v1beta as discoveryengine\nclient = discoveryengine.CompletionServiceClient()"},{"symbol":"RecommendationServiceClient","correct":"from google.cloud import discoveryengine_v1beta as discoveryengine\nclient = discoveryengine.RecommendationServiceClient()"},{"symbol":"UserEventServiceClient","correct":"from google.cloud import discoveryengine_v1beta as discoveryengine\nclient = discoveryengine.UserEventServiceClient()"}],"quickstart":{"code":"import os\nfrom google.cloud import discoveryengine_v1beta as discoveryengine\n\ndef search_discovery_engine(\n    project_id: str,\n    location_id: str,\n    data_store_id: str,\n    query: str,\n):\n    # Construct the parent resource name for the serving config.\n    # Format: projects/{project_number}/locations/{location}/dataStores/{data_store_id}\n    # Note: Discovery Engine often expects project *number*, not project *ID*.\n    parent = (\n        f\"projects/{project_id}/locations/{location_id}/dataStores/{data_store_id}\"\n    )\n\n    client = discoveryengine.SearchServiceClient()\n\n    # The request body for a search operation.\n    request = discoveryengine.SearchRequest(\n        serving_config=(\n            f\"{parent}/servingConfigs/default_config\" # Or a custom serving config\n        ),\n        query=query,\n        query_expansion_spec=discoveryengine.QueryExpansionSpec(\n            condition=discoveryengine.QueryExpansionSpec.Condition.AUTO\n        ),\n        page_size=5 # Limit to 5 results for brevity\n    )\n\n    response = client.search(request=request)\n\n    print(f\"\\nSearch results for query: '{query}'\")\n    if not response.results:\n        print(\"No results found.\")\n        return\n\n    for result in response.results:\n        print(f\"-\" * 20)\n        print(f\"Document ID: {result.document.id}\")\n        if result.document.derived_struct:\n            # Derived_struct contains parsed content like title, link, snippets.\n            title = result.document.derived_struct.get('title')\n            link = result.document.derived_struct.get('link')\n            snippet = result.document.derived_struct.get('snippets')\n            print(f\"Title: {title if title else 'N/A'}\")\n            print(f\"Link: {link if link else 'N/A'}\")\n            if snippet:\n                print(f\"Snippet: {snippet[0].get('snippet')}\")\n\n# Example usage:\nif __name__ == \"__main__\":\n    # Replace with your actual Google Cloud Project Number, Location, and Data Store ID.\n    # Ensure your service account has 'Discovery Engine User' role.\n    project_number = os.environ.get(\"GCP_PROJECT_NUMBER\", \"YOUR_PROJECT_NUMBER\")\n    location = os.environ.get(\"GCP_LOCATION\", \"global\") # e.g., 'global', 'us-central1'\n    data_store_id = os.environ.get(\"DISCOVERY_ENGINE_DATA_STORE_ID\", \"YOUR_DATA_STORE_ID\")\n    search_query = \"Google Cloud AI solutions\"\n\n    if \"YOUR_PROJECT_NUMBER\" in project_number or \"YOUR_DATA_STORE_ID\" in data_store_id:\n        print(\"Please set GCP_PROJECT_NUMBER, GCP_LOCATION, and DISCOVERY_ENGINE_DATA_STORE_ID environment variables \")\n        print(\"or replace the placeholder values in the quickstart code to run it.\")\n    else:\n        search_discovery_engine(project_number, location, data_store_id, search_query)\n","lang":"python","description":"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."},"warnings":[{"fix":"Use `gcloud projects describe <PROJECT_ID> --format='value(projectNumber)'` to get the project number, or ensure your environment variable provides the number.","message":"Resource 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}`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always import specific client modules using the version suffix, e.g., `from google.cloud import discoveryengine_v1beta as discoveryengine`.","message":"The `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.","severity":"gotcha","affected_versions":"0.1.0 - 0.18.0"},{"fix":"Ensure your environment is correctly authenticated for Google Cloud APIs. Grant the service account the 'Discovery Engine User' role for basic operations.","message":"Authentication 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"Discovery 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}