跳转至

PGSearchTool

开发中

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

描述

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

安装

包含PGSearchTool的crewai_tools包可以通过以下命令安装:

pip install 'crewai[tools]'

(注意:PGSearchTool在当前版本的crewai_tools包中尚不可用。一旦工具发布,此安装命令将进行更新。)

示例用法

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

from crewai_tools import PGSearchTool

# 使用数据库URI和目标表名初始化工具
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", # 或 google, openai, anthropic, llama2, ...
            config=dict(
                model="llama2",
                # temperature=0.5,
                # top_p=1,
                # stream=true,
            ),
        ),
        embedder=dict(
            provider="google", # 或 openai, ollama, ...
            config=dict(
                model="models/embedding-001",
                task_type="retrieval_document",
                # title="Embeddings",
            ),
        ),
    )
)