Skip to content
CrewAI 文档版本 跟随上游 源快照 b20622d2 更新于 2026-10-18

PG RAG 搜索

PGSearchTool 旨在搜索 PostgreSQL 数据库并返回最相关的结果。

概述

NOTE

PGSearchTool 目前仍在开发中。本文档概述了预期的功能和接口。 随着开发的推进,请注意部分功能可能尚不可用,或可能发生变化。

描述

PGSearchTool 被设想为一种强大的工具,用于在 PostgreSQL 数据库表中进行语义搜索。通过利用先进的检索与生成(RAG)技术, 它旨在提供一种高效的方式来查询数据库表内容,并专门针对 PostgreSQL 数据库进行了定制。 该工具的目标是简化通过语义搜索查询查找相关数据的过程,为需要在 PostgreSQL 环境中对 大规模数据集执行高级查询的用户提供有价值的资源。

安装

crewai_tools 包将在该工具发布时包含 PGSearchTool,可使用以下命令安装:

shell
pip install 'crewai[tools]'

NOTE

PGSearchTool 在当前版本的 crewai_tools 包中尚不可用。该工具发布后,此安装命令将更新。

用法示例

下面是一个建议的示例,展示如何使用 PGSearchTool 在 PostgreSQL 数据库中的某个表上执行语义搜索:

python
from crewai_tools import PGSearchTool

# Initialize the tool with the database URI and the target table name
tool = PGSearchTool(
    db_uri='postgresql://user:password@localhost:5432/mydatabase', 
    table_name='employees'
)

参数

PGSearchTool 在设计上需要以下参数才能运行:

参数类型描述
db_uristring必填。表示要查询的 PostgreSQL 数据库 URI 的字符串。该参数为必填项,必须包含必要的身份认证详细信息以及数据库的位置。
table_namestring必填。指定要在其上执行语义搜索的数据库中表名的字符串。该参数同样为必填项。

自定义模型和嵌入

该工具默认计划使用 OpenAI 进行嵌入和摘要。用户可以通过如下配置字典自定义模型:

python
tool = PGSearchTool(
    config=dict(
        llm=dict(
            provider="ollama", # or google, openai, anthropic, llama2, ...
            config=dict(
                model="llama2",
                # temperature=0.5,
                # top_p=1,
                # stream=true,
            ),
        ),
        embedder=dict(
            provider="google-generativeai", # or openai, ollama, ...
            config=dict(
                model_name="gemini-embedding-001",
                task_type="RETRIEVAL_DOCUMENT",
                # title="Embeddings",
            ),
        ),
    )
)

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。