本指南介绍了如何使用用户生成的嵌入执行 AI 驱动的搜索,而不是依赖第三方工具。

要求

  • 一个 Meilisearch 项目

配置自定义嵌入器

配置 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"]
  }'
© . This site is unofficial and not affiliated with Meilisearch.