AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

점수 수정

모든 운영자가 사용할 수 있는 점수 수정 옵션은 다음과 같습니다. 자세한 내용과 예시를 보려면 다음 옵션 중 하나를 클릭하세요.

boost 옵션은 결과의 기본 점수에 지정된 숫자 또는 문서의 숫자 필드 값을 곱합니다. 예를 들어, boost를 사용하면 결과에서 일치하는 특정 문서의 중요도를 높일 수 있습니다.

참고

  • boost 및 constant 옵션을 함께 사용할 수 없습니다.

  • The boost option with path is the same as multiplying using the function option with a path expression.

boost 옵션은 다음 필드를 사용합니다.

필드
유형
필요성
설명

value

float

조건부

기본 점수에 곱할 숫자입니다. 값은 양수여야 합니다. value와 path 중 하나는 필수이지만 둘 다 지정할 수는 없습니다.

path

문자열

조건부

기본 점수에 곱할 값의 숫자 필드 이름입니다. path와 value 중 하나는 필수이지만 둘 다 지정할 수는 없습니다.

undefined

float

옵션

path를 통해 지정된 숫자 필드가 문서에 없는 경우 path를 대체할 숫자 값입니다. 생략하면 기본값은 0입니다. path을 지정하는 경우에만 이 값을 지정할 수 있습니다.

The following examples use the movies collection in the sample_mflix database. If you have the sample dataset on your cluster, you can create the MongoDB Search default index and run the example queries on your cluster.

샘플 복합 쿼리는 한 검색 기준의 중요도를 다른 검색 기준보다 높이는 방법을 보여줍니다. 쿼리에는 title 및 score 이외의 모든 필드를 제외하는 $project 단계가 포함되어 있습니다.

다음 예시에서는 복합 연산자가 텍스트 연산자를 사용하여 plot 및 title 필드에서 Helsinki 라는 용어를 검색합니다. title 필드에 대한 쿼리는 boost 옵션과 함께 score 을 사용하여 value 필드에 지정된 대로 점수 결과에 3을 곱합니다.

1db.movies.aggregate([
2 {
3 "$search": {
4 "compound": {
5 "should": [{
6 "text": {
7 "query": "Helsinki",
8 "path": "plot"
9 }
10 },
11 {
12 "text": {
13 "query": "Helsinki",
14 "path": "title",
15 "score": { "boost": { "value": 3 } }
16 }
17 }]
18 }
19 }
20 },
21 {
22 "$limit": 5
23 },
24 {
25 "$project": {
26 "_id": 0,
27 "title": 1,
28 "plot": 1,
29 "score": { "$meta": "searchScore" }
30 }
31 }
32])

이 쿼리는 쿼리 용어와 일치하는 title 문서의 점수에 기본 값에서 3을(를) 곱한 다음 결과를 반환합니다.

[
{
plot: 'Epic tale about two generations of men in a wealthy Finnish family, spanning from the 1960s all the way through the early 1990s. The father has achieved his position as director of the ...',
title: 'Kites Over Helsinki',
score: 12.2470121383667
},
{
plot: 'Alex is Finlander married to an Italian who works as a taxi driver in Berlin. One night in his taxi come two men with a briefcase full of money. Unluckily for Alex, they are being chased by...',
title: 'Helsinki-Naples All Night Long',
score: 9.56808090209961
},
{
plot: 'The recession hits a couple in Helsinki.',
title: 'Drifting Clouds',
score: 4.5660295486450195
},
{
plot: 'Two teenagers from Helsinki are sent on a mission by their drug dealer.',
title: 'Sairaan kaunis maailma',
score: 4.041563034057617
},
{
plot: 'A murderer tries to leave his criminal past in East Helsinki and make a new life for his family',
title: 'Bad Luck Love',
score: 3.6251673698425293
}
]

constant 옵션은 기본 점수를 지정된 숫자로 대체합니다.

참고

constant 및 boost 옵션을 함께 사용하면 안 됩니다.

다음 예에서는 sample_mflix.movies 컬렉션에 대한 기본 인덱스와 복합 연산자를 활용하여 plot 및 title 필드를 쿼리합니다. 쿼리에서 텍스트 연산자는 constant 옵션과 함께 score를 사용하여 title 필드에 대한 쿼리와 일치하는 결과에서만 모든 점수 결과를 5 로 바꿉니다.

1db.movies.aggregate([
2 {
3 "$search": {
4 "compound": {
5 "should": [{
6 "text": {
7 "query": "tower",
8 "path": "plot"
9 }
10 },
11 {
12 "text": {
13 "query": "tower",
14 "path": "title",
15 "score": { "constant": { "value": 5 } }
16 }
17 }]
18 }
19 }
20 },
21 {
22 "$limit": 5
23 },
24 {
25 "$project": {
26 "_id": 0,
27 "title": 1,
28 "plot": 1,
29 "score": { "$meta": "searchScore" }
30 }
31 }
32])

위의 쿼리는 다음 결과를 반환하며, title 필드에 대한 쿼리와 일치하는 문서의 점수만 지정된 constant 값으로 대체됩니다.

1[
2 {
3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',
4 title: 'Tower Block',
5 score: 8.15460205078125
6 },
7 {
8 plot: "When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",
9 title: 'Tower Heist',
10 score: 5
11 },
12 {
13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',
14 title: 'Tokyo Tower',
15 score: 5
16 },
17 {
18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',
19 title: 'The Leaning Tower',
20 score: 5
21 },
22 {
23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',
24 title: 'Ivory Tower',
25 score: 5
26 }
27]

참고

이 옵션은 embeddedDocument 연산자에서만 사용할 수 있습니다.

embedded 옵션을 사용하여 다음에 대한 방법을 구성할 수 있습니다.

  • 일치하는 여러 내장된 문서의 점수를 집계합니다.

  • 일치하는 내장된 문서의 점수를 집계한 후 embeddedDocument 연산자의 점수를 수정합니다.

embedded 옵션은 다음 필드를 사용합니다.

필드
유형
필요성
설명

aggregate

문자열

옵션

일치하는 내장된 문서의 점수를 결합하는 방법을 구성합니다. 값은 다음 집계 전략 중 하나여야 합니다:

  • sum - (기본값) 일치하는 모든 내장된 문서의 점수를 합산합니다.

  • maximum - 일치하는 모든 내장된 문서 중 가장 높은 점수를 선택합니다.

  • minimum - 일치하는 모든 내장된 문서 중 가장 점수가 낮은 문서를 선택합니다.

  • mean - 일치하는 모든 내장된 문서의 평균(산술 MEAN) 점수를 선택합니다. MongoDB Search는 평균을 계산할 때만 일치하는 내장된 문서의 점수를 포함합니다. MongoDB Search는 쿼리 조건자를 충족하지 않는 내장된 문서를 점수가 0인 문서로 계산하지 않습니다.

이 필드를 생략하면 기본값은 sum입니다.

outerScore

옵션

집계 전략을 적용한 후 적용할 점수 수정을 지정합니다.

다음 예제에서는 sample_analytics.transactions 컬렉션의 default 인덱스를 사용합니다. 이 인덱스는 transactions 배열의 문서에 대해 embeddedDocuments 유형을 구성하고 transactions.symbol 및 transactions.transaction_code 필드에 대해 string 유형을 구성합니다.

예시

샘플 인덱스
{
"mappings": {
"dynamic": true,
"fields": {
"transactions": {
"dynamic": true,
"fields": {
"symbol": {
"type": "string"
},
"transaction_code": {
"type": "string"
}
},
"type": "embeddedDocuments"
}
}
}
}

문서 배열이 포함된 transactions 필드에 대한 샘플 쿼리에는 출력을 10 개의 결과로 제한하는 $limit 단계, 그리고 $project 단계가 포함되어 있습니다.

  • account_id와 transaction_count 이외의 모든 필드를 제외합니다.

  • 집계 전략과 추가 점수 수정을 적용하는 score 필드를 추가합니다.

    참고

    You can use function inside the score option of the embeddedDocument operator's operator. However, for function score expressions that require the path option, the numeric field that you specify as the path for the expression must be inside the embeddedDocument operator's path. For example, in the following example query, the field transactions.amount that is specified inside the score option of the compound operator on line 24 is inside in the embeddedDocument operator's path transactions on line 4.

이 쿼리는 AMD를 구매한 계정을 검색하고 가장 큰 단일 AMD 구매(주식 수 기준)에 해당 계정이 이 기간 동안 수행한 트랜잭션 수의 log1p값을 곱합니다. 다음을 기준으로 계정의 순위를 매깁니다.

  • 단일 트랜잭션에서 구매한 AMD 개수

  • 마지막 기간의 트랜잭션 수

1db.transactions.aggregate({
2 "$search": {
3 "embeddedDocument": {
4 "path": "transactions",
5 "operator": {
6 "compound": {
7 "must": [
8 {
9 "text": {
10 "path": "transactions.symbol",
11 "query": "amd"
12 }
13 },
14 {
15 "text": {
16 "path": "transactions.transaction_code",
17 "query": "buy"
18 }
19 }
20 ],
21 "score": {
22 "function": {
23 "path": {
24 "value": "transactions.amount",
25 "undefined": 1.0
26 }
27 }
28 }
29 }
30 },
31 "score": {
32 "embedded": {
33 "aggregate": "maximum",
34 "outerScore": {
35 "function": {
36 "multiply": [
37 {
38 "log1p": {
39 "path": {
40 "value": "transaction_count"
41 }
42 }
43 },
44 {
45 "score": "relevance"
46 }
47 ]
48 }
49 }
50 }
51 }
52 }
53 }
54},
55{ "$limit": 10 },
56{
57 "$project": {
58 "_id": 0,
59 "account_id": 1,
60 "transaction_count": 1,
61 "score": { $meta: "searchScore" }
62 }
63})

MongoDB Search는 지난 기간 동안 많은 트랜잭션을 수행하고 단일 트랜잭션 에서 AMD 을(를) 많이 구매한 계정의 순위를 높입니다.

1[
2 { account_id: 467651, transaction_count: 99, score: 19982 },
3 { account_id: 271554, transaction_count: 96, score: 19851.822265625 },
4 { account_id: 71148, transaction_count: 99, score: 19840 },
5 { account_id: 408143, transaction_count: 100, score: 19836.76953125 },
6 { account_id: 977774, transaction_count: 98, score: 19822.64453125 },
7 { account_id: 187107, transaction_count: 96, score: 19754.470703125 },
8 { account_id: 492843, transaction_count: 97, score: 19744.998046875 },
9 { account_id: 373169, transaction_count: 93, score: 19553.697265625 },
10 { account_id: 249078, transaction_count: 89, score: 19436.896484375 },
11 { account_id: 77690, transaction_count: 90, score: 19418.017578125 }
12]

The function option allows you to alter the final score of the document using a numeric field . You can specify the numeric field for computing the final score through an expression. If the final result of the function score is less than 0, MongoDB Search replaces the score with 0.

참고

embeddedDocument 연산자의 operator의 score 옵션 안에 function을 사용할 수 있습니다. 그러나 path 옵션이 필요한 함수 점수 표현식의 경우, 표현식의 path로 지정하는 숫자 필드가 embeddedDocument 연산자의 path 안에 있어야 합니다.

문서의 최종 점수를 변경하려면 function 옵션과 함께 다음 표현식을 사용하세요.

  • 산술 표현식: 일련의 숫자를 더하거나 곱하는 표현식

  • 상수 표현식: 함수 점수에 상수를 허용하는 표현식

  • 가우스 감쇠 표현식: 지정된 비율로 곱하여 점수를 감쇠 또는 감소시키는 표현식

  • 경로 표현식: 인덱싱된 숫자 필드 값을 함수 점수에 통합하는 표현식

  • 점수 표현식은 MongoDB Search에서 할당된 관련성 점수를 반환합니다.

  • 단항 표현식: 단일 인수를 사용하는 표현식입니다. MongoDB Search에서는 지정된 숫자의 로그10(x) 또는 로그10(x+1)를 계산할 수 있습니다.

참고

MongoDB Search 함수 점수는 항상 float 값이며 매우 크거나 작은 숫자의 경우 정밀도가 손실될 수 있습니다.

산술 표현식은 일련의 숫자를 더하거나 곱하는 연산식입니다. 예를 들어, 산술 표현식을 사용하여 데이터 인리치먼트 파이프라인의 숫자 필드를 통해 관련성 순위를 변경할 수 있습니다. 다음 옵션 중 하나를 포함해야 합니다:

옵션
유형
설명

add

표현식으로 구성된 배열

Adds a series of numbers. Takes an array of expressions, which can have negative values. Array length must be greater than or equal to 2. For example:

산술 표현식 구문
"function": {
"add": [
{"path": "rating"},
{"score": "relevance"}
]
}

이전 예시 에서 MongoDB Search는 path 및 score 표현식을 사용하여 다음을 추가합니다.

  • 문서에 rating 필드가 없는 경우 rating 필드 또는 0 의 숫자 값

  • 관련성 점수는 MongoDB Search가 관련성에 따라 할당하는 점수입니다.

multiply

표현식으로 구성된 배열

Multiplies a series of numbers. Takes an array of expressions, which can have negative values. Array length must be greater than or equal to 2. For example:

산술 표현식 구문
"function": {
"multiply": [
{
"path": {
"value": "popularity",
"undefined": 2.5
}
},
{
"score": "relevance"
},
{
"constant": 0.75
}
]
}

이전 예시 에서 MongoDB Search는 path, score, constant 표현식을 사용하여 문서 의 최종 점수를 변경합니다. 다음을 곱합니다:

  • 문서에 popularity 필드가 없는 경우 popularity 필드 또는 2.5의 숫자 값인 경로 표현식의 숫자 값

  • 관련성 점수는 MongoDB Search가 관련성에 따라 할당하는 점수입니다.

  • 의 상수값 0.75

참고

undefined 으로 평가되는 산술 표현식을 상수 값으로 바꿀 수 없습니다.

다음 예시에서는 sample_mflix.movies 컬렉션의 기본 인덱스를 사용하여 title 필드를 쿼리합니다. 샘플 쿼리에는 출력을 5개의 결과로 제한하는 $limit 단계와 title 및 score를 제외한 모든 필드를 제외하는 $project 단계가 포함됩니다.

예시

이 예에서 텍스트 연산자는 score 와 function 옵션을 사용하여 다음을 곱합니다:

  • 문서의 imdb.rating 필드의 값에 해당하는 경로 표현식의 숫자 값이며, imdb.rating 필드가 문서에 없는 경우 2 값입니다.

  • 관련성 점수 또는 문서의 현재 점수

db.movies.aggregate([{
"$search": {
"text": {
"path": "title",
"query": "men",
"score": {
"function":{
"multiply":[
{
"path": {
"value": "imdb.rating",
"undefined": 2
}
},
{
"score": "relevance"
}
]
}
}
}
}
},
{
$limit: 5
},
{
$project: {
"_id": 0,
"title": 1,
"score": { "$meta": "searchScore" }
}
}])

이 쿼리는 점수가 지정된 function 값으로 대체된 다음 결과를 반환합니다.

{ "title" : "Men...", "score" : 23.431293487548828 }
{ "title" : "12 Angry Men", "score" : 22.080968856811523 }
{ "title" : "X-Men", "score" : 21.34803581237793 }
{ "title" : "X-Men", "score" : 21.34803581237793 }
{ "title" : "Matchstick Men", "score" : 21.05954933166504 }