정의
vectorSearch 연산자 지정된 필드의 벡터 임베딩에 대해 ANN 또는 ENN 검색 수행합니다. 이 연산자 사용하여 퍼지 검색, 구문 일치, 위치 필터링, 와일드카드 패턴 일치 등과 같은 분석된 텍스트 기능을 시맨틱 검색 과 함께 추가할 수 있습니다.
구문
vectorSearch 의 구문은 다음과 같습니다:
{ "$search": { "index": "<index name>", // optional, defaults to "default" "vectorSearch": { "exact": true | false, "filter": {<operator-specification>}, "limit": <number-of-results>, "numCandidates": <number-of-candidates>, "path": "<field-to-search>", "queryVector": [<array-of-numbers>], "score": {<options>} } } }
옵션
vectorSearch 다음 필드를 사용하여 쿼리를 구성합니다.
필드 | 유형 | 필요성 | 설명 |
|---|---|---|---|
| 부울 | 옵션 |
등가 최근접 이웃 또는 근사 최근접 이웃 검색을 실행할지 여부를 지정하는 플래그입니다. 값은 다음 중 하나일 수 있습니다:
생략하는 경우 기본값은 MongoDB Vector Search supports ANN search on Atlas clusters running MongoDB v6.0.11, v7.0.2, or later and ENN search on clusters running MongoDB v6.0.16, v7.0.10, v7.3.2, or later. You can also use MongoDB Vector Search with self-managed or local Atlas deployments that you create with the Atlas CLI. |
| 객체 | 옵션 | MongoDB Search 연산자를 사용하여 메타데이터 또는 특정 검색 기준에 따라 문서를 사전 필터링할 수 있습니다. To learn more, see Pre-Filter. |
| Int | 필수 사항 | |
| Int | 옵션 |
검색 중에 사용할 가장 가까운 이웃의 수입니다. 값은 ( 정확도를 높이기 위해 반환할 문서 수( This overrequest pattern is the recommended way to trade off latency and :recall in your ANN searches, and we recommend tuning this parameter based on your specific dataset size and query requirements. |
| 문자열 | 필수 사항 | 검색할 인덱싱된 벡터 유형 필드입니다. |
| 정수 또는 실수 배열 | 필수 사항 | Array of numbers of To learn more about generating BSON 배열 크기는 필드에 대한 인덱스 정의에서 지정된 벡터 차원 수( 데이터를 임베드할 때 사용한 것과 동일한 모델을 사용하여 쿼리를 임베드해야 합니다. 벡터 하위 유형이 동일한 경우, full-fidelity 벡터를 사용하여 임베딩을 쿼리할 수 있습니다. |
| 객체 | 옵션 | 일치하는 검색 텀 결과에 할당된 점수입니다. 다음 옵션 중 하나를 사용하여 기본 점수를 수정합니다.
쿼리에서 |
행동
MongoDB 검색 인덱스
vectorSearch 연산자를 사용하여 검색할 필드를 인덱싱해야 합니다. MongoDB Search 인덱스 정의에서 다음 유형의 필드를 인덱싱할 수 있습니다.
벡터 임베딩을 포함하는 필드. 이 필드는 쿼리
path옵션에서 지정한 필드입니다.문서를 사전 필터링하는 필드. 이 필드는 쿼리
filter옵션에서 지정한 필드입니다.
사전 필터
문서를 사전 필터링하여 시맨틱 검색 범위를 좁힐 수 있습니다. filter 필드 에서 지원되는 MongoDB Search 연산자 사용하여 문서를 쿼리 하고 필터하다 .
중요
필터링된 쿼리는 일반적으로 이에 상응하는 필터링되지 않은 쿼리 보다 느립니다.
vector 유형의 인덱스 정의에서 데이터를 필터링할 필드를 반드시 인덱싱해야 합니다.
점수
You can include the score of each document in your search results. Specify the $meta expression with the searchScore value in the $project stage. You can also specify the searchScoreDetails value for the scoreDetails field $meta expression for a detailed breakdown of the score.
자세한 내용은 결과에서 문서의 점수를 매기기 및 점수 세부 정보 반환을 참조하세요.
vectorSearch 연산자 제한 사항
vectorSearch 연산자는 쿼리에서 최상위 연산자여야 합니다. 따라서 다음 MongoDB Search 연산자에서는 vectorSearch 연산자를 사용할 수 없습니다.
You can't use the vectorSearch operator to query fields indexed using a vectorSearch type index.
다음 $search 옵션은 vectorSearch 연산자와 함께 사용할 수 없습니다:
MongoDB Search Playground에서는 $search 쿼리를 vectorSearch 연산자와 함께 실행할 수 없습니다.
예시
The following examples use the sample_mflix.embedded_movies collection from the sample data. If you load the sample data and create the sample index on the collection, you can run the following ANN and ENN queries against the collection after replacing the <connection-string> and <index-name> placeholders in the queries.