Skip to main content

Module telemetry

Module telemetry 

Source
Expand description

遥测与反馈模块:提供可选的、应用可控的用户反馈收集机制。

§Telemetry and Feedback Module

This module provides optional, application-controlled telemetry and feedback collection capabilities. Privacy is paramount - the runtime MUST NOT force telemetry collection.

§Overview

The feedback system enables:

  • Collection of user preferences (thumbs up/down, ratings)
  • Tracking of choice selections in multi-candidate responses
  • Recording corrections and regeneration requests
  • Custom feedback integration with external systems

§Design Principles

  • Opt-in Only: No telemetry is collected unless explicitly configured
  • Application-Controlled: The application decides what to collect and where to send
  • Stable Linkage: client_request_id provides correlation across events
  • Pluggable Sinks: Implement FeedbackSink for custom destinations

§Key Components

ComponentDescription
FeedbackEventTyped feedback event enum
FeedbackSinkTrait for feedback destinations
NoopFeedbackSinkDefault no-op sink (no collection)
InMemoryFeedbackSinkIn-memory sink for testing
ConsoleFeedbackSinkConsole logging sink for debugging
CompositeFeedbackSinkMulti-destination composite sink

§Feedback Types

TypeDescription
ThumbsFeedbackSimple positive/negative feedback
RatingFeedbackNumeric rating (e.g., 1-5 stars)
ChoiceSelectionFeedbackMulti-candidate selection tracking
CorrectionFeedbackUser corrections to model output
RegenerateFeedbackRegeneration request tracking
TextFeedbackFree-form text feedback

§Example

use ai_lib_rust::telemetry::{FeedbackEvent, ThumbsFeedback, set_feedback_sink, InMemoryFeedbackSink};
use std::sync::Arc;

// Configure feedback collection (opt-in)
let sink = Arc::new(InMemoryFeedbackSink::new(100));
set_feedback_sink(sink.clone());

// Record feedback
let feedback = ThumbsFeedback::thumbs_up("req-123")
    .with_reason("Helpful response");
// report_feedback(FeedbackEvent::Thumbs(feedback)).await?;

Structs§

ChoiceSelectionFeedback
Feedback for multi-candidate selection.
CompositeFeedbackSink
Composite sink for multiple destinations.
ConsoleFeedbackSink
Console sink for debugging.
CorrectionFeedback
Correction feedback.
InMemoryFeedbackSink
In-memory sink for testing.
NoopFeedbackSink
No-op sink.
RatingFeedback
Rating feedback (e.g., 1-5 stars).
RegenerateFeedback
Regeneration feedback.
StopFeedback
Stop generation feedback.
TextFeedback
Free-form text feedback.
ThumbsFeedback
Thumbs up/down feedback.

Enums§

FeedbackEvent
Typed feedback events (extensible).

Traits§

FeedbackSink
Feedback sink trait.

Functions§

get_feedback_sink
noop_sink
report_feedback
set_feedback_sink