Skip to content

MongoDB Atlas 向量存储节点#

¥MongoDB Atlas Vector Store node

MongoDB Atlas 向量搜索是 MongoDB Atlas 的一项功能,使用户能够存储和查询向量嵌入。使用此节点可以与 MongoDB Atlas 集合中的 Vector Search 索引进行交互。你可以在链中插入文档、检索文档,并将向量存储用作代理的工具。

¥MongoDB Atlas Vector Search is a feature of MongoDB Atlas that enables users to store and query vector embeddings. Use this node to interact with Vector Search indexes in your MongoDB Atlas collections. You can insert documents, retrieve documents, and use the vector store in chains or as a tool for agents.

本页包含 MongoDB Atlas 向量存储节点的节点参数以及更多资源的链接。

¥On this page, you'll find the node parameters for the MongoDB Atlas Vector Store node, and links to more resources.

Credentials

你可以在 此处 中找到此节点的身份验证信息。

¥You can find authentication information for this node here.

Parameter resolution in sub-nodes

Sub-nodes behave differently to other nodes when processing multiple items using an expression.

Most nodes, including root nodes, take any number of items as input, process these items, and output the results. You can use expressions to refer to input items, and the node resolves the expression for each item in turn. For example, given an input of five name values, the expression {{ $json.name }} resolves to each name in turn.

In sub-nodes, the expression always resolves to the first item. For example, given an input of five name values, the expression {{ $json.name }} always resolves to the first name.

先决条件#

¥Prerequisites

在使用此节点之前,请在你的 MongoDB Atlas 集合中创建一个 矢量搜索索引。请按照以下步骤创建触发器节点:

¥Before using this node, create a Vector Search index in your MongoDB Atlas collection. Follow these steps to create one:

  1. 登录 MongoDB Atlas 控制面板

¥Log in to the MongoDB Atlas dashboard.

  1. 选择你的组织和项目。

¥Select your organization and project.

  1. 查找 "搜索和矢量搜索" 部分。

¥Find "Search & Vector Search" section.

  1. 选择你的集群,然后单击 "前往搜索"。

¥Select your cluster and click "Go to search".

  1. 点击 "创建搜索索引"。

¥Click "Create Search Index".

  1. 选择 "向量搜索" 模式并使用可视化编辑器或 JSON 编辑器。例如:

¥Choose "Vector Search" mode and use the visual or JSON editors. For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
  "fields": [
    {
      "type": "vector",
      "path": "<field-name>",
      "numDimensions": 1536, // any other value
      "similarity": "<similarity-function>"
    }
  ]
}

  1. 根据你的嵌入模型调整 "dimensions" 值(例如,OpenAI 的 text-embedding-small-3 应设置为 1536)。

¥Adjust the "dimensions" value according to your embedding model (For example, 1536 for OpenAI's text-embedding-small-3).

  1. 为你的索引命名并创建。

¥Name your index and create.

配置节点时,请务必注意以下必填值:

¥Make sure to note the following values which are required when configuring the node:

  • 收藏名称

¥Collection name

  • 向量索引名

¥Vector index name

  • 嵌入和元数据的字段名称。

¥Field names for embeddings and metadata

节点使用模式#

¥Node usage patterns

你可以按照以下模式使用 MongoDB Atlas 向量存储节点:

¥You can use the MongoDB Atlas Vector Store node in the following patterns:

作为常规应用使用用于插入和检索文档的节点#

¥Use as a regular node to insert and retrieve documents

你可以将 MongoDB Atlas 向量存储用作常规节点来插入或获取文档。此模式将 MongoDB Atlas 向量存储置于常规连接流程中,而无需使用代理。

¥You can use the MongoDB Atlas Vector Store as a regular node to insert or get documents. This pattern places the MongoDB Atlas Vector Store in the regular connection flow without using an agent.

你可以在 此模板 的场景 1 中找到示例(该模板使用 Supabase Vector Store,但模式相同)。

¥You can see an example of this in scenario 1 of this template (the template uses the Supabase Vector Store, but the pattern is the same).

直接连接到 AI 代理作为工具#

¥Connect directly to an AI agent as a tool

你可以将 MongoDB Atlas 向量存储节点直接连接到 AI 代理 的工具连接器,以便在响应查询时使用向量存储作为资源。

¥You can connect the MongoDB Atlas Vector Store node directly to the tool connector of an AI agent to use the vector store as a resource when answering queries.

在这里,连接方式如下:AI 代理(工具连接器)-> MongoDB Atlas 向量存储节点。

¥Here, the connection would be: AI agent (tools connector) -> MongoDB Atlas Vector Store node.

使用检索器获取文档#

¥Use a retriever to fetch documents

你可以将 Vector Store 检索器 节点与 MongoDB Atlas 向量存储节点配合使用,从 MongoDB Atlas 向量存储节点获取文档。这通常与 Question and Answer 链 节点一起使用,用于从向量存储中获取与给定聊天输入匹配的文档。

¥You can use the Vector Store Retriever node with the MongoDB Atlas Vector Store node to fetch documents from the MongoDB Atlas Vector Store node. This is often used with the Question and Answer Chain node to fetch documents from the vector store that match the given chat input.

连接流程示例(链接的示例使用 Pinecone,但模式相同)如下所示:问答链(检索器连接器)-> 向量存储检索器(向量存储连接器)-> MongoDB Atlas 向量存储。

¥An example of the connection flow (the linked example uses Pinecone, but the pattern is the same) would be: Question and Answer Chain (Retriever connector) -> Vector Store Retriever (Vector Store connector) -> MongoDB Atlas Vector Store.

使用 Vector Store 问答工具回答问题#

¥Use the Vector Store Question Answer Tool to answer questions

另一种模式使用 Vector Store 问答工具 来汇总来自 MongoDB Atlas 向量存储节点的结果并回答问题。此模式并非直接连接 MongoDB Atlas 向量存储,而是使用专门用于汇总向量存储中数据的工具。

¥Another pattern uses the Vector Store Question Answer Tool to summarize results and answer questions from the MongoDB Atlas Vector Store node. Rather than connecting the MongoDB Atlas Vector Store directly as a tool, this pattern uses a tool specifically designed to summarize data in the vector store.

在这种情况下,连接流程(链接示例使用内存向量存储,但格式相同)如下所示:AI 代理(工具连接器)-> 向量存储问答工具(向量存储连接器)-> 内存向量存储。

¥The connections flow (the linked example uses the In-Memory Vector Store, but the pattern is the same) in this case would look like this: AI agent (tools connector) -> Vector Store Question Answer Tool (Vector Store connector) -> In-Memory Vector store.

节点参数#

¥Node parameters

Operation Mode#

This Vector Store node has four modes: Get Many, Insert Documents, Retrieve Documents (As Vector Store for Chain/Tool), and Retrieve Documents (As Tool for AI Agent). The mode you select determines the operations you can perform with the node and what inputs and outputs are available.

Get Many#

In this mode, you can retrieve multiple documents from your vector database by providing a prompt. The prompt is embedded and used for similarity search. The node returns the documents that are most similar to the prompt with their similarity score. This is useful if you want to retrieve a list of similar documents and pass them to an agent as additional context.

Insert Documents#

Use insert documents mode to insert new documents into your vector database.

Retrieve Documents (as Vector Store for Chain/Tool)#

Use Retrieve Documents (As Vector Store for Chain/Tool) mode with a vector-store retriever to retrieve documents from a vector database and provide them to the retriever connected to a chain. In this mode you must connect the node to a retriever node or root node.

Retrieve Documents (as Tool for AI Agent)#

Use Retrieve Documents (As Tool for AI Agent) mode to use the vector store as a tool resource when answering queries. When formulating responses, the agent uses the vector store when the vector store name and description match the question details.

重新排序结果#

¥Rerank Results

Enables reranking. If you enable this option, you must connect a reranking node to the vector store. That node will then rerank the results for queries. You can use this option with the Get Many, Retrieve Documents (As Vector Store for Chain/Tool) and Retrieve Documents (As Tool for AI Agent) modes.

获取多个参数#

¥Get Many parameters

  • MongoDB 集合:输入要使用的 MongoDB 集合的名称。

¥Mongo Collection: Enter the name of the MongoDB collection to use.

  • 向量索引名:输入 MongoDB Atlas 集合中的向量搜索索引的名称。

¥Vector Index Name: Enter the name of the Vector Search index in your MongoDB Atlas collection.

  • 嵌入字段:输入文档中包含向量嵌入的字段名称。

¥Embedding Field: Enter the field name in your documents that contains the vector embeddings.

  • 元数据字段:输入文档中包含文本元数据的字段名称。

¥Metadata Field: Enter the field name in your documents that contains the text metadata.

插入文档参数#

¥Insert Documents parameters

  • MongoDB 集合:输入要使用的 MongoDB 集合的名称。

¥Mongo Collection: Enter the name of the MongoDB collection to use.

  • 向量索引名:输入 MongoDB Atlas 集合中的向量搜索索引的名称。

¥Vector Index Name: Enter the name of the Vector Search index in your MongoDB Atlas collection.

  • 嵌入字段:输入文档中包含向量嵌入的字段名称。

¥Embedding Field: Enter the field name in your documents that contains the vector embeddings.

  • 元数据字段:输入文档中包含文本元数据的字段名称。

¥Metadata Field: Enter the field name in your documents that contains the text metadata.

检索文档参数(作为链/工具的向量存储)#

¥Retrieve Documents parameters (As Vector Store for Chain/Tool)

  • MongoDB 集合:输入要使用的 MongoDB 集合的名称。

¥Mongo Collection: Enter the name of the MongoDB collection to use.

  • 向量索引名:输入 MongoDB Atlas 集合中的向量搜索索引的名称。

¥Vector Index Name: Enter the name of the Vector Search index in your MongoDB Atlas collection.

  • 嵌入字段:输入文档中包含向量嵌入的字段名称。

¥Embedding Field: Enter the field name in your documents that contains the vector embeddings.

  • 元数据字段:输入文档中包含文本元数据的字段名称。

¥Metadata Field: Enter the field name in your documents that contains the text metadata.

检索文档(作为工具) (适用于 AI 代理)参数#

¥Retrieve Documents (As Tool for AI Agent) parameters

  • 名称:向量存储的名称。

¥Name: The name of the vector store.

  • 描述:向 LLM 解释此工具的功能。良好的、具体的描述有助于 LLM 更频繁地生成预期结果。

¥Description: Explain to the LLM what this tool does. A good, specific description allows LLMs to produce expected results more often.

  • MongoDB 集合:输入要使用的 MongoDB 集合的名称。

¥Mongo Collection: Enter the name of the MongoDB collection to use.

  • 向量索引名:输入 MongoDB Atlas 集合中的向量搜索索引的名称。

¥Vector Index Name: Enter the name of the Vector Search index in your MongoDB Atlas collection.

  • 限制:输入要从向量存储中检索的结果数量。例如,将其设置为 10 以获取十个最佳结果。

¥Limit: Enter how many results to retrieve from the vector store. For example, set this to 10 to get the ten best results.

节点选项#

¥Node options

选项#

¥Options

  • 元数据筛选器:根据元数据筛选结果。

¥Metadata Filter: Filters results based on metadata.

模板和示例#

¥Templates and examples

Template widget placeholder.

相关资源#

¥Related resources

参考:

¥Refer to:

¥LangChain's MongoDB Atlas Vector Search documentation for more information about the service.

¥MongoDB Atlas Vector Search documentation for more information about MongoDB Atlas Vector Search.

View n8n's Advanced AI documentation.

Self-hosted AI Starter Kit#

New to working with AI and using self-hosted n8n? Try n8n's self-hosted AI Starter Kit to get started with a proof-of-concept or demo playground using Ollama, Qdrant, and PostgreSQL.