Skip to main content

oxirs_embed/
enterprise_knowledge_product.rs

1//! Product, category, and sales-related types for enterprise knowledge.
2
3use crate::Vector;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// Product embedding with business context
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ProductEmbedding {
11    /// Product unique identifier
12    pub product_id: String,
13    /// Product name
14    pub name: String,
15    /// Product description
16    pub description: String,
17    /// Product category
18    pub category: String,
19    /// Subcategories
20    pub subcategories: Vec<String>,
21    /// Product features
22    pub features: Vec<ProductFeature>,
23    /// Price information
24    pub price: f64,
25    /// Availability status
26    pub availability: ProductAvailability,
27    /// Sales metrics
28    pub sales_metrics: SalesMetrics,
29    /// Customer ratings
30    pub ratings: CustomerRatings,
31    /// Product embedding vector
32    pub embedding: Vector,
33    /// Similar products
34    pub similar_products: Vec<String>,
35    /// Market position score
36    pub market_position: f64,
37    /// Last updated
38    pub last_updated: DateTime<Utc>,
39}
40
41/// Product feature information
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct ProductFeature {
44    /// Feature name
45    pub feature_name: String,
46    /// Feature value
47    pub feature_value: String,
48    /// Feature type
49    pub feature_type: FeatureType,
50    /// Feature importance score
51    pub importance_score: f64,
52}
53
54/// Types of product features
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub enum FeatureType {
57    Categorical,
58    Numerical,
59    Boolean,
60    Text,
61    List,
62}
63
64/// Product availability status
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub enum ProductAvailability {
67    InStock(u32),
68    OutOfStock,
69    Discontinued,
70    PreOrder(DateTime<Utc>),
71    Limited(u32),
72}
73
74/// Sales metrics for products
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct SalesMetrics {
77    /// Total units sold
78    pub units_sold: u64,
79    /// Revenue generated
80    pub revenue: f64,
81    /// Sales velocity (units per day)
82    pub sales_velocity: f64,
83    /// Conversion rate
84    pub conversion_rate: f64,
85    /// Return rate
86    pub return_rate: f64,
87    /// Profit margin
88    pub profit_margin: f64,
89}
90
91/// Customer ratings and reviews
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct CustomerRatings {
94    /// Average rating (1-5)
95    pub average_rating: f64,
96    /// Total number of reviews
97    pub review_count: u32,
98    /// Rating distribution
99    pub rating_distribution: HashMap<u8, u32>,
100    /// Sentiment score (-1 to 1)
101    pub sentiment_score: f64,
102}
103
104/// Category hierarchy structure
105#[derive(Debug, Clone)]
106pub struct CategoryHierarchy {
107    /// Category tree
108    pub categories: HashMap<String, Category>,
109    /// Category relationships
110    pub parent_child: HashMap<String, Vec<String>>,
111    /// Category embeddings
112    pub category_embeddings: HashMap<String, Vector>,
113}
114
115/// Category information
116#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct Category {
118    /// Category ID
119    pub category_id: String,
120    /// Category name
121    pub name: String,
122    /// Parent category
123    pub parent: Option<String>,
124    /// Child categories
125    pub children: Vec<String>,
126    /// Products in this category
127    pub products: Vec<String>,
128    /// Category attributes
129    pub attributes: HashMap<String, String>,
130    /// Category performance metrics
131    pub performance: CategoryPerformance,
132}
133
134/// Category performance metrics
135#[derive(Debug, Clone, Serialize, Deserialize)]
136pub struct CategoryPerformance {
137    /// Total sales
138    pub total_sales: f64,
139    /// Product count
140    pub product_count: u32,
141    /// Average rating
142    pub average_rating: f64,
143    /// Growth rate
144    pub growth_rate: f64,
145    /// Market share
146    pub market_share: f64,
147}