fenic.core.metrics
Metrics tracking for query execution and model usage.
This module defines classes for tracking various metrics during query execution, including language model usage, embedding model usage, operator performance, and overall query statistics.
Classes:
-
LMMetrics
–Tracks language model usage metrics including token counts and costs.
-
OperatorMetrics
–Metrics for a single operator in the query execution plan.
-
PhysicalPlanRepr
–Tree node representing the physical execution plan, used for pretty printing execution plan.
-
QueryMetrics
–Comprehensive metrics for an executed query.
-
RMMetrics
–Tracks embedding model usage metrics including token counts and costs.
LMMetrics
dataclass
LMMetrics(num_uncached_input_tokens: int = 0, num_cached_input_tokens: int = 0, num_output_tokens: int = 0, cost: float = 0.0, num_requests: int = 0)
Tracks language model usage metrics including token counts and costs.
Attributes:
-
num_uncached_input_tokens
(int
) –Number of uncached tokens in the prompt/input
-
num_cached_input_tokens
(int
) –Number of cached tokens in the prompt/input,
-
num_output_tokens
(int
) –Number of tokens in the completion/output
-
cost
(float
) –Total cost in USD for the LM API call
OperatorMetrics
dataclass
OperatorMetrics(operator_id: str, num_output_rows: int = 0, execution_time_ms: float = 0.0, lm_metrics: LMMetrics = LMMetrics(), rm_metrics: RMMetrics = RMMetrics(), is_cache_hit: bool = False)
Metrics for a single operator in the query execution plan.
Attributes:
-
operator_id
(str
) –Unique identifier for the operator
-
num_output_rows
(int
) –Number of rows output by this operator
-
execution_time_ms
(float
) –Execution time in milliseconds
-
lm_metrics
(LMMetrics
) –Language model usage metrics for this operator
-
is_cache_hit
(bool
) –Whether results were retrieved from cache
PhysicalPlanRepr
dataclass
PhysicalPlanRepr(operator_id: str, children: List[PhysicalPlanRepr] = list())
Tree node representing the physical execution plan, used for pretty printing execution plan.
QueryMetrics
dataclass
QueryMetrics(execution_time_ms: float = 0.0, num_output_rows: int = 0, total_lm_metrics: LMMetrics = LMMetrics(), total_rm_metrics: RMMetrics = RMMetrics(), _operator_metrics: Dict[str, OperatorMetrics] = dict(), _plan_repr: PhysicalPlanRepr = lambda: PhysicalPlanRepr(operator_id='empty')())
Comprehensive metrics for an executed query.
Includes overall statistics and detailed metrics for each operator in the execution plan.
Attributes:
-
execution_time_ms
(float
) –Total query execution time in milliseconds
-
num_output_rows
(int
) –Total number of rows returned by the query
-
total_lm_metrics
(LMMetrics
) –Aggregated language model metrics across all operators
Methods:
-
get_execution_plan_details
–Generate a formatted execution plan with detailed metrics.
-
get_summary
–Summarize the query metrics in a single line.
get_execution_plan_details
get_execution_plan_details() -> str
Generate a formatted execution plan with detailed metrics.
Produces a hierarchical representation of the query execution plan, including performance metrics and language model usage for each operator.
Returns:
-
str
(str
) –A formatted string showing the execution plan with metrics.
Source code in src/fenic/core/metrics.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
get_summary
get_summary() -> str
Summarize the query metrics in a single line.
Returns:
-
str
(str
) –A concise summary of execution time, row count, and LM cost.
Source code in src/fenic/core/metrics.py
127 128 129 130 131 132 133 134 135 136 137 138 |
|
RMMetrics
dataclass
RMMetrics(num_input_tokens: int = 0, num_requests: int = 0, cost: float = 0.0)
Tracks embedding model usage metrics including token counts and costs.
Attributes:
-
num_input_tokens
(int
) –Number of tokens to embed
-
cost
(float
) –Total cost in USD to embed the tokens