PGSearchTool

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_uristring强制。一个 string,表示要查询的 PostgreSQL 数据库的 URI。此参数将是强制性的,并且必须包含必要的认证详细信息和数据库位置。
table_namestring强制。一个 string,指定数据库中要执行语义搜索的表的名称。此参数也将是强制性的。

自定义模型和嵌入

该工具默认计划使用 OpenAI 进行嵌入和摘要。用户可以选择使用 config dictionary 来自定义模型,如下所示

代码
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",
            ),
        ),
    )
)