mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-15 01:25:13 -05:00
Adds the following tools for Postgre (1) get_column_cardinality - to fetch the estimates of the distinct column counts in the table for particular column or all columns (2) list-query-stats - to obtain the query level statistics in a database. This tool requires pg_stat_statements extension as a prerequisite. <img width="2428" height="1368" alt="image" src="https://github.com/user-attachments/assets/5d9b22f0-6b09-4abe-8411-b1139387e259" /> <img width="3774" height="1010" alt="image" src="https://github.com/user-attachments/assets/b1d9fdf1-8a3b-4afe-ab98-63226a7e3705" /> PR Checklist [Y] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) [Y] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea [Y] Ensure the tests and linter pass [Y] Code coverage does not decrease (if any source code was changed) [Y] Appropriate docs were updated (if necessary) [Y] Make sure to add ! if this involve a breaking change 🛠️ Fixes https://github.com/googleapis/genai-toolbox/issues/1691 --------- Co-authored-by: Averi Kitsch <akitsch@google.com>
2.7 KiB
2.7 KiB
title, type, weight, description, aliases
| title | type | weight | description | aliases | |
|---|---|---|---|---|---|
| postgres-get-column-cardinality | docs | 1 | The "postgres-get-column-cardinality" tool estimates the number of unique values in one or all columns of a Postgres database table. |
|
About
The postgres-get-column-cardinality tool estimates the number of unique values
(cardinality) for one or all columns in a specific PostgreSQL table by using the
database's internal statistics. It's compatible with any of the following sources:
postgres-get-column-cardinality returns detailed information as JSON about column
cardinality values, ordered by estimated cardinality in descending order. The tool takes
the following input parameters:
schema_name(required): The schema name in which the table is present.table_name(required): The table name in which the column is present.column_name(optional): The column name for which the cardinality is to be found. If not provided, cardinality for all columns will be returned. Default:"".
Example
tools:
get_column_cardinality:
kind: postgres-get-column-cardinality
source: postgres-source
description: Estimates the number of unique values (cardinality) quickly for one or all columns in a specific PostgreSQL table by using the database's internal statistics, returning the results in descending order of estimated cardinality. Please run ANALYZE on the table before using this tool to get accurate results. The tool returns the column_name and the estimated_cardinality. If the column_name is not provided, the tool returns all columns along with their estimated cardinality.
The response is a json array with the following elements:
[
{
"column_name": "name of the column",
"estimated_cardinality": "estimated number of unique values in the column"
}
]
Notes
For accurate results, it's recommended to run ANALYZE on the table before using this
tool. The ANALYZE command updates the database statistics that this tool relies on
to estimate cardinality.
Reference
| field | type | required | description |
|---|---|---|---|
| kind | string | true | Must be "postgres-get-column-cardinality". |
| source | string | true | Name of the source the SQL should execute on. |
| description | string | true | Description of the tool that is passed to the LLM. |