Skip to main content

oxirs_embed/
enterprise_knowledge_customer.rs

1//! Customer, purchase, preference, and recommendation types for enterprise knowledge.
2
3use crate::Vector;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// Customer embedding with behavior context
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CustomerEmbedding {
11    /// Customer unique identifier
12    pub customer_id: String,
13    /// Customer name (anonymized if needed)
14    pub name: String,
15    /// Customer segment
16    pub segment: CustomerSegment,
17    /// Purchase history
18    pub purchase_history: Vec<Purchase>,
19    /// Preferences
20    pub preferences: CustomerPreferences,
21    /// Behavior metrics
22    pub behavior_metrics: BehaviorMetrics,
23    /// Customer embedding vector
24    pub embedding: Vector,
25    /// Predicted lifetime value
26    pub predicted_ltv: f64,
27    /// Churn risk
28    pub churn_risk: f64,
29    /// Recommended products
30    pub recommendations: Vec<ProductRecommendation>,
31    /// Last updated
32    pub last_updated: DateTime<Utc>,
33}
34
35/// Customer segments
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub enum CustomerSegment {
38    HighValue,
39    Regular,
40    Occasional,
41    NewCustomer,
42    AtRisk,
43    Churned,
44}
45
46/// Purchase information
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct Purchase {
49    /// Product ID
50    pub product_id: String,
51    /// Purchase date
52    pub purchase_date: DateTime<Utc>,
53    /// Quantity
54    pub quantity: u32,
55    /// Price paid
56    pub price: f64,
57    /// Channel used
58    pub channel: PurchaseChannel,
59    /// Satisfaction rating
60    pub satisfaction: Option<u8>,
61}
62
63/// Purchase channels
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub enum PurchaseChannel {
66    Online,
67    InStore,
68    Mobile,
69    Phone,
70    ThirdParty,
71}
72
73/// Customer preferences
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct CustomerPreferences {
76    /// Preferred categories
77    pub preferred_categories: Vec<String>,
78    /// Price sensitivity
79    pub price_sensitivity: f64,
80    /// Brand loyalty
81    pub brand_loyalty: HashMap<String, f64>,
82    /// Preferred channels
83    pub preferred_channels: Vec<PurchaseChannel>,
84    /// Communication preferences
85    pub communication_preferences: CommunicationPreferences,
86}
87
88/// Communication preferences
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct CommunicationPreferences {
91    /// Email opt-in
92    pub email_opt_in: bool,
93    /// SMS opt-in
94    pub sms_opt_in: bool,
95    /// Frequency preference
96    pub frequency: CommunicationFrequency,
97    /// Content preferences
98    pub content_types: Vec<String>,
99}
100
101/// Communication frequency
102#[derive(Debug, Clone, Serialize, Deserialize)]
103pub enum CommunicationFrequency {
104    Daily,
105    Weekly,
106    Monthly,
107    Quarterly,
108    Never,
109}
110
111/// Customer behavior metrics
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct BehaviorMetrics {
114    /// Visit frequency
115    pub visit_frequency: f64,
116    /// Average session duration (minutes)
117    pub avg_session_duration: f64,
118    /// Pages/products viewed per session
119    pub avg_products_viewed: f64,
120    /// Cart abandonment rate
121    pub cart_abandonment_rate: f64,
122    /// Return visit rate
123    pub return_visit_rate: f64,
124    /// Referral rate
125    pub referral_rate: f64,
126}
127
128/// Product recommendation
129#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct ProductRecommendation {
131    /// Product ID
132    pub product_id: String,
133    /// Recommendation score
134    pub score: f64,
135    /// Reason for recommendation
136    pub reason: RecommendationReason,
137    /// Confidence level
138    pub confidence: f64,
139    /// Expected revenue impact
140    pub expected_revenue: f64,
141}
142
143/// Reasons for recommendations
144#[derive(Debug, Clone, Serialize, Deserialize)]
145pub enum RecommendationReason {
146    SimilarProducts,
147    CustomersBought,
148    PopularInCategory,
149    PersonalizedPreference,
150    TrendingNow,
151    SeasonalRecommendation,
152}