使用 Cohere 嵌入的語義搜尋

    簡介

    本指南將引導您設定 Meilisearch 與 Cohere 嵌入,以啟用語義搜尋功能。透過利用 Meilisearch 的 AI 功能和 Cohere 的嵌入 API,您可以增強搜尋體驗並檢索更相關的結果。

    需求

    要遵循本指南,您需要:

    設定 Meilisearch

    若要在 Meilisearch 中設定嵌入器,您需要針對您的設定進行配置。您可以參考Meilisearch 文件,以取得關於更新嵌入器設定的更多詳細資訊。

    Cohere 提供多種嵌入模型

    以下是 Cohere 的嵌入器設定範例

    {
      "cohere": {
        "source": "rest",
        "apiKey": "<Cohere API Key>",
        "dimensions": 1024,
        "documentTemplate": "<Custom template (Optional, but recommended)>",
        "url": "https://api.cohere.com/v1/embed",
        "request": {
          "model": "embed-english-v3.0",
          "texts": [
            "{{text}}",
            "{{..}}"
          ],
          "input_type": "search_document"
        },
        "response": {
          "embeddings": [
            "{{embedding}}",
            "{{..}}"
          ]
        },
      }
    }
    

    在此設定中

    一旦您設定好嵌入器設定,Meilisearch 將會自動為您的文件產生嵌入,並將其儲存在向量儲存中。

    請注意,大多數第三方工具都有速率限制,這由 Meilisearch 管理。如果您有免費帳戶,索引過程可能需要一些時間,但 Meilisearch 會使用重試策略來處理它。

    建議監控任務佇列,以確保一切順利執行。您可以使用 Cloud UI 或Meilisearch API 來存取任務佇列。

    完成嵌入器設定後,您現在可以使用 Meilisearch 執行語意搜尋。當您發送搜尋查詢時,Meilisearch 會使用已設定的嵌入器為查詢產生嵌入向量,然後使用它在向量儲存中找到語意上最相似的文件。若要執行語意搜尋,您只需要發出正常的搜尋請求,但要包含 hybrid 參數。

    {
      "q": "<Query made by the user>",
      "hybrid": {
        "semanticRatio": 1,
        "embedder": "cohere"
      }
    }
    

    在此請求中:

    您可以使用 Meilisearch API 或用戶端函式庫來執行搜尋,並根據語意相似性檢索相關文件。

    結論

    遵循本指南,您現在應該已設定好 Meilisearch 和 Cohere 嵌入功能,讓您可以在應用程式中利用語意搜尋功能。Meilisearch 的自動批次處理和高效的嵌入向量處理能力,使其成為將語意搜尋整合到專案中的強大選擇。

    若要探索嵌入器的更多設定選項,請參閱關於嵌入器設定可能性的詳細文件