您可以在MongoDB Community Edition中安装搜索进程mongot。搜索进程可作为映像部署在Docker中。mongot进程支持使用您自己的嵌入或自动嵌入进行全文搜索和语义搜索。
Install MongoDB Search and Vector Search with Docker
注意
要更快地使用用于实验的部署,请参阅以下自管理部署教程:
开始之前
在部署mongot 之前,您必须完成以下步骤:
安装Docker和Docker Compose。
If you want MongoDB Vector Search to automatically generate embeddings for text data in your collection, create endpoint service API keys. To learn more, see Automated Embedding.
重要
自动嵌入处于预览状态。在预览期间,功能和相应的文档可能随时更改。要学习;了解更多信息,请参阅预览功能。
If you don't already have the keys, create the endpoint service API keys from the Atlas UI. We recommend that you create two keys, one for generating embeddings at index-time and another for generating embeddings at query-time, from two Atlas projects.
注意
用于生成嵌入的提供商终结点取决于您是从Atlas用户界面创建API密钥,还是直接从 Voyage AI创建 API 密钥。
步骤
警告
This procedure provides a simple and insecure default configuration that does not enable access control. The steps create a deployment intended for local experimentation only.
Before exposing these containers and using your setup in production, see the following resources to secure your deployment:
Download the MongoDB Docker image.
要下载MongoDB Docker映像,运行以下命令:
docker pull mongodb/mongodb-community-server:latest
注意
You must have a minimum of MongoDB 8.2+ to use MongoDB Search with an on-prem deployment. For more information, see MongoDB Search Compatibility.
有关使用Docker安装MongoDB的更多详细信息,请参阅使用Docker安装MongoDB Community。
创建mongod配置文件。
要创建配置文件,请将以下代码保存到 mongod.conf 或您的首选位置。
# MongoDB Configuration File # Network configuration net: port: 27017 bindIpAll: true # Equivalent to --bind_ip_all # Replica set configuration replication: replSetName: rs0 # Search configuration parameters setParameter: # Server parameters to advise mongod of mongot availability for search index management and querying searchIndexManagementHostAndPort: mongot-community.search-community:27028 mongotHost: mongot-community.search-community:27028 skipAuthenticationToSearchIndexManagementServer: false useGrpcForSearch: true searchTLSMode: disabled
Start your mongod.
要启动 mongod:
Replace
<your_admin_username>with the username you want to specify for your admin user.Replace
<your_admin_password>with the password you want to specify for your admin user.Replace
</path/to/data/db>with the path to the local directory for the mounted volume.Replace
</path/to/mongod.conf>with the path to the configuration file you created above.
docker run --rm \ --name mongod \ -v </path/to/mongod.conf>:/etc/mongod.conf:ro \ -v </path/to/data/db>:/data/db \ -p 27017:27017 \ --network search-community \ mongodb/mongodb-community-server:latest \ --config /etc/mongod.conf \ --replSetMember=mongod.search-community:27017
Create a user for the mongot process on your MongoDB deployment.
mongot must be able to connect to your MongoDB deployment through a user with the searchCoordinator role.
运行以下命令以连接到 admin数据库:
use admin
要创建具有 searchCoordinator角色的用户:
Replace
<your-mongot-username>with a username for yourmongotuser.将
<your-mongot-password>替换为您在步骤 5 中的passwordFile中指定的密码。运行以下命令:
db.createUser( { user: "<mongot_username>", pwd: "<mongot_password>", roles: [ "searchCoordinator" ] } )
For more information on creating users, see Create a User on Self-Managed Deployments.
指定搜索配置选项。
您可以使用 YAML 配置文件配置 mongot。您必须将在上一步中指定的用户名指定为 syncSource.replicaSet.username。您还必须将上一步中创建的 passwordFile 指定为 syncSource.replicaSet.passwordFile。
For more information on mongot configuration options, see mongot Options.
示例,您可以将设置调整为本地配置,如下所示:
# mongot.conf syncSource: replicaSet: hostAndPort: "mongod.search-community:27017" scramAuth: username: "mongotUser" passwordFile: "/passwordFile" authSource: "admin" tls: enabled: false replicationReader: readPreference: "secondaryPreferred" storage: dataPath: "/data/mongot" server: grpc: address: "mongot-community.search-community:27028" tls: mode: "disabled" metrics: enabled: true address: "mongot-community.search-community:9946" healthCheck: address: "mongot-community.search-community:8080" logging: verbosity: INFO
将文件保存到 mongot.config 或您的首选文件位置。
两个容器在同一 search-community Docker网络上运行。
启动mongot进程。
要在 Community 二进制文件中启动 Search,mongot:
Replace
</path/to/data/mongot>with the path to the local directory for the mounted volume to storemongotdata.将
</path/to/mongot.conf>替换为您在上一步中创建的mongot配置文件的路径。将
</path/to/passwordFile>替换为您创建的密码文件的路径。
docker run --rm \ --name mongot-community \ -v </path/to/data/mongot>:/data/mongot \ -v </path/to/mongot.conf>:/mongot-community/config.default.yml \ -v </path/to/passwordFile>:/passwordFile:ro \ --network search-community \ -p 8080:8080 \ -p 9946:9946 \ mongodb/mongodb-community-search:latest
此命令:
挂载卷。
从本地卷挂载配置文件。
指定端口范围。
公开指标端口。
使用名为
mongot-community的容器在search-communityDocker网络上启动容器。
Verify the health of the mongot process.
To verify, send a request by using a HTTP client or curl to the /health endpoint. For example, send a curl request similar to the following sample request:
curl localhost:8080/health
端点在响应中返回以下内容之一:
SERVING, if themongotprocess is runningmongotmight not serve queries as it doesn't check the status of the indexes, which must be inReadystate to serve queries.NOT_SERVING, if themongotprocess isn't running
For more information, see Verify Your mongot Connection.
Uninstall MongoDB Search and MongoDB Vector Search with Docker
To completely remove MongoDB Search and MongoDB Vector Search from a system, remove the container image, the configuration files, and any data or log directories. The following section guides you through the necessary steps.
Drop the mongotUser user.
要删除 mongotUser 用户,运行以下命令:
use admin db.dropUser("mongotUser")
For details, see db.dropUser().
后续步骤
创建MongoDB Search 索引