PGSearchTool

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

描述

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

安装

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

pip install 'crewai[tools]'

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

示例用法

以下是一个展示如何在PostgreSQL数据库中的表上使用PGSearchTool进行语义搜索的示例:

Code
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进行嵌入和摘要。用户将可以选择使用如下配置字典自定义模型:

Code
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",
            ),
        ),
    )
)

这个页面有帮助吗?