Docs Menu
Docs Home

MongoDB Vector Search를 사용하여 자동으로 임베딩 생성하기

클러스터 의 텍스트 데이터에 대한 벡터 임베딩을 자동으로 생성하고 관리 MongoDB Vector Search를 구성할 수 있습니다. M10 이상의 Atlas cluster 에서 원클릭 AI 시맨틱 검색 인덱스 생성하고Voyage AI 임베딩 모델을 사용하여 벡터를 사용한 인덱싱, 업데이트 및 쿼리를 간소화할 수 있습니다.

자동화된 임베딩을 활성화 MongoDB Vector Search는 Atlas 컬렉션 의 지정된 텍스트 필드 에 대한 인덱스 타임과 자동화된 임베딩을 위해 인덱싱된 필드 에 대한 쿼리 의 텍스트 문자열에 대한 쿼리 타임에 지정된 임베딩 모델을 사용하여 임베딩을 자동으로 생성합니다.

중요

모든 cloud 제공자 의 M10 이상 클러스터 에서 MongoDB Vector Search 자동 임베딩을 사용할 수 있습니다. 그러나 벡터 임베딩을 생성하기 위한 추론 프로세스 처리하는 서비스는 Google Cloud Platform 에서 실행됩니다. 즉, 클러스터의 cloud 제공자 와 관계없이 임베딩 생성 및 검색을 위해 데이터가 Google Cloud Platform 으로 전송됩니다. 엔터프라이즈 급 보안을 제공하므로 데이터는 클러스터 에만 저장됩니다.

임베딩 모델은 공유된 멀티 테넌트 추론 플랫폼에서 실행 . 따라서 미리 보기 기간 동안에는 문서 100k 미만인 데이터 세트를 사용해야 하며 부하 테스트가 아닌 기능 평가를 위해서만 쿼리를 실행 . 한도가 더 높은 사용 사례 있는 경우 계정 팀 문의하세요.

워크로드 에 대한 엄격한 요금 제한은 없지만 전역 제한이 있습니다. 쿼리가 속도 제한 오류(오류 409)를 반환하면 백오프를 수행하고 애플리케이션 코드에서 다시 시도합니다. 이를 통해 애플리케이션 속도 제한을 정상적으로 처리하다 하고 지속적인 기능을 보장할 수 있습니다.

자동화된 임베딩을 사용하여 벡터 검색 활성화 하려면 다음이 필요합니다.

  • M10 이상 클러스터

  • 자동화된 임베딩을 위해 인덱스 하려는 텍스트 필드 있는 컬렉션 입니다.

  • 다음 클라이언트 중 하나:

    다음 드롭다운 메뉴를 사용하여 이 페이지의 절차에 대한 클라이언트 설정하다 .

다음 섹션에서는 MongoDB Vector Search 인덱스 구문과 텍스트 필드에 대한 임베딩을 자동으로 생성할 수 있는 필드에 대해 설명하고 자동 임베딩을 위해 인덱스 구성하는 단계를 안내합니다.

MongoDB Vector Search 인덱스를 생성하고 관리 하려면 Project Data Access Admin 이상의 역할 필요합니다.

다음은 임베딩 자동 생성을 활성화하는 구문입니다.

1{
2 "fields": [
3 {
4 "type": "text",
5 "path": "<field-name>",
6 "model": "voyage-3-large | voyage-3.5 | voyage-3.5-lite"
7 }
8 ]
9}

인덱스 정의에는 다음 필드가 필요합니다.

필드

유형

설명

type

문자열

필드 의 유형입니다. 자동화된 임베딩의 경우 text이어야 합니다.

path

문자열

자동화된 임베딩을 위해 인덱스 하려는 컬렉션 필드 의 이름입니다.

model

문자열

인덱스를 위한 임베딩을 생성할 때 사용할 Voyage AI 임베딩 모델입니다. 다음 모델 중 하나를 지정할 수 있습니다.

  • voyage-3-large - 모든 언어와 도메인에 걸쳐 최고 품질의 검색을 제공합니다.

  • voyage-3.5 - 다국어 사용 및 범용 검색 정확도를 위한 균형 잡힌 모델입니다.

  • voyage-3.5-lite - 지연 시간 과 낮은 비용 에 최적화된 가볍고 빠른 모델입니다.

인덱스 생성한 후 이후에 임베딩 모델을 변경하면 MongoDB Vector Search는 데이터 세트에 대한 새 임베딩을 생성합니다. MongoDB Vector Search가 임베딩을 생성하는 동안 이전 임베딩을 사용하여 계속 쿼리 할 수 있습니다. 이전 임베딩이 새 임베딩 모델의 임베딩으로 대체되면 MongoDB Vector Search는 이전 임베딩을 제거합니다.

자동화된 임베딩을 위한 인덱스 필드는 다음 vector 유형 인덱스 필드와 상호 배타적입니다.

  • numDimensions

  • similarity

  • quantization

컬렉션에 이미 임베딩이 있는 경우 vector 필드 유형을 사용하여 임베딩을 인덱싱해야 합니다. 임베딩을 사용하여 필드를 인덱싱하는 방법에 대해 자세히 알아보려면 벡터 검색을 위해 필드를 인덱스하는 방법을 참조하세요.

임베딩을 자동으로 생성하기 위해 텍스트 필드 인덱스 하고 자체 임베딩으로 필드 인덱스 하려는 경우 textvector 유형을 모두 사용하여 인덱스 만들 수 있습니다. MongoDB Vector Search는 text 유형으로 인덱싱된 필드 대해서만 쿼리에 대한 임베딩을 자동으로 생성합니다. vector 유형으로 인덱싱된 필드 검색하려면 쿼리 에 임베딩을 지정해야 합니다.

필드를 인덱스 MongoDB Vector Search filter 유형을 사용하여 데이터를 사전 필터링할 수도 있습니다. 사전 필터링은 유사성 비교를 실행 문서 수를 줄여 쿼리 지연 시간 줄이고 검색 결과의 정확성을 높일 수 있습니다. 데이터 사전 필터링에 대해 자세히 학습하려면 filter 유형 정보를 참조하세요.

다음 절차에서는 MongoDB Vector Search 인덱스 에서 자동화된 임베딩을 활성화하는 단계를 안내합니다. sample_mflix.movies 데이터 세트를 로드한 경우 절차의 예시 컬렉션 의 fullplot 필드 에 대해 자동 임베딩을 활성화 방법을 보여줍니다.

1
  1. 아직 표시되지 않은 경우 탐색 표시줄의 Organizations 메뉴에서 원하는 프로젝트가 포함된 조직을 선택합니다.

  2. 아직 표시되지 않은 경우 탐색 표시줄의 Projects 메뉴에서 원하는 프로젝트를 선택합니다.

  3. 사이드바에서 Database 제목 아래의 Clusters를 클릭합니다.

Clusters(클러스터) 페이지가 표시됩니다.

2

Search & Vector Search 옵션 또는 Data Explorer에서 MongoDB 검색 페이지로 이동할 수 있습니다.

3

페이지에서 다음 항목을 선택한 후 Next를 클릭합니다.

Search Type

Vector Search 인덱스 유형을 선택합니다.

Index Name and Data Source

다음 정보를 지정합니다.

  • Index Name: <INDEX-NAME>

  • Database and Collection:

    • <DATABASE-NAME>

    • <COLLECTION-NAME>

Configuration Method

JSON Editor0}을 선택합니다.

예시

예를 들어, 인덱스 이름에는 movies_automated_embeddings를 입력하고 Database and Collection 드롭다운에서 sample_mflixmovies를 선택하세요.

4

JSON 편집기에서 다음 인덱스 정의를 입력하세요.

1{
2 "fields": [
3 {
4 "type": "text",
5 "path": "<FIELD-NAME>",
6 "model": "voyage-3-large | voyage-3.5 | voyage-3.5-lite"
7 }
8 ]
9}

예시

예를 들어, fullplot 컬렉션의 voyage-3-large 필드를 위한 자동 임베딩을 활성화하는 인덱스를 생성하려면 다음을 입력합니다.

1{
2 "fields": [
3 {
4 "type": "text",
5 "path": "fullplot",
6 "model": "voyage-3-large"
7 }
8 ]
9}
5
  1. Next를 클릭합니다.

  2. 인덱스 구성을 검토하고 Create Vector Search Index을 클릭합니다.

참고

인덱스 생성을 완료하는 데 시간이 걸릴 수 있습니다. 인덱스가 생성되는 동안 Atlas UI의 Status 열에 Pending이 표시됩니다. 인덱스 생성이 완료되면 Atlas UI의 Status 열에 Ready가 표시됩니다.

1

자세한 학습은 mongosh 통해 클러스터에 연결을참조하세요.

2

전환하려면 다음 명령을 실행합니다.

use <DATABASE-NAME>

여기서 <DATABASE-NAME> 은 사용하려는 데이터베이스 의 이름입니다.

예시

예시 를 들어 movies 컬렉션 포함된 sample_mflix 데이터베이스 로 전환하려면 다음 명령을 실행 .

use sample_mflix
3

db.collection.createSearchIndex() 메서드의 구문은 다음과 같습니다.

1db.<COLLECTION-NAME>.createSearchIndex(
2 "<INDEX-NAME>",
3 "vectorSearch",
4 {
5 "fields": [
6 {
7 "type": "text",
8 "path": "<FIELD-NAME>",
9 "model": "voyage-3-large | voyage-3.5 | voyage-3.5-lite"
10 },
11 {
12 "type": "filter",
13 "path": "<FIELD-NAME>"
14 },
15 ...
16 ]
17 }
18);

예시

예시 컬렉션 의 fullplot 필드 에 voyage-3-large 모델을 사용하여 자동 임베딩을 활성화하는 인덱스 만들려면 터미널에서 다음 명령을 실행 .

1db.movies.createSearchIndex(
2 "movies_automated_embeddings",
3 "vectorSearch",
4 {
5 "fields": [
6 {
7 "type": "text",
8 "path": "fullplot",
9 "model": "voyage-3-large"
10 }
11 ]
12 }
13);
1

터미널에서 다음 명령을 실행하여 auto-embeddings-project라는 새 디렉터리를 만들고 프로젝트를 초기화합니다.

mkdir auto-embeddings-project
cd auto-embeddings-project
npm init -y
2
touch <file-name>.js

예시

예를 들어, create_index.js라는 파일을 만드세요.

touch create_index.js
3
1const { MongoClient } = require("mongodb");
2
3// connect to your Atlas deployment
4const uri = "<CONNECTION-STRING>";
5const client = new MongoClient(uri);
6
7async function run() {
8 try {
9 const database = client.db("<DATABASE-NAME>");
10 const collection = database.collection("<COLLECTION-NAME>");
11
12 // define your MongoDB Vector Search index
13 const index = {
14 "name": "<INDEX-NAME>",
15 "type": "vectorSearch",
16 "definition": {
17 "fields": [
18 {
19 "type": "vector",
20 "path": "<FIELD-NAME>",
21 "model": "voyage-3-large | voyage-3.5 | voyage-3.5-lite"
22 },
23 ]
24 }
25 }
26 // run the helper method
27 await collection.createSearchIndex("<INDEX-NAME>", index);
28 } finally {
29 await client.close();
30 }
31}
32run().catch(console.dir);

예시

예시 들어 sample_mflix.movies 네임스페이스 의 fullplot 필드 에 voyage-3-large 모델을 사용하여 자동 임베딩을 활성화하는 인덱스 만들려면 다음을 복사하여 create_index.js 파일 에 붙여넣습니다.

1const { MongoClient } = require("mongodb");
2
3// connect to your Atlas deployment
4const uri = "<CONNECTION-STRING>";
5const client = new MongoClient(uri);
6
7async function run() {
8 try {
9 const database = client.db("sample_mflix");
10 const collection = database.collection("movies");
11
12 // define your MongoDB Vector Search index
13 const index = {
14 "name": "movies_automated_embeddings",
15 "type": "vectorSearch",
16 "definition": {
17 "fields": [
18 {
19 "type": "text",
20 "path": "fullplot",
21 "model": "voyage-3-large"
22 }
23 ]
24 }
25 }
26 // run the helper method
27 await collection.createSearchIndex(index);
28 } finally {
29 await client.close();
30 }
31}
32run().catch(console.dir);
4

<CONNECTION-STRING>

Atlas cluster 의 연결 문자열 .

<DATABASE-NAME>

인덱스 생성하려는 컬렉션 포함된 데이터베이스 의 이름입니다.

<COLLECTION-NAME>

인덱스를 생성하려는 컬렉션의 이름입니다.

<FIELD-NAME>

자동화된 임베딩을 위해 인덱스 하려는 컬렉션 필드 의 이름입니다.

<INDEX-NAME>

생성하려는 인덱스 의 이름입니다.

5
node <file-name>.js

예시

예를 들어, create_index.js 파일에 정의된 인덱스를 생성하려면 터미널에서 다음 명령을 실행하세요.

node create_index.js
1
touch <file-name>.py

예시

예를 들어, create_index.py라는 파일을 만드세요.

touch create_index.py
2
1from pymongo import MongoClient
2from pymongo.operations import SearchIndexModel
3
4client = pymongo.MongoClient("<CONNECTION-STRING>")
5db = client["<DATABASE-NAME>"]
6collection = db["<COLLECTION-NAME>"]
7
8search_index_model = SearchIndexModel(
9 definition={
10 "fields": [
11 {
12 "type": "text",
13 "path": "<FIELD-NAME>",
14 "model": "voyage-3-large | voyage-3.5 | voyage-3.5-lite"
15 }
16 ]
17 },
18 name="<INDEX-NAME>",
19 type="vectorSearch",
20)
21result = collection.create_search_index(model=search_index_model)
22print(result)

예시

예시 들어 sample_mflix.movies 네임스페이스 의 fullplot 필드 에 voyage-3-large 모델을 사용하여 자동 임베딩을 활성화하는 인덱스 만들려면 다음을 복사하여 create_index.py 파일 에 붙여넣습니다.

1from pymongo import MongoClient
2from pymongo.operations import SearchIndexModel
3
4client = MongoClient("<CONNECTION-STRING>")
5db = client["sample_mflix"]
6collection = db["movies"]
7
8search_index_model = SearchIndexModel(
9 definition={
10 "fields": [
11 {
12 "type": "text",
13 "path": "fullplot",
14 "model": "voyage-3-large"
15 }
16 ]
17 },
18 name="movies_automated_embeddings",
19 type="vectorSearch",
20)
21result = collection.create_search_index(model=search_index_model)
22print(result)
3

<CONNECTION-STRING>

Atlas cluster 의 연결 문자열 .

<database-name>

인덱스 생성하려는 컬렉션 포함된 데이터베이스 의 이름입니다.

<collection-name>

인덱스를 생성하려는 컬렉션의 이름입니다.

<field-name>

자동화된 임베딩을 위해 인덱스 하려는 컬렉션 필드 의 이름입니다.

<index-name>

생성하려는 인덱스 의 이름입니다.

4
python <file-name>.py

예시

예를 들어, create_index.py 파일에 정의된 인덱스를 생성하려면 터미널에서 다음 명령을 실행하세요.

python create_index.py

자동화된 임베딩을 사용하여 인덱스 만든 후 인덱스된 필드 대해 텍스트 쿼리를 실행 수 있습니다. MongoDB Vector Search는 인덱스 에 지정된 것과 동일한 임베딩 모델을 사용하여 쿼리 의 텍스트 문자열에 대한 임베딩을 자동으로 생성합니다. 임베딩을 사용하여 지정된 쿼리 텍스트와 의미적으로 유사한 문서를 인덱스 검색 .

다음 섹션에서는 자동 임베딩을 위해 인덱싱된 필드에 대해 쿼리 텍스트에 대한 임베딩을 자동으로 생성하기 위한 $vectorSearch 파이프라인 구문 및 필드를 설명하고 자동 임베딩을 위해 인덱싱된 필드에 대해 시맨틱 검색 쿼리를 실행 방법을 보여 줍니다.

다음 구문은 자동 임베딩을 위해 인덱싱된 필드 에 대해 쿼리 실행 방법을 보여줍니다.

1{
2 "$vectorSearch": {
3 "index": "<index-name>",
4 "limit": <number-of-results>,
5 "numCandidates": <number-of-candidates>,
6 "path": "<field-to-search>",
7 "query": "<query-string>"
8 }
9}

자동화된 임베딩을 사용하는 MongoDB Vector Search 쿼리 에는 다음 필드가 필요합니다.

필드
유형
필요성
설명

exact

부울

조건부

numCandidates 이(가) 생략된 경우 이 필드는 필수 항목입니다. numCandidates와(과) 상호 배타적입니다.

ENN 또는 ANN 검색 실행 할지 여부를 지정하는 플래그입니다. 값은 다음 중 하나일 수 있습니다.

  • false - ANN 검색 실행 시

  • true - ENN 검색 실행 시

생략하는 경우 기본값은 false입니다.

index

문자열

필수 사항

사용할 MongoDB Vector Search 인덱스 의 이름입니다.

인덱스 이름의 철자가 잘못되었거나 지정된 인덱스 클러스터 에 없는 경우 MongoDB Vector Search는 결과를 반환하지 않습니다.

limit

숫자

필수 사항

결과에 반환할 문서 수(int 유형만 해당)입니다. numCandidates를 지정하는 경우 이 값은 numCandidates 값을 초과할 수 없습니다.

numCandidates

숫자

조건부

exactfalse이거나 생략된 경우 이 필드는 필수입니다. exact와 상호 배타적입니다.

검색 중에 사용할 가장 가까운 이웃의 수입니다. 값은 (<=)10000보다 작거나 같아야 합니다. 반환할 문서 수보다 작은 숫자는 지정할 수 없습니다(limit).

path

문자열

필수 사항

검색할 인덱싱된 벡터 유형 필드입니다.

query

문자열

필수 사항

임베딩을 자동으로 생성하고 시맨틱 검색을 수행할 텍스트입니다.

인덱스된 필드에 대해 근사 최근접 이웃(ANN) 또는 등가 최근접 이웃(ENN) 쿼리를 실행할 수 있습니다. 자세한 내용은 근사 최근접 이웃(ANN) 검색등가 최근접 이웃(ENN) 검색을 참조하세요.

자동 임베딩을 위해 인덱싱된 필드에 대해서는 쿼리 에서 벡터 임베딩을 지정할 수 없습니다. 대신 필드 에 대해 언어 쿼리 실행 해야 합니다. 자동화된 임베딩을 위해 인덱싱된 필드 에 대해 언어 쿼리 실행 MongoDB Vector Search는 인덱싱된 필드 와 동일한 임베딩 모델을 사용하여 쿼리 텍스트에 대한 임베딩을 자동으로 생성합니다. 그런 다음 생성된 임베딩을 사용하여 인덱싱된 필드 대해 시맨틱 검색 수행합니다.

선택적으로 쿼리 에 filter 필드를 지정하여 MongoDB Vector Search가 시맨틱 검색 수행하는 문서를 사전 필터링할 수 있습니다. 자세한 학습 은 MongoDB 벡터 검색 사전 필터를 참조하세요.

선택적으로 결과에서 문서의 점수를 조회 할 수도 있습니다. 자세한 학습은 MongoDB Vector Search 점수를 참조하세요.

Atlas UI 에서는 MongoDB Vector Search 쿼리를 실행 수 없습니다. mongosh 또는 지원되는 운전자 사용하여 쿼리를 실행 .

1

자세한 학습은 mongosh 통해 클러스터에 연결을참조하세요.

2
use <database-name>

예시

예를 들어, sample_mflix 데이터베이스로 전환하려면 터미널에서 다음 명령을 실행합니다.

use sample_mflix
3

db.collection.aggregate() 메서드의 구문은 다음과 같습니다.

1db.<COLLECTION-NAME>.aggregate([
2 {
3 "$vectorSearch": {
4 "index": "<INDEX-NAME>",
5 "path": "<FIELD-NAME>",
6 "query": "<QUERY-TEXT>",
7 "numCandidates": <NUMBER-OF-CANDIDATES-TO-CONSIDER>,
8 "limit": <NUMBER-OF-DOCUMENTS-TO-RETURN>
9 }
10 }
11])

예시

예시 들어 young heroes caught in epic struggles between light and darkness와 의미론적으로 유사한 영화에 대한 시맨틱 검색 위해 movies 컬렉션 의 fullplot 필드 에 대해 쿼리 실행 하려면 다음 쿼리 복사하여 붙여넣고 실행 .

1db.movies.aggregate([
2 {
3 "$vectorSearch": {
4 "index": "movies_automated_embeddings",
5 "path": "fullplot",
6 "query": "young heroes caught in epic struggles between light and darkness",
7 "numCandidates": 1000,
8 "limit": 10
9 }
10 },
11 {
12 "$project": {
13 "_id": 0,
14 "title": 1,
15 "fullplot": 1,
16 "score": {"$meta": "vectorSearchScore"}
17 }
18 }
19])
1[
2 {
3 title: 'Day Watch',
4 fullplot: 'Anton belongs to the Forces of the Light as well as his powerful girlfriend and apprentice, but his son is a powerful teenager from the Darkness and Anton protects him. When the balance between Light and Darkness is affected by the death of some evil vampires, Anton is framed and accused of the murders, and he chases an ancient chalk that has the power of changing the destiny of its owner.',
5 score: 0.5449697971343994
6 },
7 {
8 title: 'Dungeons & Dragons',
9 fullplot: "The Empire of Izmer has long been a divided land. The Mages - an elite group of magic-users - rule whilst the lowly commoners are powerless. Izmer's young Empress, Savina, wants equality and prosperity for all, but the evil Mage Profion is plotting to depose her and establish his own rule. The Empress possesses a scepter which controls Izmer's Golden Dragons. To challenge her rule, Profion must have the scepter, and tricks the Council of Mages into believing Savina is unfit to hold it. Knowing that Profion will bring death and destruction to Izmer, Savina must find the legendary Rod of Savrille, a mythical rod that has the power to control Red Dragons, a species even mightier than the Gold. Enter two thieves, Ridley and Snails, who unwittingly become instrumental in Savina's search for the Rod. Joined by a feisty Dwarf named Elwood, and helped by the Empress's expert tracker, the Elf Norda, the young heroes go in search of the Rod of Savrille. From the deadly maze of the Thieves Guild at Antius to an Elven Village, secret grotto and abandoned castles, Ridley and his band must outwit Profion's chief henchman Damodar at every turn while, back in Izmer, Profion prepares to do battle with the Empress. All depends on the Rod, but the outcome of the race to reach it first is far from certain, and Izmar's very survival hangs in the balance.",
10 score: 0.5414832830429077
11 },
12 {
13 title: 'Brave Story',
14 fullplot: 'A young boy attempts to change his destiny by entering a magic gateway to another world; but on his quest to find the Tower of Fortune and be granted any wish, he must conjure up all his bravery to battle demons, his friends, and ultimately himself.',
15 score: 0.5404887795448303
16 },
17 {
18 title: 'Justin and the Knights of Valour',
19 fullplot: 'Justin lives in a kingdom where bureaucrats rule and knights have been ousted. His dream is to be become one of the Knights of Valour, like his grandfather was, but his father Reginald, the chief counsel to the Queen, wants his son to follow in his footsteps and become a lawyer. After an inspiring visit to his beloved Grandmother and bidding farewell to his supposed lady-love Lara, Justin leaves home and embarks on a quest to become a knight. Along the way he meets the beautiful, feisty Talia, a quirky wizard called Melquiades, and the handsome Sir Clorex and is mentored by three monks; Blucher, Legantir and Braulio, who teach and test him in the ancient ways of the Knights of Valour. Whilst an unlikely candidate for knighthood, Justin must rise to the challenge quickly when banished former knight Sir Heraclio and his army, lead by Sota, return and threaten to destroy the Kingdom.',
20 score: 0.5374966859817505
21 },
22 {
23 title: 'Forest Warrior',
24 fullplot: 'John McKenna is a spiritual being who is able to transform into bear, wolf or eagle. He lives in the forests of Tanglewood and has dedicated his life to protect them. One day a gang of evil lumberjacks led by Travis Thorne arrive Tanglewood to chop the forest down. McKenna cannot let this happen, and together with his new friends - Lords of the Tanglewood, a band of children who love to play in the forest - he battles against Thorne and his evil gang.',
25 score: 0.5331881642341614
26 },
27 {
28 title: 'Forest Warrior',
29 fullplot: 'John McKenna is a spiritual being who is able to transform into bear, wolf or eagle. He lives in the forests of Tanglewood and has dedicated his life to protect them. One day a gang of evil lumberjacks led by Travis Thorne arrive Tanglewood to chop the forest down. McKenna cannot let this happen, and together with his new friends - Lords of the Tanglewood, a band of children who love to play in the forest - he battles against Thorne and his evil gang.',
30 score: 0.5331881642341614
31 },
32 {
33 title: 'Catatan (Harian) si Boy',
34 fullplot: "A circle of friends risking their Friendship, Trust, Love and Hope in search of a legend. A young and privileged teenager with a golden heart, beset with challenges and tribulations we face today with the goal to open many young people's mind with inspirations and hopes that drive them in achieving their dreams. To get out of their comfort zone and finish what they started.",
35 score: 0.5322973728179932
36 },
37 {
38 title: 'Bionicle: Mask of Light',
39 fullplot: "In a land of living machines, two young ones are chosen to seek the legendary Mask of Light to reveal the savior of all the lands from the dark forces of the Makuta. During the course of their adventure, they will call on the heroes of their people, the great Toa. These Toa, masters of nature's forces such as Fire, Wind, Earth & Water, try to protect the chosen ones as they seek their destiny.",
40 score: 0.5315042734146118
41 },
42 {
43 title: 'Fear No Evil',
44 fullplot: 'High school student turns out to be personification of Lucifer. Two arch angels in human form (as women) take him on.',
45 score: 0.5295513868331909
46 },
47 {
48 title: 'Tales of Vesperia: The First Strike',
49 fullplot: 'In a mythical kingdom, the mighty Imperial Knights harness a magical substance known as Aer to power their weapons and protect humanity from the monsters of the forest. But something strange is afoot. The Aer is somehow changing, causing the wilderness to waste away and stirring the woodland beasts to attack with greater frequency. As danger creeps steadily closer to civilization, two young recruits - Flynn, the rigid son of a fallen hero, and the rebellious and brash Yuri - must ride with their fellow Imperial Knights to distant ruins in hopes of uncovering the truth behind the transforming Aer. Some will not survive the thrilling journey. Some will be betrayed. If Flynn and Yuri cannot overcome their differences and learn to fight together, all will be lost for the people of the realm.',
50 score: 0.5276793241500854
51 }
52]
1

예시

예를 들어, automated-embeddings-query.js라는 파일을 만드세요.

touch automated-embeddings-query.js
2
1const { MongoClient } = require("mongodb");
2
3// connect to your Atlas cluster
4const uri = "<CONNECTION-STRING>";
5
6const client = new MongoClient(uri);
7
8async function run() {
9 try {
10 await client.connect();
11
12 // set namespace
13 const database = client.db("<DATABASE-NAME>");
14 const coll = database.collection("<COLLECTION-NAME>");
15
16 // define pipeline
17 const agg = [
18 {
19 '$vectorSearch': {
20 'index': '<INDEX-NAME>',
21 'path': '<FIELD-NAME>',
22 'query': "<QUERY-TEXT>",
23 'numCandidates': <NUMBER-OF-CANDIDATES-TO-CONSIDER>,
24 'limit': <NUMBER-OF-DOCUMENTS-TO-RETURN>
25 }
26 }
27 ];
28 // run pipeline
29 const result = coll.aggregate(agg);
30
31 // print results
32 await result.forEach((doc) => console.dir(JSON.stringify(doc)));
33 } finally {
34 await client.close();
35 }
36}
37run().catch(console.dir);

예시

예시 들어 automated-embeddings-query.js 파일 에서 다음 코드를 복사하여 붙여넣어 young heroes caught in epic struggles between light and darkness와 의미론적으로 유사한 영화에 대한 시맨틱 검색 위한 movies 컬렉션 의 fullplot 필드 에 대한 쿼리 정의합니다.

1const { MongoClient } = require("mongodb");
2
3// connect to your Atlas cluster
4const uri = "<CONNECTION-STRING>";
5
6const client = new MongoClient(uri);
7
8async function run() {
9 try {
10 await client.connect();
11
12 // set namespace
13 const database = client.db("sample_mflix");
14 const coll = database.collection("movies");
15
16 // define pipeline
17 const agg = [
18 {
19 '$vectorSearch': {
20 'index': 'movies_automated_embeddings',
21 'path': 'fullplot',
22 'query': "young heroes caught in epic struggles between light and darkness",
23 'numCandidates': 1000,
24 'limit': 10
25 }
26 }, {
27 '$project': {
28 '_id': 0,
29 'fullplot': 1,
30 'title': 1,
31 'score': {
32 '$meta': 'vectorSearchScore'
33 }
34 }
35 }
36 ];
37 // run pipeline
38 const result = coll.aggregate(agg);
39
40 // print results
41 await result.forEach((doc) => console.dir(JSON.stringify(doc)));
42 } finally {
43 await client.close();
44 }
45}
46run().catch(console.dir);
3

<CONNECTION-STRING>

연결 문자열 클러스터 .

<DATABASE-NAME>

컬렉션이 포함된 데이터베이스의 이름입니다.

<COLLECTION-NAME>

인덱싱된 필드 포함하는 컬렉션 의 이름입니다.

<INDEX-NAME>

인덱스의 이름입니다.

<FIELD-NAME>

인덱싱된 필드 의 이름입니다.

<QUERY-TEXT>

임베딩을 생성하고 시맨틱 검색에 사용할 문자열입니다.

<NUMBER-OF-CANDIDATES-TO-CONSIDER>

고려할 최근접 이웃의 수입니다.

<NUMBER-OF-DOCUMENTS-TO-RETURN>

결과에서 반환할 문서 수입니다.

4
node <FILE-NAME>.js

여기서 <FILE-NAME> 은 사용자가 만든 .js 파일 의 이름입니다.

예시

예시 들어 automated-embeddings-query.js 파일 에서 예시 쿼리 실행 하려면 다음 명령을 실행 .

node automated-embeddings-query.js
'{"title":"Day Watch","fullplot":"Anton belongs to the Forces of the Light as well as his powerful girlfriend and apprentice, but his son is a powerful teenager from the Darkness and Anton protects him. When the balance between Light and Darkness is affected by the death of some evil vampires, Anton is framed and accused of the murders, and he chases an ancient chalk that has the power of changing the destiny of its owner.","score":0.5449697971343994}'
`{"title":"Dungeons & Dragons","fullplot":"The Empire of Izmer has long been a divided land. The Mages - an elite group of magic-users - rule whilst the lowly commoners are powerless. Izmer's young Empress, Savina, wants equality and prosperity for all, but the evil Mage Profion is plotting to depose her and establish his own rule. The Empress possesses a scepter which controls Izmer's Golden Dragons. To challenge her rule, Profion must have the scepter, and tricks the Council of Mages into believing Savina is unfit to hold it. Knowing that Profion will bring death and destruction to Izmer, Savina must find the legendary Rod of Savrille, a mythical rod that has the power to control Red Dragons, a species even mightier than the Gold. Enter two thieves, Ridley and Snails, who unwittingly become instrumental in Savina's search for the Rod. Joined by a feisty Dwarf named Elwood, and helped by the Empress's expert tracker, the Elf Norda, the young heroes go in search of the Rod of Savrille. From the deadly maze of the Thieves Guild at Antius to an Elven Village, secret grotto and abandoned castles, Ridley and his band must outwit Profion's chief henchman Damodar at every turn while, back in Izmer, Profion prepares to do battle with the Empress. All depends on the Rod, but the outcome of the race to reach it first is far from certain, and Izmar's very survival hangs in the balance.","score":0.5414832830429077}`
'{"title":"Brave Story","fullplot":"A young boy attempts to change his destiny by entering a magic gateway to another world; but on his quest to find the Tower of Fortune and be granted any wish, he must conjure up all his bravery to battle demons, his friends, and ultimately himself.","score":0.5404887795448303}'
'{"title":"Justin and the Knights of Valour","fullplot":"Justin lives in a kingdom where bureaucrats rule and knights have been ousted. His dream is to be become one of the Knights of Valour, like his grandfather was, but his father Reginald, the chief counsel to the Queen, wants his son to follow in his footsteps and become a lawyer. After an inspiring visit to his beloved Grandmother and bidding farewell to his supposed lady-love Lara, Justin leaves home and embarks on a quest to become a knight. Along the way he meets the beautiful, feisty Talia, a quirky wizard called Melquiades, and the handsome Sir Clorex and is mentored by three monks; Blucher, Legantir and Braulio, who teach and test him in the ancient ways of the Knights of Valour. Whilst an unlikely candidate for knighthood, Justin must rise to the challenge quickly when banished former knight Sir Heraclio and his army, lead by Sota, return and threaten to destroy the Kingdom.","score":0.5374966859817505}'
'{"title":"Forest Warrior","fullplot":"John McKenna is a spiritual being who is able to transform into bear, wolf or eagle. He lives in the forests of Tanglewood and has dedicated his life to protect them. One day a gang of evil lumberjacks led by Travis Thorne arrive Tanglewood to chop the forest down. McKenna cannot let this happen, and together with his new friends - Lords of the Tanglewood, a band of children who love to play in the forest - he battles against Thorne and his evil gang.","score":0.5331881642341614}'
'{"title":"Forest Warrior","fullplot":"John McKenna is a spiritual being who is able to transform into bear, wolf or eagle. He lives in the forests of Tanglewood and has dedicated his life to protect them. One day a gang of evil lumberjacks led by Travis Thorne arrive Tanglewood to chop the forest down. McKenna cannot let this happen, and together with his new friends - Lords of the Tanglewood, a band of children who love to play in the forest - he battles against Thorne and his evil gang.","score":0.5331881642341614}'
`{"title":"Catatan (Harian) si Boy","fullplot":"A circle of friends risking their Friendship, Trust, Love and Hope in search of a legend. A young and privileged teenager with a golden heart, beset with challenges and tribulations we face today with the goal to open many young people's mind with inspirations and hopes that drive them in achieving their dreams. To get out of their comfort zone and finish what they started.","score":0.5322973728179932}`
`{"title":"Bionicle: Mask of Light","fullplot":"In a land of living machines, two young ones are chosen to seek the legendary Mask of Light to reveal the savior of all the lands from the dark forces of the Makuta. During the course of their adventure, they will call on the heroes of their people, the great Toa. These Toa, masters of nature's forces such as Fire, Wind, Earth & Water, try to protect the chosen ones as they seek their destiny.","score":0.5315042734146118}`
'{"title":"Fear No Evil","fullplot":"High school student turns out to be personification of Lucifer. Two arch angels in human form (as women) take him on.","score":0.5295513868331909}'
'{"title":"Tales of Vesperia: The First Strike","fullplot":"In a mythical kingdom, the mighty Imperial Knights harness a magical substance known as Aer to power their weapons and protect humanity from the monsters of the forest. But something strange is afoot. The Aer is somehow changing, causing the wilderness to waste away and stirring the woodland beasts to attack with greater frequency. As danger creeps steadily closer to civilization, two young recruits - Flynn, the rigid son of a fallen hero, and the rebellious and brash Yuri - must ride with their fellow Imperial Knights to distant ruins in hopes of uncovering the truth behind the transforming Aer. Some will not survive the thrilling journey. Some will be betrayed. If Flynn and Yuri cannot overcome their differences and learn to fight together, all will be lost for the people of the realm.","score":0.5276793241500854}'
1

예시

예를 들어, automated-embeddings-query.js라는 파일을 만드세요.

touch automated-embeddings-query.py
2
1import pymongo
2
3# connect to your Atlas cluster
4client = pymongo.MongoClient("<CONNECTION-STRING>")
5
6# define pipeline
7pipeline = [
8 {
9 '$vectorSearch': {
10 'index': '<INDEX-NAME>',
11 'path': '<FIELD-NAME>',
12 'query': '<QUERY-TEXT>',
13 'numCandidates': <NUMBER-OF-CANDIDATES-TO-CONSIDER>,
14 'limit': <NUMBER-OF-DOCUMENTS-TO-RETURN>
15 }
16 }
17]
18
19# run pipeline
20result = client["<DATABASE-NAME>"]["<COLLECTION-NAME>"].aggregate(pipeline)
21
22# print results
23for i in result:
24 print(i)
25

예시

예시 들어 automated-embeddings-query.py 파일 에서 다음 코드를 복사하여 붙여넣어 young heroes caught in epic struggles between light and darkness와 의미론적으로 유사한 영화에 대한 시맨틱 검색 위한 movies 컬렉션 의 fullplot 필드 에 대한 쿼리 정의합니다.

1import pymongo
2
3# connect to your Atlas cluster
4client = pymongo.MongoClient("<CONNECTION-STRING>")
5
6# define pipeline
7pipeline = [
8 {
9 '$vectorSearch': {
10 'index': 'movies_automated_embeddings',
11 'path': 'fullplot',
12 'query': "young heroes caught in epic struggles between light and darkness",
13 'numCandidates': 1000,
14 'limit': 10
15 },
16 },
17 {
18 '$project': {
19 '_id': 0,
20 'title': 1,
21 'fullplot': 1,
22 'score': {'$meta': 'vectorSearchScore'}
23 }
24 }
25]
26
27# run pipeline
28result = client["sample_mflix"]["movies"].aggregate(pipeline)
29
30# print results
31for i in result:
32 print(i)
33
3

<CONNECTION-STRING>

연결 문자열 클러스터 .

<DATABASE-NAME>

컬렉션이 포함된 데이터베이스의 이름입니다.

<COLLECTION-NAME>

인덱싱된 필드 포함하는 컬렉션 의 이름입니다.

<INDEX-NAME>

인덱스의 이름입니다.

<FIELD-NAME>

인덱싱된 필드 의 이름입니다.

<QUERY-TEXT>

임베딩을 생성하고 시맨틱 검색에 사용할 문자열입니다.

<NUMBER-OF-CANDIDATES-TO-CONSIDER>

고려할 최근접 이웃의 수입니다.

<NUMBER-OF-DOCUMENTS-TO-RETURN>

결과에서 반환할 문서 수입니다.

4
python <FILE-NAME>.py

여기서 <FILE-NAME> 은 사용자가 만든 .py 파일 의 이름입니다.

예시

예시 들어 automated-embeddings-query.py 파일 에서 예시 쿼리 실행 하려면 다음 명령을 실행 .

python automated-embeddings-query.js
{'title': 'Day Watch', 'fullplot': 'Anton belongs to the Forces of the Light as well as his powerful girlfriend and apprentice, but his son is a powerful teenager from the Darkness and Anton protects him. When the balance between Light and Darkness is affected by the death of some evil vampires, Anton is framed and accused of the murders, and he chases an ancient chalk that has the power of changing the destiny of its owner.', 'score': 0.5449697971343994}
{'title': 'Dungeons & Dragons', 'fullplot': "The Empire of Izmer has long been a divided land. The Mages - an elite group of magic-users - rule whilst the lowly commoners are powerless. Izmer's young Empress, Savina, wants equality and prosperity for all, but the evil Mage Profion is plotting to depose her and establish his own rule. The Empress possesses a scepter which controls Izmer's Golden Dragons. To challenge her rule, Profion must have the scepter, and tricks the Council of Mages into believing Savina is unfit to hold it. Knowing that Profion will bring death and destruction to Izmer, Savina must find the legendary Rod of Savrille, a mythical rod that has the power to control Red Dragons, a species even mightier than the Gold. Enter two thieves, Ridley and Snails, who unwittingly become instrumental in Savina's search for the Rod. Joined by a feisty Dwarf named Elwood, and helped by the Empress's expert tracker, the Elf Norda, the young heroes go in search of the Rod of Savrille. From the deadly maze of the Thieves Guild at Antius to an Elven Village, secret grotto and abandoned castles, Ridley and his band must outwit Profion's chief henchman Damodar at every turn while, back in Izmer, Profion prepares to do battle with the Empress. All depends on the Rod, but the outcome of the race to reach it first is far from certain, and Izmar's very survival hangs in the balance.", 'score': 0.5414832830429077}
{'title': 'Brave Story', 'fullplot': 'A young boy attempts to change his destiny by entering a magic gateway to another world; but on his quest to find the Tower of Fortune and be granted any wish, he must conjure up all his bravery to battle demons, his friends, and ultimately himself.', 'score': 0.5404887795448303}
{'title': 'Justin and the Knights of Valour', 'fullplot': 'Justin lives in a kingdom where bureaucrats rule and knights have been ousted. His dream is to be become one of the Knights of Valour, like his grandfather was, but his father Reginald, the chief counsel to the Queen, wants his son to follow in his footsteps and become a lawyer. After an inspiring visit to his beloved Grandmother and bidding farewell to his supposed lady-love Lara, Justin leaves home and embarks on a quest to become a knight. Along the way he meets the beautiful, feisty Talia, a quirky wizard called Melquiades, and the handsome Sir Clorex and is mentored by three monks; Blucher, Legantir and Braulio, who teach and test him in the ancient ways of the Knights of Valour. Whilst an unlikely candidate for knighthood, Justin must rise to the challenge quickly when banished former knight Sir Heraclio and his army, lead by Sota, return and threaten to destroy the Kingdom.', 'score': 0.5374966859817505}
{'title': 'Forest Warrior', 'fullplot': 'John McKenna is a spiritual being who is able to transform into bear, wolf or eagle. He lives in the forests of Tanglewood and has dedicated his life to protect them. One day a gang of evil lumberjacks led by Travis Thorne arrive Tanglewood to chop the forest down. McKenna cannot let this happen, and together with his new friends - Lords of the Tanglewood, a band of children who love to play in the forest - he battles against Thorne and his evil gang.', 'score': 0.5331881642341614}
{'title': 'Forest Warrior', 'fullplot': 'John McKenna is a spiritual being who is able to transform into bear, wolf or eagle. He lives in the forests of Tanglewood and has dedicated his life to protect them. One day a gang of evil lumberjacks led by Travis Thorne arrive Tanglewood to chop the forest down. McKenna cannot let this happen, and together with his new friends - Lords of the Tanglewood, a band of children who love to play in the forest - he battles against Thorne and his evil gang.', 'score': 0.5331881642341614}
{'title': 'Catatan (Harian) si Boy', 'fullplot': "A circle of friends risking their Friendship, Trust, Love and Hope in search of a legend. A young and privileged teenager with a golden heart, beset with challenges and tribulations we face today with the goal to open many young people's mind with inspirations and hopes that drive them in achieving their dreams. To get out of their comfort zone and finish what they started.", 'score': 0.5322973728179932}
{'title': 'Bionicle: Mask of Light', 'fullplot': "In a land of living machines, two young ones are chosen to seek the legendary Mask of Light to reveal the savior of all the lands from the dark forces of the Makuta. During the course of their adventure, they will call on the heroes of their people, the great Toa. These Toa, masters of nature's forces such as Fire, Wind, Earth & Water, try to protect the chosen ones as they seek their destiny.", 'score': 0.5315042734146118}
{'title': 'Fear No Evil', 'fullplot': 'High school student turns out to be personification of Lucifer. Two arch angels in human form (as women) take him on.', 'score': 0.5295513868331909}
{'title': 'Tales of Vesperia: The First Strike', 'fullplot': 'In a mythical kingdom, the mighty Imperial Knights harness a magical substance known as Aer to power their weapons and protect humanity from the monsters of the forest. But something strange is afoot. The Aer is somehow changing, causing the wilderness to waste away and stirring the woodland beasts to attack with greater frequency. As danger creeps steadily closer to civilization, two young recruits - Flynn, the rigid son of a fallen hero, and the rebellious and brash Yuri - must ride with their fellow Imperial Knights to distant ruins in hopes of uncovering the truth behind the transforming Aer. Some will not survive the thrilling journey. Some will be betrayed. If Flynn and Yuri cannot overcome their differences and learn to fight together, all will be lost for the people of the realm.', 'score': 0.5276793241500854}

이 페이지의 내용