Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /

MongoDB Vector Search

이 가이드 에서는 Java 운전자 의 MongoDB Vector Search 기능 사용하는 방법을 학습 수 있습니다. Aggregates 빌더 클래스는 $vectorSearch 파이프라인 단계를 만드는 데 사용할 수 있는 vectorSearch() 헬퍼 메서드를 제공합니다. 이 파이프라인 단계에서는 문서들에서 시맨틱 검색 을 수행할 수 있습니다. 시맨틱 검색 제공된 검색 또는 구문 텀 의미는 비슷하지만 반드시 동일하지는 않은 정보를 찾는 검색 유형입니다.

중요

기능 호환성

이 기능을 지원하는 MongoDB Atlas 버전에 대한 자세한 내용은 MongoDB Atlas 설명서의 제한 사항을 참조하세요.

이 기능을 사용하려면 벡터 검색 인덱스를 만들고 벡터 임베딩을 인덱스해야 합니다. 프로그래밍 방식으로 벡터 검색 인덱스를 학습하는 방법에 대한 자세한 내용은 인덱스 가이드의 MongoDB 검색 및 벡터 검색 인덱스 섹션을 참조하세요. 벡터 임베딩에 대해 자세히 알아보려면 Atlas 문서의 벡터 검색을 위해 벡터 임베딩을 인덱스하는 방법을 참조하세요.

벡터 임베딩에 벡터 검색 인덱스 생성한 후 다음 섹션에 표시된 대로 파이프라인 단계에서 이 인덱스 참조할 수 있습니다.

다음 예에서는 vectorSearch()project() 메서드를 사용하여 벡터 검색 점수를 계산하는 집계 파이프라인을 구축하는 방법을 보여줍니다.

// Create an instance of the BinaryVector class as the query vector
BinaryVector queryVector = BinaryVector.floatVector(
new float[]{0.0001f, 1.12345f, 2.23456f, 3.34567f, 4.45678f});
// Specify the index name for the vector embedding index
String indexName = "mflix_movies_embedding_index";
// Specify the path of the field to search on
FieldSearchPath fieldSearchPath = fieldPath("plot_embedding");
// Limit the number of matches to 1
int limit = 1;
// Create a pre-filter to only search within a subset of documents
VectorSearchOptions options = exactVectorSearchOptions()
.filter(gte("year", 2016));
// Create the vectorSearch pipeline stage
List<Bson> pipeline = asList(
vectorSearch(
fieldSearchPath,
queryVector,
indexName,
limit,
options),
project(
metaVectorSearchScore("vectorSearchScore")));

쿼리 벡터 유형

앞의 예시 에서는 쿼리 벡터로 제공 BinaryVector 인스턴스 만들지만 Double 인스턴스의 List 을 만들 수도 있습니다. 그러나 저장 효율성 높이려면 BinaryVector 유형을 사용하는 것이 좋습니다.

다음 예시 집계 실행 하고 이전 집계 파이프라인 의 결과에서 벡터 검색 메타 점수를 출력하는 방법을 보여 줍니다.

Document found = collection.aggregate(pipeline).first();
double score = found.getDouble("vectorSearchScore").doubleValue();
System.out.println("vectorSearch score: " + score);

Java 드라이버 벡터 검색 예제

Java 운전자 사용하여 Atlas 벡터 검색을 수행하는 방법에 대한 더 많은 튜토리얼을 찾으려면 Atlas 설명서를 참조하세요.

자동 임베딩 MongoDB Vector Search 인덱스 쿼리하여 텍스트 검색을 위한 벡터 생성을 자동화할 수 있습니다. 자동 임베딩 인덱스 만드는 방법에 대한 학습 MongoDB 자동 임베딩 검색 인덱스 모델을 참조하세요.

다음 예시 plot 필드 에서 time travel 구문과의 의미적 유사성을 검색하는 MongoDB Vector Search 쿼리 구성합니다. 이 쿼리 auto_embedding_index이라는 plot 필드 에 자동 임베딩된 MongoDB Vector Search 인덱스 사용합니다.

List<Bson> pipeline = asList(
vectorSearch(
fieldPath("plot"),
textQuery("time travel"),
"auto_embedding_index",
10L,
approximateVectorSearchOptions(150L)
),
project(
fields(include("title", "plot"), excludeId())
)
);
List<Document> results = collection.aggregate(pipeline).into(new ArrayList<>());
for (Document doc : results) {
System.out.println("Title: " + doc.getString("title"));
System.out.println("Plot: " + doc.getString("plot"));
System.out.println("---");
}
Title: Manuel on the Island of Wonders
Plot: Manuel's fantasy travel through Time goes from Long Ago (Episode 1 - O jardim proibido / Le Jardin interdit) through Now (Episode 2 - O pique-nique dos sonhos / Le Pique-nique des rèves), ...
---
Title: 11 Minutes Ago
Plot: Traveling in 11-minute increments, a time-tumbler from 48-years in the future spends two years of his life weaving through a two-hour wedding reception.
---
Title: Time Freak
Plot: A neurotic inventor creates a time machine and gets lost traveling around yesterday.
---
Title: Timecrimes
Plot: A man accidentally gets into a time machine and travels back in time nearly an hour. Finding himself will be the first of a series of disasters of unforeseeable consequences.
---
Title: The Little Girl Who Conquered Time
Plot: A high-school girl acquires the ability to time travel.
---
Title: Time Traveller
Plot: A high-school girl acquires the ability to time travel.
---
Title: Je t'aime je t'aime
Plot: Recovering from an attempted suicide, a man is selected to participate in a time travel experiment that has only been tested on mice. A malfunction in the experiment causes the man to ...
---
Title: A.P.E.X.
Plot: A time-travel experiment in which a robot probe is sent from the year 2073 to the year 1973 goes terribly wrong thrusting one of the project scientists, a man named Nicholas Sinclair into a...
---
Title: The Ah of Life
Plot: Theoretical mathematician, Nigel Kline finds himself the subject of his own vertical time study. Entering into Einstein's relativity, three versions of Nigel face off with each other, weaving time and space in a world of fluid moments.
---
Title: About Time
Plot: At the age of 21, Tim discovers he can travel in time and change what happens and has happened in his own life. His decision to make his world a better place by getting a girlfriend turns out not to be as easy as you might think.
---

참고

자동 임베딩 인덱스 사용하는 경우, 해당 텍스트의 벡터 표현 대신 검색 할 텍스트를 직접 제공하세요.

MongoDB Vector Search 인덱스 자동 임베딩에 대한 자세한 내용은 인덱스 가이드 의 MongoDB 검색 인덱스 모델 자동 임베딩 섹션을 참조하세요.

이 가이드에서 사용되는 메서드 또는 유형에 대해 자세히 알아보려면 다음 API 문서를 참조하세요.

돌아가기

MongoDB Search

이 페이지의 내용