Skip to content

Conversation

june616
Copy link

@june616 june616 commented Oct 16, 2025

Description

Add comprehensive LLM usage and retry tracking for the indexing stage, providing complete performance observability.

Related Issues

[Feature Request]: Enhance LLM usage logging in indexing workflows #2103

Proposed Changes

  1. Data Structure Extensions
  • Added to PipelineRunStats:
    • total_llm_retries: Total retry attempts across all workflows
    • llm_usage_by_workflow[workflow]["retries"]: Per-workflow retry count
  1. Context Injection Mechanism
  • Added inject_llm_context() helper function
  • Centralized context injection in run_pipeline.py
  • Propagated through ModelManager to all LLM models
  1. Retry Tracking
  • Added _record_retries() common method to Retry base class
  • All retry strategies (Exponential, Native, Random, Incremental) record uniformly
  • Used finally blocks to ensure both successful and failed retries are tracked
  1. Enhanced Logging
  • Output LLM usage (including retries) after each workflow
  • Output total statistics after pipeline completion
  • Added exception logging for context injection failures

Sample output in stats.json:

{
  "total_llm_calls": 20,
  "total_prompt_tokens": 104652,
  "total_completion_tokens": 9691,
  "total_llm_retries": 8,
  "llm_usage_by_workflow": {
    "extract_graph": {
      "llm_calls": 5,
      "prompt_tokens": 66766,
      "completion_tokens": 5757,
      "retries": 6
    }
  }
}

Checklist

I've validated the functionality with end-to-end indexing runs.

  • I have tested these changes locally.
  • I have reviewed the code changes.
  • I have updated the documentation (if necessary).
  • [N/A] I have added appropriate unit tests (if applicable).

Note: Both Linux and Windows smoke tests are failing with the same root cause: "ValidationError: API Key is required for chat when using api_key authentication". My changes do not affect configuration validation or authentication logic.

Additional Notes

[Add any additional notes or context that may be helpful for the reviewer(s).]

@june616 june616 requested a review from a team as a code owner October 16, 2025 17:44
@june616
Copy link
Author

june616 commented Oct 16, 2025

@microsoft-github-policy-service agree company="Microsoft"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant