개요
In this guide, you can learn how to use the MongoDB Vector Search feature in the Java driver. The Aggregates builders class provides the the vectorSearch() helper method that you can use to create a $vectorSearch pipeline stage. This pipeline stage allows you to perform a semantic search on your documents. A semantic search is a type of search which locates information that is similar in meaning, but not necessarily identical, to your provided search term or phrase.
벡터 검색 수행
이 기능 사용하려면 벡터 검색 인덱스 만들고 벡터 임베딩을 인덱스 해야 합니다. 벡터 검색 인덱스 만드는 방법에 대한 학습은 MongoDB Atlas 설명서의 지원되는 클라이언트 섹션을 참조하세요. 벡터 임베딩에 대해 자세히 학습하려면 Atlas 설명서에서 벡터 검색을 위한 벡터 임베딩을 인덱스하는 방법 을 참조하세요.
벡터 임베딩에 벡터 검색 인덱스 생성한 후 다음 섹션에 표시된 대로 파이프라인 단계에서 이 인덱스 참조할 수 있습니다.
벡터 검색 예제
다음 예에서는 vectorSearch() 및 project() 메서드를 사용하여 벡터 검색 점수를 계산하는 집계 파이프라인을 구축하는 방법을 보여줍니다.
List<Double> queryVector = (asList(-0.0072121937, -0.030757688, -0.012945653)); String indexName = "mflix_movies_embedding_index"; FieldSearchPath fieldSearchPath = fieldPath("plot_embedding"); int numCandidates = 2; int limit = 1; VectorSearchOptions options = vectorSearchOptions().filter(gte("year", 2016)); List<Bson> pipeline = asList( vectorSearch( fieldSearchPath, queryVector, indexName, numCandidates, limit, options), project( metaVectorSearchScore("vectorSearchScore")));
다음 예시 집계 실행 하고 이전 집계 파이프라인 의 결과에서 벡터 검색 메타 점수를 출력하는 방법을 보여 줍니다.
Document found = collection.aggregate(pipeline).first(); double score = found.getDouble("vectorSearchScore").doubleValue(); System.out.println("vectorSearch score: " + score);
API 문서
이 가이드에서 사용되는 메서드 또는 유형에 대해 자세히 알아보려면 다음 API 문서를 참조하세요.