跳转到主要内容

概述

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-generativeai", # or openai, ollama, ...
            config=dict(
                model_name="gemini-embedding-001",
                task_type="RETRIEVAL_DOCUMENT",
                # title="Embeddings",
            ),
        ),
    )
)