Atlas Search 및 Vector Search 인덱스
이 페이지의 내용
개요
In this guide, you can learn how to create and manage Atlas Search and Vector Search indexes. These indexes allow you to use the following features:
Atlas Search: Perform fast, full-text searches
Atlas Vector Search: Perform semantic (similarity) searches on vector embeddings
Atlas Search and Vector Search indexes specify which fields to index, specify how these fields are indexed, and set other optional configurations.
참고
Atlas Search index-management methods run asynchronously. The driver methods can return a result before the desired action completes on the server.
This guide explains how to perform the following actions to manage your Atlas Search and Vector Search indexes:
참고
샘플 데이터
The examples in this guide use the embedded_movies
collection in the sample_mflix
database, which is one of the Atlas sample datasets. For instructions on importing the Atlas sample data, see Load Sample Data in the Atlas documentation.
검색 인덱스 모델 만들기
To create an Atlas Search or Vector Search index, you must first build a CreateSearchIndexModel
instance that sets your index specifications.
The CreateSearchIndexModel
has the following properties:
속성 | 유형 | 설명 |
---|---|---|
|
| Specifies the index definition. If you omit this setting, the driver creates an Atlas Search index with dynamic mappings. |
|
| Sets the index name. If you omit this setting, the driver sets the name to |
|
| Sets the index type. If you omit this setting, the driver creates an Atlas Search index by default. |
Atlas Search 필드 매핑에 대해 자세히 알아보려면 Atlas 설명서에서 필드 매핑 정의 를 참조하세요.
To learn more about defining Atlas Vector Search indexes, see How to Index Fields for Vector Search in the Atlas documentation.
예제 모델
The following example creates a CreateSearchIndexModel
instance to provide specifications for an index named search_idx
. The code specifies static mappings of the title
and released
fields:
var def = new BsonDocument { { "mappings", new BsonDocument { { "dynamic", false }, { "fields", new BsonDocument { { "title", new BsonDocument { {"type", "string" } } }, { "released", new BsonDocument { { "type", "date" } } } } } } } }; var indexModel = new CreateSearchIndexModel( "search_idx", SearchIndexType.Search, def );
The following example creates a CreateSearchIndexModel
instance to provide specifications for an index named vs_idx
. The code specifies the embedding path as plot_embedding
, indexes 1536
dimensions, and uses the "euclidean"
vector similarity function:
var def = new BsonDocument { { "fields", new BsonArray { new BsonDocument { { "type", "vector" }, { "path", "plot_embedding" }, { "numDimensions", 1536 }, { "similarity", "euclidean" } } } } }; var indexModel = new CreateSearchIndexModel( "vs_idx", SearchIndexType.VectorSearch, def );
검색 인덱스 만들기
You can create an Atlas Search or Vector Search index on a collection by calling the SearchIndexes.CreateOne()
method on an IMongoCollection
instance. This method accepts an index model as a parameter, specified in a CreateSearchIndexModel
instance.
예시
다음 예제에서는 embedded_movies
collection에 Atlas Search를 생성합니다. 이 코드는 인덱스 이름을 설정하고 동적 매핑을 활성화하는 CreateSearchIndexModel
를 생성합니다. 그런 다음 이 코드는 CreateSearchIndexModel
인스턴스를 SearchIndexes.CreateOne()
메서드에 전달하여 Atlas Search 인덱스를 생성합니다.
var indexModel = new CreateSearchIndexModel( "example_index", SearchIndexType.Search, new BsonDocument { { "mappings", new BsonDocument { { "dynamic", true }, } } } ); var result = movieCollection.SearchIndexes.CreateOne(indexModel); Console.WriteLine("Created Atlas Search index:\n{0}", result);
Created Atlas Search index: "example_index"
다중 검색 인덱스 만들기
You can create multiple Atlas Search and Vector Search indexes by calling the SearchIndexes.CreateMany()
method on an IMongoCollection
instance. This method accepts an IEnumerable
of CreateSearchIndexModel
instances as a parameter.
예시
이 예에서는 다음 조치를 수행합니다.
Creates a
CreateSearchIndexModel
instance that specifies an Atlas Search index namedas_idx
Creates a
CreateSearchIndexModel
instance that specifies an Atlas Vector Search index namedvs_idx
Passes a
List
of bothCreateSearchIndexModel
instances to theSearchIndexes.CreateMany()
methodCreates the Atlas Search and Vector Search indexes on the
embedded_movies
collection
var searchModel = new CreateSearchIndexModel( "as_idx", SearchIndexType.Search, new BsonDocument { { "mappings", new BsonDocument { { "dynamic", true }, } } } ); var vectorModel = new CreateSearchIndexModel( "vs_idx", SearchIndexType.VectorSearch, new BsonDocument { { "fields", new BsonArray { new BsonDocument { { "type", "vector" }, { "path", "plot_embedding" }, { "numDimensions", 1536 }, { "similarity", "euclidean" } } } } } ); var models = new List<CreateSearchIndexModel> { searchModel, vectorModel }; var indexes = movieCollection.SearchIndexes.CreateMany(models); Console.WriteLine("Created Search indexes:\n{0} {1}", indexes.ToArray());
Created Search indexes: as_idx vs_idx
검색 인덱스 나열
You can access information about a collection's existing Atlas Search and Vector Search indexes by calling the SearchIndexes.List()
method on the collection.
예시
The following example accesses information about the Atlas Search and Vector Search indexes created in the Create Multiple Search Indexes section of this page. The code calls the SearchIndexes.List()
method and prints a list of the Atlas Search and Vector Search indexes on the collection:
var indexesList = movieCollection.SearchIndexes.List().ToList(); foreach (var i in indexesList) { Console.WriteLine(i); }
{ "id": "...", "name": "as_idx", "status": "READY", "queryable": true, "latestDefinitionVersion": {...}, "latestDefinition": { "mappings": { "dynamic": true } }, "statusDetail": [...] } { "id": "...", "name": "vs_idx", "type": "vectorSearch", "status": "READY", "queryable": true, ..., "latestDefinition": { "fields": [{ "type": "vector", "path": "plot_embedding", "numDimensions": 1536, "similarity": "euclidean" }] }, "statusDetail": [...] }
검색 인덱스 업데이트
You can update an Atlas Search or Vector Search index by calling the SearchIndexes.Update()
method on an IMongoCollection
instance. This method accepts the following parameters:
업데이트할 인덱스의 이름
수정된 인덱스 정의 문서
예시
The following example updates the Vector Search index named vs_index
created in the Create Multiple Search Indexes section of this page. The code creates a new index definition document that instructs the index to use "dotProduct"
as the vector similarity function. Then, the code calls the SearchIndexes.Update()
method to update the index:
var updatedDef = new BsonDocument { { "fields", new BsonArray { new BsonDocument { { "type", "vector" }, { "path", "plot_embedding" }, { "numDimensions", 1536 }, { "similarity", "dotProduct" } } } } }; movieCollection.SearchIndexes.Update("vs_index", updatedDef);
검색 인덱스 삭제
You can delete an Atlas Search or Vector Search index by calling the SearchIndexes.DropOne()
method on an IMongoCollection
instance. This method accepts the name of the index to delete as a parameter.
예시
다음 예에서는 이 페이지 의 Atlas Search 인덱스 만들기 섹션에서 생성된 Atlas Search (이)라는 이름의 인덱스를 삭제합니다.example_index
이 코드는 인덱스 이름을 SearchIndexes.DropOne()
메서드에 전달하여 인덱스를 삭제합니다.
movieCollection.SearchIndexes.DropOne("example_index");
추가 정보
To learn about other indexes you can create by using the .NET/C# Driver, see the Indexes guide.
Atlas Search에 대해 자세히 알아보려면 다음 Atlas 설명서를 참조하세요.
To learn more about Atlas Vector Search, see the following Atlas documentation:
API 문서
이 가이드에서 사용되는 메서드 또는 유형에 대해 자세히 알아보려면 다음 API 문서를 참조하세요.