建立搜尋應用程式

本頁說明如何建立搜尋應用程式。

建立應用程式

控制台

如要使用 Google Cloud 控制台建立搜尋應用程式,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「AI Applications」頁面。

    AI 應用程式

  2. 在「應用程式」頁面,點選「 建立應用程式」。

  3. 在「Create app」(建立應用程式) 頁面,點選「Site search with AI mode」(運用 AI 模式打造站內搜尋服務) 下方的「Create」(建立)。

  4. 決定是否要為這個應用程式啟用 Enterprise 功能,然後按一下切換鈕開啟或關閉。如要使用網站搜尋和選擇應用程式區域等功能,必須啟用 Enterprise 版功能。Enterprise 版功能會產生額外費用。詳情請參閱「Enterprise 版功能」。

  5. 決定是否要為這個應用程式啟用生成式回覆和進階 LLM 功能,然後按一下切換鈕。您必須啟用「生成式回覆」選項,才能使用搜尋摘要或含後續查詢的搜尋等功能。詳情請參閱「生成式回覆」。

  6. 在「Your app name」欄位輸入內容。

  7. 在「External name of your company or organization」(貴公司或貴組織的外部名稱) 欄位中,輸入公司或組織的通用名稱。避免使用 Inc 或 LLC 等後置詞。 這個欄位可協助 LLM 識別應用程式代表的公司。

  8. 選取應用程式的位置。必須啟用企業功能,才能挑選位置。除非您有理由將資料限制在特定地理區域,否則 Google 建議您使用預設的「global (Global)」(全域)。

  9. 按一下「繼續」。

  10. 如要連結至資料儲存庫,請在「Data stores」(資料儲存庫) 頁面中,選取先前建立的資料儲存庫,或建立新的資料儲存庫。

    您可以選擇下列其中一個選項:

    • 選取現有的資料儲存庫:如果只附加一個資料儲存庫,之後就無法移除,也無法在應用程式中新增其他資料儲存庫。附加多個資料儲存庫後,您日後可以更新附加的資料儲存庫,但應用程式一律至少需要兩個資料儲存庫。
    • 建立新的資料儲存庫,並將資料擷取至其中:
      1. 按一下「 Create data store」(建立資料儲存庫),然後按照「Create a new data store」(建立新的資料儲存庫) 頁面中的步驟操作。
      2. 選擇新的資料儲存庫,然後點選「選取」。詳情請參閱「建立搜尋資料儲存庫」。

REST

使用指令列建立應用程式前,必須先有資料儲存庫。如果沒有資料儲存庫,請按照「建立資料儲存庫並擷取 Agent Search 資料」中的步驟建立。

如要使用 engines.create 方法,透過指令列建立搜尋應用程式,請按照下列步驟操作:

  1. 找出資料儲存庫 ID。如果您已有資料儲存庫 ID,請跳到下一個步驟。

    1. 前往 Google Cloud 控制台的「AI Applications」頁面,然後點選導覽選單中的「Data Stores」(資料儲存庫)。

      前往「Data Stores」(資料儲存庫) 頁面

    2. 點按資料儲存庫的名稱。

    3. 在資料儲存庫的「Data」(資料) 頁面,取得資料儲存庫 ID。

  2. 建立搜尋應用程式並連結至資料儲存庫。資料儲存庫只能連結至一個應用程式,且之後無法從應用程式中移除。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines?engineId=APP_ID" \
    -d '{
      "displayName": "APP_DISPLAY_NAME",
      "dataStoreIds": ["DATA_STORE_ID"],
      "solutionType": "SOLUTION_TYPE_SEARCH",
      "industryVertical": "GENERIC",
      "searchEngineConfig": {
         "searchTier": "SEARCH_TIER",
         "searchAddOns": ["SEARCH_ADD_ON"]
       }
    }'
    

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案的 ID。
    • APP_ID:要建立的 Agent Search 應用程式 ID。
    • APP_DISPLAY_NAME:要建立的 Agent Search 應用程式顯示名稱。
    • DATA_STORE_ID:要新增至 Agent Search 應用程式的現有 Agent Search 資料儲存庫 ID。
    • SEARCH_TIER:搜尋層級可以是 SEARCH_TIER_STANDARD 或 SEARCH_TIER_ENTERPRISE。必須啟用SEARCH_TIER_ENTERPRISE,才能使用網站搜尋等功能,以及為應用程式選擇區域。Enterprise 版功能會產生額外費用。詳情請參閱「Enterprise 版本功能」。
    • SEARCH_ADD_ON:如要為這個應用程式啟用生成式回覆和進階 LLM 功能,請指定 SEARCH_ADD_ON_LLM。生成式回覆包括搜尋摘要和後續查詢。

      如果不想使用生成式回覆,請將 SEARCH_ADD_ON_UNSPECIFIED 指定為搜尋外掛程式,或移除 searchAddOns 欄位。

      詳情請參閱「生成式回覆」。

Python

詳情請參閱 Agent Search Python API 參考文件。

如要向 Agent Search 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

from typing import List

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine_v1 as discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# engine_id = "YOUR_ENGINE_ID"
# data_store_ids = ["YOUR_DATA_STORE_ID"]


def create_engine_sample(
    project_id: str, location: str, engine_id: str, data_store_ids: List[str]
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.EngineServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    engine = discoveryengine.Engine(
        display_name="Test Engine",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_type=discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH,
        # For search apps only
        search_engine_config=discoveryengine.Engine.SearchEngineConfig(
            # Options: SEARCH_TIER_STANDARD, SEARCH_TIER_ENTERPRISE
            search_tier=discoveryengine.SearchTier.SEARCH_TIER_ENTERPRISE,
            # Options: SEARCH_ADD_ON_LLM, SEARCH_ADD_ON_UNSPECIFIED
            search_add_ons=[discoveryengine.SearchAddOn.SEARCH_ADD_ON_LLM],
        ),
        # For generic recommendation apps only
        # similar_documents_config=discoveryengine.Engine.SimilarDocumentsEngineConfig,
        data_store_ids=data_store_ids,
    )

    request = discoveryengine.CreateEngineRequest(
        parent=parent,
        engine=engine,
        engine_id=engine_id,
    )

    # Make the request
    operation = client.create_engine(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateEngineMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

Terraform

如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。詳情請參閱 Terraform 供應商參考文件。

如要使用 Terraform 建立搜尋應用程式,請參閱 discovery_engine_search_engine。

後續步驟