建立搜尋應用程式

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

建立應用程式

控制台

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

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

    AI 應用程式

  2. 在「應用程式」頁面中,按一下「建立應用程式」

  3. 在「建立應用程式」頁面,點選「運用 AI 模式打造站內搜尋服務」下方的「建立」

  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)

  9. 按一下「繼續」

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

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

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

REST

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

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

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

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

      前往「Data Stores」頁面

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

    3. 在資料儲存庫的「資料」頁面中,取得資料儲存庫 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:要建立的 Vertex AI Search 應用程式 ID。
    • APP_DISPLAY_NAME:要建立的 Vertex AI Search 應用程式顯示名稱。
    • :現有 Vertex AI Search 資料儲存庫的 ID,您要將該資料儲存庫新增至 Vertex AI Search 應用程式。DATA_STORE_ID
    • SEARCH_TIER:搜尋層級可以是 SEARCH_TIER_STANDARDSEARCH_TIER_ENTERPRISESEARCH_TIER_ENTERPRISE,才能使用網站搜尋和選擇應用程式區域等功能。Enterprise 版功能會產生額外費用。詳情請參閱「Enterprise 版功能」。
    • SEARCH_ADD_ON:如要為這個應用程式提供進階大型語言模型功能生成的內容,請指定 SEARCH_ADD_ON_LLM。生成式回覆包括搜尋摘要含後續查詢的搜尋

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

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

Python

詳情請參閱 Vertex AI Search Python API 參考文件

如要向 Vertex AI 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

後續步驟