Skip to main content

llama-index tools database integration

Project description

Database Tool

This tool connects to a database (using SQLAlchemy under the hood) and allows an Agent to query the database and get information about the tables.

Usage

This tool has more extensive example usage documented in a Jupyter notebook here.

Here's an example usage of the DatabaseToolSpec.

from llama_index.tools.database import DatabaseToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

db_tools = DatabaseToolSpec(
    scheme="postgresql",  # Database Scheme
    host="localhost",  # Database Host
    port="5432",  # Database Port
    user="postgres",  # Database User
    password="FakeExamplePassword",  # Database Password
    dbname="postgres",  # Database Name
)
agent = FunctionAgent(
    tools=db_tools.to_tool_list(),
    llm=OpenAI(model="gpt-4.1"),
)

print(await agent.run("What tables does this database contain"))
print(await agent.run("Describe the first table"))
print(await agent.run("Retrieve the first row of that table"))

The tools available are:

list_tables: A tool to list the tables in the database schema describe_tables: A tool to describe the schema of a table load_data: A tool that accepts an SQL query and returns the result

This loader is designed to be used as a way to load data as a Tool in a Agent.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_tools_database-0.4.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_tools_database-0.4.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_tools_database-0.4.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_tools_database-0.4.1.tar.gz
Algorithm Hash digest
SHA256 9a024208163009131182322c5a82ccea6d53fcdfe20da131c74fa22c8a149ed5
MD5 aa9fe9b1a3624d6bda773a7e3c8e278a
BLAKE2b-256 b010084213e8d0865ab229733580d56de58428f5422747bb3c5580f619bdd5e4

See more details on using hashes here.

File details

Details for the file llama_index_tools_database-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_tools_database-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d2463a7c3b27763ca1e1f89e90a97d0c186a253525ccd933649061882046903
MD5 2d4c2d4da555183c50eaa262618baa2c
BLAKE2b-256 904428d797612f9e7f5d3d69ac43698a0ec977709cd633d8bad54fed191dca60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page