PGVector 向量存储节点#
PGVector 是 PostgreSQL 的一个扩展。使用此节点与 PostgreSQL 数据库中的 PGVector 表进行交互。您可以将文档插入到向量表中,从向量表获取文档,检索文档以将它们提供给连接到链的检索器,或直接连接到智能体作为工具。
在此页面上,您将找到 PGVector 节点的节点参数和更多资源的链接。
凭证
您可以在此处找到此节点的身份验证信息。
子节点中的参数解析
子节点在使用表达式处理多个项目时,与其他节点的行为不同。
大多数节点(包括根节点)接受任意数量的项目作为输入,处理这些项目,并输出结果。您可以使用表达式引用输入项目,节点会依次为每个项目解析表达式。例如,给定五个 name
值的输入,表达式 {{ $json.name }}
会依次解析为每个名称。
在子节点中,表达式始终解析为第一个项目。例如,给定五个 name
值的输入,表达式 {{ $json.name }}
始终解析为第一个名称。
节点使用模式#
您可以在以下模式中使用 PGVector 向量存储节点。
作为常规节点用于插入和检索文档#
您可以将 PGVector 向量存储用作常规节点来插入或获取文档。此模式将 PGVector 向量存储放置在常规连接流中,而不使用智能体。
您可以在此模板的场景 1 中看到这方面的示例(该模板使用 Supabase 向量存储,但模式相同)。
直接连接到 AI 智能体作为工具#
You can connect the PGVector Vector Store node directly to the tool connector of an AI agent to use a vector store as a resource when answering queries.
Here, the connection would be: AI agent (tools connector) -> PGVector Vector Store node.
Use a retriever to fetch documents#
You can use the Vector Store Retriever node with the PGVector Vector Store node to fetch documents from the PGVector 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.
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) -> PGVector Vector Store.
Use the Vector Store Question Answer Tool to answer questions#
Another pattern uses the Vector Store Question Answer Tool to summarize results and answer questions from the PGVector Vector Store node. Rather than connecting the PGVector Vector Store directly as a tool, this pattern uses a tool specifically designed to summarizes data in the vector store.
The connections flow (the linked example uses the Simple 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) -> Simple Vector store.
Node parameters#
操作模式#
此向量存储节点有四种模式:获取多个、插入文档、检索文档(作为链/工具的向量存储)和检索文档(作为 AI 代理的工具)。您选择的模式决定了您可以使用节点执行的操作以及可用的输入和输出。
获取多个#
在此模式下,您可以通过提供提示从向量数据库中检索多个文档。提示会被嵌入并用于相似性搜索。节点返回与提示最相似的文档及其相似度分数。如果您想检索相似文档列表并将其作为额外上下文传递给代理,这非常有用。
插入文档#
使用插入文档模式将新文档插入到向量数据库中。
检索文档(作为链/工具的向量存储)#
使用检索文档(作为链/工具的向量存储)模式与向量存储检索器一起从向量数据库检索文档,并将其提供给连接到链的检索器。在此模式下,您必须将节点连接到检索器节点或根节点。
检索文档(作为 AI 代理的工具)#
使用检索文档(作为 AI 代理的工具)模式在回答查询时将向量存储用作工具资源。在制定响应时,当向量存储名称和描述与问题详细信息匹配时,代理会使用向量存储。
Rerank Results#
启用重新排序。如果您启用此选项,必须将重新排序节点连接到向量存储。该节点然后将对查询结果进行重新排序。您可以在 获取多个
、检索文档(作为链/工具的向量存储)
和 检索文档(作为 AI 代理的工具)
模式下使用此选项。
Get Many parameters#
- Table name: Enter the name of the table you want to query.
- Prompt: Enter your search query.
- Limit: Enter a number to set how many results to retrieve from the vector store. For example, set this to
10
to get the ten best results.
Insert Documents parameters#
- Table name: Enter the name of the table you want to query.
Retrieve Documents parameters (As Vector Store for Chain/Tool)#
- Table name: Enter the name of the table you want to query.
Retrieve Documents (As Tool for AI Agent) parameters#
- Name: The name of the vector store.
- Description: Explain to the LLM what this tool does. A good, specific description allows LLMs to produce expected results more often.
- Table Name: Enter the PGVector table to use.
- 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#
Collection#
A way to separate datasets in PGVector. This creates a separate table and column to keep track of which collection a vector belongs to.
- Use Collection: Select whether to use a collection (turned on) or not (turned off).
- Collection Name: Enter the name of the collection you want to use.
- Collection Table Name: Enter the name of the table to store collection information in.
Column Names#
The following options specify the names of the columns to store the vectors and corresponding information in:
- ID Column Name
- Vector Column Name
- Content Column Name
- Metadata Column Name
Metadata Filter#
在获取多个模式下可用。搜索数据时,使用此选项与文档相关的元数据进行匹配。
这是一个 AND
查询。如果您指定多个元数据过滤器字段,所有字段都必须匹配。
插入数据时,元数据是使用文档加载器设置的。有关加载文档的更多信息,请参阅默认数据加载器。
Templates and examples#
Related resources#
Refer to LangChain's PGVector documentation for more information about the service.
查看 n8n 的高级 AI 文档。
自托管 AI 入门套件#
刚开始使用 AI 和自托管 n8n?试试 n8n 的自托管 AI 入门套件,使用 Ollama、Qdrant 和 PostgreSQL 开始构建概念验证或演示环境。
🚀 与作者交流

📚 教程 💡 案例 🔧 技巧

⚡ 快答 🎯 定制 🚀 支持