From 16265d27f56c6560bb5c596be6055d8b8d47a052 Mon Sep 17 00:00:00 2001 From: Yuhong Sun Date: Sun, 2 Feb 2025 16:27:44 -0800 Subject: [PATCH] k --- .../versions/98a5008d8711_agent_tracking.py | 4 ++-- .../nodes/generate_initial_answer.py | 6 +++--- .../nodes/decompose_orig_question.py | 2 +- .../agent_search/deep_search/main/models.py | 10 +++++----- .../main/nodes/generate_refined_answer.py | 2 +- .../main/nodes/persist_agent_results.py | 16 ++++++++-------- backend/onyx/db/chat.py | 4 ++-- backend/onyx/db/models.py | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/backend/alembic/versions/98a5008d8711_agent_tracking.py b/backend/alembic/versions/98a5008d8711_agent_tracking.py index 3084bc47d..6daf2466f 100644 --- a/backend/alembic/versions/98a5008d8711_agent_tracking.py +++ b/backend/alembic/versions/98a5008d8711_agent_tracking.py @@ -25,8 +25,8 @@ def upgrade() -> None: sa.Column("persona_id", sa.Integer(), nullable=True), sa.Column("agent_type", sa.String(), nullable=False), sa.Column("start_time", sa.DateTime(timezone=True), nullable=False), - sa.Column("base_duration__s", sa.Float(), nullable=False), - sa.Column("full_duration__s", sa.Float(), nullable=False), + sa.Column("base_duration_s", sa.Float(), nullable=False), + sa.Column("full_duration_s", sa.Float(), nullable=False), sa.Column("base_metrics", postgresql.JSONB(), nullable=True), sa.Column("refined_metrics", postgresql.JSONB(), nullable=True), sa.Column("all_metrics", postgresql.JSONB(), nullable=True), diff --git a/backend/onyx/agents/agent_search/deep_search/initial/generate_initial_answer/nodes/generate_initial_answer.py b/backend/onyx/agents/agent_search/deep_search/initial/generate_initial_answer/nodes/generate_initial_answer.py index cfc908bd2..8bfc29a5e 100644 --- a/backend/onyx/agents/agent_search/deep_search/initial/generate_initial_answer/nodes/generate_initial_answer.py +++ b/backend/onyx/agents/agent_search/deep_search/initial/generate_initial_answer/nodes/generate_initial_answer.py @@ -265,9 +265,9 @@ def generate_initial_answer( agent_base_end_time = datetime.now() if agent_base_end_time and state.agent_start_time: - duration__s = (agent_base_end_time - state.agent_start_time).total_seconds() + duration_s = (agent_base_end_time - state.agent_start_time).total_seconds() else: - duration__s = None + duration_s = None agent_base_metrics = AgentBaseMetrics( num_verified_documents_total=len(relevant_docs), @@ -285,7 +285,7 @@ def generate_initial_answer( support_boost_factor=initial_agent_stats.agent_effectiveness.get( "support_ratio" ), - duration__s=duration__s, + duration_s=duration_s, ) return InitialAnswerUpdate( diff --git a/backend/onyx/agents/agent_search/deep_search/initial/generate_sub_answers/nodes/decompose_orig_question.py b/backend/onyx/agents/agent_search/deep_search/initial/generate_sub_answers/nodes/decompose_orig_question.py index 12e0f7e3d..63766602e 100644 --- a/backend/onyx/agents/agent_search/deep_search/initial/generate_sub_answers/nodes/decompose_orig_question.py +++ b/backend/onyx/agents/agent_search/deep_search/initial/generate_sub_answers/nodes/decompose_orig_question.py @@ -137,7 +137,7 @@ def decompose_orig_question( agent_refined_metrics=AgentRefinedMetrics( refined_doc_boost_factor=None, refined_question_boost_factor=None, - duration__s=None, + duration_s=None, ), log_messages=[ get_langgraph_node_log_string( diff --git a/backend/onyx/agents/agent_search/deep_search/main/models.py b/backend/onyx/agents/agent_search/deep_search/main/models.py index 048ca2d3d..d9ead45e6 100644 --- a/backend/onyx/agents/agent_search/deep_search/main/models.py +++ b/backend/onyx/agents/agent_search/deep_search/main/models.py @@ -10,9 +10,9 @@ class RefinementSubQuestion(BaseModel): class AgentTimings(BaseModel): - base_duration__s: float | None - refined_duration__s: float | None - full_duration__s: float | None + base_duration_s: float | None + refined_duration_s: float | None + full_duration_s: float | None class AgentBaseMetrics(BaseModel): @@ -23,13 +23,13 @@ class AgentBaseMetrics(BaseModel): verified_avg_score_base: float | None = None base_doc_boost_factor: float | None = None support_boost_factor: float | None = None - duration__s: float | None = None + duration_s: float | None = None class AgentRefinedMetrics(BaseModel): refined_doc_boost_factor: float | None = None refined_question_boost_factor: float | None = None - duration__s: float | None = None + duration_s: float | None = None class AgentAdditionalMetrics(BaseModel): diff --git a/backend/onyx/agents/agent_search/deep_search/main/nodes/generate_refined_answer.py b/backend/onyx/agents/agent_search/deep_search/main/nodes/generate_refined_answer.py index 0e5fda153..3cec84030 100644 --- a/backend/onyx/agents/agent_search/deep_search/main/nodes/generate_refined_answer.py +++ b/backend/onyx/agents/agent_search/deep_search/main/nodes/generate_refined_answer.py @@ -320,7 +320,7 @@ def generate_refined_answer( agent_refined_metrics = AgentRefinedMetrics( refined_doc_boost_factor=refined_agent_stats.revision_doc_efficiency, refined_question_boost_factor=refined_agent_stats.revision_question_efficiency, - duration__s=agent_refined_duration, + duration_s=agent_refined_duration, ) return RefinedAnswerUpdate( diff --git a/backend/onyx/agents/agent_search/deep_search/main/nodes/persist_agent_results.py b/backend/onyx/agents/agent_search/deep_search/main/nodes/persist_agent_results.py index 04fc76f33..5a8225548 100644 --- a/backend/onyx/agents/agent_search/deep_search/main/nodes/persist_agent_results.py +++ b/backend/onyx/agents/agent_search/deep_search/main/nodes/persist_agent_results.py @@ -49,9 +49,9 @@ def persist_agent_results(state: MainState, config: RunnableConfig) -> MainOutpu combined_agent_metrics = CombinedAgentMetrics( timings=AgentTimings( - base_duration__s=agent_base_duration, - refined_duration__s=agent_refined_duration, - full_duration__s=agent_full_duration, + base_duration_s=agent_base_duration, + refined_duration_s=agent_refined_duration, + full_duration_s=agent_full_duration, ), base_metrics=agent_base_metrics, refined_metrics=agent_refined_metrics, @@ -110,17 +110,17 @@ def persist_agent_results(state: MainState, config: RunnableConfig) -> MainOutpu logger.debug(log_message) if state.agent_base_metrics: - logger.debug(f"Initial loop: {state.agent_base_metrics.duration__s}") + logger.debug(f"Initial loop: {state.agent_base_metrics.duration_s}") if state.agent_refined_metrics: - logger.debug(f"Refined loop: {state.agent_refined_metrics.duration__s}") + logger.debug(f"Refined loop: {state.agent_refined_metrics.duration_s}") if ( state.agent_base_metrics and state.agent_refined_metrics - and state.agent_base_metrics.duration__s - and state.agent_refined_metrics.duration__s + and state.agent_base_metrics.duration_s + and state.agent_refined_metrics.duration_s ): logger.debug( - f"Total time: {float(state.agent_base_metrics.duration__s) + float(state.agent_refined_metrics.duration__s)}" + f"Total time: {float(state.agent_base_metrics.duration_s) + float(state.agent_refined_metrics.duration_s)}" ) return main_output diff --git a/backend/onyx/db/chat.py b/backend/onyx/db/chat.py index 353da4bbc..fb3f3dfd8 100644 --- a/backend/onyx/db/chat.py +++ b/backend/onyx/db/chat.py @@ -966,8 +966,8 @@ def log_agent_metrics( persona_id=persona_id, agent_type=agent_type, start_time=start_time, - base_duration__s=agent_timings.base_duration__s, - full_duration__s=agent_timings.full_duration__s, + base_duration_s=agent_timings.base_duration_s, + full_duration_s=agent_timings.full_duration_s, base_metrics=vars(agent_base_metrics) if agent_base_metrics else None, refined_metrics=vars(agent_refined_metrics) if agent_refined_metrics else None, all_metrics=vars(agent_additional_metrics) diff --git a/backend/onyx/db/models.py b/backend/onyx/db/models.py index 9089b3cd2..f8b5cb7c5 100644 --- a/backend/onyx/db/models.py +++ b/backend/onyx/db/models.py @@ -1851,8 +1851,8 @@ class AgentSearchMetrics(Base): ) agent_type: Mapped[str] = mapped_column(String) start_time: Mapped[datetime.datetime] = mapped_column(DateTime(timezone=True)) - base_duration__s: Mapped[float] = mapped_column(Float) - full_duration__s: Mapped[float] = mapped_column(Float) + base_duration_s: Mapped[float] = mapped_column(Float) + full_duration_s: Mapped[float] = mapped_column(Float) base_metrics: Mapped[JSON_ro] = mapped_column(postgresql.JSONB(), nullable=True) refined_metrics: Mapped[JSON_ro] = mapped_column(postgresql.JSONB(), nullable=True) all_metrics: Mapped[JSON_ro] = mapped_column(postgresql.JSONB(), nullable=True)