使用 AI 驱动的搜索与用户提供的嵌入

    本指南展示了如何使用用户生成的嵌入执行 AI 驱动的搜索,而无需依赖第三方工具。

    要求

    配置自定义嵌入器

    配置 embedder 索引设置,将其源设置为 userProvided

    curl \
      -X PATCH 'MEILISEARCH_URL/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"]
      }'