使用使用者提供的嵌入向量進行 AI 驅動的搜尋 實驗性

    本指南說明如何使用使用者產生的嵌入向量執行 AI 驅動的搜尋,而不是依賴第三方工具。

    需求

    設定自訂嵌入器

    設定 embedder 索引設定,將其來源設定為 userProvided

    curl \
      -X PATCH 'https://127.0.0.1:7700/indexes/movies/settings' \
      -H 'Content-Type: application/json' \
      --data-binary '{
        "embedders": {
          "image2text": {
            "source":  "userProvided",
            "dimensions": 3
          }
        }
      }'
    

    將文件新增至 Meilisearch

    接下來,使用 /documents 端點來上傳向量化的文件。將向量資料放置在文件的 _vectors 欄位中

    curl -X POST -H 'content-type: application/json' \
    'localhost:7700/indexes/products/documents' \
    --data-binary '[
        { "id": 0, "_vectors": {"image2text": [0, 0.8, -0.2]}, "text": "frying pan" },
        { "id": 1, "_vectors": {"image2text": [1, -0.2, 0]}, "text": "baking dish" }
    ]'
    

    使用使用者提供的嵌入向量進行向量搜尋

    使用自訂嵌入器時,您必須向量化文件和使用者查詢。

    取得查詢的向量後,將其傳遞至 vector 搜尋參數,以執行 AI 驅動的搜尋

    curl -X POST -H 'content-type: application/json' \
      'localhost:7700/indexes/products/search' \
      --data-binary '{ "vector": [0, 1, 2] }'
    

    vector 必須是一個數字陣列,指示搜尋向量。在使用使用者提供的嵌入向量進行向量搜尋時,您必須自行產生這些向量。

    vector 可以與其他搜尋參數一起使用,包括filtersort

    curl -X POST -H 'content-type: application/json' \
      'localhost:7700/indexes/products/search' \
      --data-binary '{
        "vector": [0, 1, 2],
        "filter": "price < 10",
        "sort": ["price:asc"]
      }'