跳转到主要内容

概述

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

描述

PGSearchTool 被设想为一款强大的工具,用于在 PostgreSQL 数据库表中进行语义搜索。通过利用先进的检索与生成(RAG)技术,它旨在为查询数据库表内容提供一种高效的方式,特别针对 PostgreSQL 数据库。该工具的目标是通过语义搜索查询简化查找相关数据的过程,为需要在 PostgreSQL 环境中对大量数据集进行高级查询的用户提供宝贵的资源。

安装

crewai_tools 包将在发布时包含 PGSearchTool,可以使用以下命令进行安装
pip install 'crewai[tools]'
PGSearchTool 尚未在当前版本的 crewai_tools 包中提供。此安装命令将在工具发布后更新。

用法示例

以下是一个建议的示例,展示了如何使用 PGSearchTool 对 PostgreSQL 数据库中的表进行语义搜索
代码
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_uri字符串必需。一个字符串,表示要查询的 PostgreSQL 数据库的 URI。此参数为必需项,必须包含必要的身份验证详细信息和数据库位置。
table_name字符串必需。一个字符串,指定数据库中将执行语义搜索的表的名称。此参数也为必需项。

自定义模型和嵌入

该工具默认打算使用 OpenAI 进行嵌入和摘要。用户将可以选择使用配置字典来自定义模型,如下所示
代码
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", # or openai, ollama, ...
            config=dict(
                model="models/embedding-001",
                task_type="retrieval_document",
                # title="Embeddings",
            ),
        ),
    )
)