Enhance the PandasAI library with the Semantic Agent for more accurate and interpretable results.
SemanticAgent
(currently in beta) extends the capabilities of the PandasAI library by adding a semantic layer to its results. Unlike the standard Agent
, the SemanticAgent
generates a JSON query, which can then be used to produce Python or SQL code. This approach ensures more accurate and interpretable outputs.
Note: Usage of the Semantic Agent in production is subject to a license. For more details, refer to the license documentation. If you plan to use it in production, contact us.
SemanticAgent
is similar to creating an instance of an Agent
.
SemanticAgent
considers all dataframes passed to it and generates an appropriate schema.
schema
parameter during the instantiation of the SemanticAgent
.
SemanticAgent
:
SemanticAgent
is a comprehensive representation of the data, including tables, columns, measures, dimensions, and relationships between tables. Here’s a breakdown of its components:
count
, avg
, sum
, max
, min
).left
, right
, inner
).GROUP BY
clause, these would be the columns listed.
timeDimensions
entry specifies a time period and its granularity. The dateRange
field allows various formats, including specific dates such as ["2022-01-01", "2023-03-31"]
, relative periods like “last week”, “last month”, “this month”, “this week”, “today”, “this year”, and “last year”.
Example:
WHERE
clauses. Each filter specifies a member, an operator, and a set of values. The operators allowed include: “equals”, “notEquals”, “contains”, “notContains”, “startsWith”, “endsWith”, “gt” (greater than), “gte” (greater than or equal to), “lt” (less than), “lte” (less than or equal to), “set”, “notSet”, “inDateRange”, “notInDateRange”, “beforeDate”, and “afterDate”.
ORDER BY
clauses. Each entry in the order
array specifies an identifier and the direction of sorting. The direction can be either “asc” for ascending or “desc” for descending order.