MongoDB Search 또는 MongoDB Vector Search 쿼리 에서 반환된 모든 문서 에는 관련성에 따라 점수가 할당되며, 결과 설정하다 에 포함된 문서는 가장 높은 점수부터 가장 낮은 점수 순으로 반환됩니다.
사용법
To include the score of each document in your search results, use the $project stage in your aggregation pipeline.
For the
$vectorSearchstage, thescorefield takes the$metaexpression, which requires thevectorSearchScorevalue to return the score of each document in your vector search results.
참고
다음 기능도 있습니다.
searchScore$search쿼리에서만 사용 가능vectorSearchScoreonly in$vectorSearchqueries
다른 쿼리에서 searchScore 및 vectorSearchScore를 사용하는 경우, MongoDB는 v8.2부터 경고를 로그합니다.
예시
The following query uses a $project stage to add a field named score to the returned documents:
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 <operator-specification> 6 } 7 } 8 }, 9 { 10 "$project": { 11 "<field-to-include>": 1, 12 "<field-to-exclude>": 0, 13 "score": { "$meta": "searchScore" } 14 } 15 } 16 ])
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 <operator-specification> 6 }, 7 "scoreDetails": true 8 } 9 }, 10 { 11 "$project": { 12 "<field-to-include>": 1, 13 "<field-to-exclude>": 0, 14 "scoreDetails": { "$meta": "searchScoreDetails" } 15 } 16 } 17 ])
자세한 내용은 점수 상세 정보 반환을 참조하세요.
1 db.movies.aggregate([ 2 { 3 "$vectorSearch": { 4 <query-syntax> 5 } 6 }, 7 { 8 "$project": { 9 "<field-to-include>": 1, 10 "<field-to-exclude>": 0, 11 "score": { "$meta": "vectorSearchScore" } 12 } 13 } 14 ])
To learn more, see MongoDB Vector Search Scoring.
행동
The score assigned to a returned document is part of the document's metadata. You can use a $project stage in your aggregation pipeline to include each returned document's score along with the result set. Documents return from highest score to lowest. Many factors can influence a document's score, including the following:
문서에서 검색어의 위치입니다.
문서에서 검색어의 발생 빈도입니다.
루센 점수 알고리즘 에 대해 자세히 학습하려면 루센 문서를 참조하세요.
추가 옵션
기본값 채점 동작 외에도 MongoDB Search는 다음 옵션을 지원합니다.
고려 사항
결과의 여러 문서에 동일한 점수가 있는 경우 결과의 문서 순서는 비결정적입니다. MongoDB Search 결과가 정해진 순서를 갖도록 하려면 단계에 $search 정렬 옵션을 포함하여 고유한 필드 기준으로 결과를 정렬합니다. 정렬 옵션을 사용하여 결과를 점수별로 오름차순으로 정렬하여 반환할 수도 있습니다. 자세히 학습 MongoDB 검색 결과 정렬 및 점수별 정렬 예시를 참조하세요.
On separate Search Nodes, each node assigns documents different internal Lucene IDs used for sorting when scores are identical. When sorting and paginating results, the mongot process on the node that is processing the query might include documents from other nodes if their internal IDs have greater pagination order than the token. To prevent this, use $match after $search to exclude documents by their _id.
배열 값을 쿼리할 때 MongoDB Search는 배열 에서 쿼리 와 일치하는 값이 더 많을수록 더 높은 점수를 할당합니다.