相似文件 實驗性
/similar
路徑使用 AI 驅動的搜尋,以回傳與目標文件相似的多個文件。
Meilisearch 公開了兩個用於檢索相似文件的路徑:POST
和 GET
。在大多數情況下,POST
將提供更好的效能和易用性。
啟用 `/similar`
這是一個實驗性功能。要使用它,您必須首先啟用並配置 AI 驅動的搜尋。
使用 POST
取得相似文件
POST/indexes/{index_uid}/similar
檢索與特定搜尋結果相似的文件。
路徑參數
名稱 | 類型 | 描述 |
---|---|---|
index_uid * | 字串 | 請求的索引的uid |
請求主體
參數 | 類型 | 預設值 | 描述 |
---|---|---|---|
id | 字串或數字 | null | 目標文件的識別碼 (必要) |
embedder | 字串 | "default" | 計算推薦時要使用的 Embedder。必要 |
attributesToRetrieve | 字串陣列 | ["*"] | 要在回傳的文件中顯示的屬性 |
offset | 整數 | 0 | 要跳過的文件數量 |
limit | 整數 | 20 | 回傳的最大文件數量 |
filter | 字串 | null | 依屬性的值篩選查詢 |
showRankingScore | 布林值 | false | 顯示文件的整體排名分數 |
showRankingScoreDetails | 布林值 | false | 顯示詳細的排名分數資訊 |
rankingScoreThreshold | 數字 | null | 排除排名分數較低的結果 |
retrieveVectors | 布林值 | false | 回傳文件向量資料 |
範例
curl \
-X POST 'https://127.0.0.1:7700/indexes/INDEX_NAME/similar' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer DEFAULT_SEARCH_API_KEY' \
--data-binary '{
"id": TARGET_DOCUMENT_ID,
"embedder": "EMBEDDER_NAME"
}'
回應:200 OK
{
"hits": [
{
"id": "299537",
"title": "Captain Marvel"
},
{
"id": "166428",
"title": "How to Train Your Dragon: The Hidden World"
}
{
"id": "287947",
"title": "Shazam!"
}
],
"id": "23",
"processingTimeMs": 0,
"limit": 20,
"offset": 0,
"estimatedTotalHits": 3
}
使用 GET
取得相似文件
GET/indexes/{index_uid}/similar
檢索與特定搜尋結果相似的文件。
路徑參數
名稱 | 類型 | 描述 |
---|---|---|
index_uid * | 字串 | 請求的索引的uid |
查詢參數
參數 | 類型 | 預設值 | 描述 |
---|---|---|---|
id | 字串或數字 | null | 目標文件的識別碼 (必要) |
embedder | 字串 | "default" | 計算推薦時要使用的 Embedder。必要 |
attributesToRetrieve | 字串陣列 | ["*"] | 要在回傳的文件中顯示的屬性 |
offset | 整數 | 0 | 要跳過的文件數量 |
limit | 整數 | 20 | 回傳的最大文件數量 |
filter | 字串 | null | 依屬性的值篩選查詢 |
showRankingScore | 布林值 | false | 顯示文件的整體排名分數 |
showRankingScoreDetails | 布林值 | false | 顯示詳細的排名分數資訊 |
rankingScoreThreshold | 數字 | null | 排除排名分數較低的結果 |
retrieveVectors | 布林值 | false | 回傳文件向量資料 |
範例
curl \
-X GET 'https://127.0.0.1:7700/indexes/INDEX_NAME/similar?id=TARGET_DOCUMENT_ID&embedder=EMBEDDER_NAME'
回應:200 OK
{
"hits": [
{
"id": "299537",
"title": "Captain Marvel"
},
{
"id": "166428",
"title": "How to Train Your Dragon: The Hidden World"
}
{
"id": "287947",
"title": "Shazam!"
}
],
"id": "23",
"processingTimeMs": 0,
"limit": 20,
"offset": 0,
"estimatedTotalHits": 3
}