oxirs-embed 0.2.4

Knowledge graph embeddings with TransE, ComplEx, and custom models
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
//! Core types and enums for contextual embeddings
//!
//! This module contains all the fundamental data types, enums, and configurations
//! used throughout the contextual embedding system.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use chrono::{DateTime, Utc};
use uuid::Uuid;

/// Types of context to consider for embeddings
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum ContextType {
    /// Query-specific context
    Query,
    /// User-specific context and preferences
    User,
    /// Task-specific context and requirements
    Task,
    /// Temporal context (time-based)
    Temporal,
    /// Interactive context (feedback-based)
    Interactive,
    /// Domain-specific context
    Domain,
    /// Session context
    Session,
    /// Geographic context
    Geographic,
    /// Device context
    Device,
    /// Environmental context
    Environmental,
    /// Social context
    Social,
    /// Cultural context
    Cultural,
    /// Linguistic context
    Linguistic,
    /// Semantic context
    Semantic,
    /// Syntactic context
    Syntactic,
    /// Pragmatic context
    Pragmatic,
}

/// Adaptation strategies for contextual embeddings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AdaptationStrategy {
    /// No adaptation (baseline)
    None,
    /// Linear adaptation
    Linear,
    /// Attention-based adaptation
    Attention,
    /// Multi-layer perceptron adaptation
    MLP,
    /// Transformer-based adaptation
    Transformer,
    /// Mixture of experts
    MixtureOfExperts,
    /// Dynamic routing
    DynamicRouting,
    /// Meta-learning adaptation
    MetaLearning,
    /// Reinforcement learning
    ReinforcementLearning,
    /// Continual learning
    ContinualLearning,
    /// Transfer learning
    TransferLearning,
    /// Few-shot learning
    FewShotLearning,
    /// Zero-shot learning
    ZeroShotLearning,
    /// Self-supervised learning
    SelfSupervisedLearning,
    /// Contrastive learning
    ContrastiveLearning,
    /// Multi-task learning
    MultiTaskLearning,
}

/// Methods for fusing multiple contexts
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ContextFusionMethod {
    /// Concatenation
    Concatenation,
    /// Element-wise addition
    Addition,
    /// Element-wise multiplication
    Multiplication,
    /// Weighted average
    WeightedAverage,
    /// Attention-based fusion
    Attention,
    /// Gating mechanism
    Gating,
    /// Bilinear pooling
    BilinearPooling,
    /// Compact bilinear pooling
    CompactBilinearPooling,
    /// Multimodal compact bilinear pooling
    MultimodalCompactBilinearPooling,
    /// Low-rank bilinear pooling
    LowRankBilinearPooling,
    /// Hierarchical fusion
    Hierarchical,
    /// Cross-attention
    CrossAttention,
    /// Self-attention
    SelfAttention,
    /// Multi-head attention
    MultiHeadAttention,
    /// Transformer fusion
    TransformerFusion,
    /// Graph-based fusion
    GraphFusion,
    /// Dynamic fusion
    DynamicFusion,
    /// Learned fusion
    LearnedFusion,
    /// Modular fusion
    ModularFusion,
    /// Adaptive fusion
    AdaptiveFusion,
    /// Contextual fusion
    ContextualFusion,
}

/// Feedback aggregation strategies
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FeedbackAggregation {
    /// Simple averaging
    Average,
    /// Weighted averaging by recency
    RecencyWeighted,
    /// Weighted averaging by confidence
    ConfidenceWeighted,
    /// Exponential moving average
    ExponentialMovingAverage,
    /// Attention-based aggregation
    AttentionBased,
    /// Learned aggregation
    LearnedAggregation,
    /// Hierarchical aggregation
    HierarchicalAggregation,
    /// Contextual aggregation
    ContextualAggregation,
    /// Dynamic aggregation
    DynamicAggregation,
    /// Multi-scale aggregation
    MultiScaleAggregation,
    /// Temporal aggregation
    TemporalAggregation,
    /// Adaptive aggregation
    AdaptiveAggregation,
}

/// Query intent classification
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum QueryIntent {
    /// Informational query
    Informational,
    /// Navigational query
    Navigational,
    /// Transactional query
    Transactional,
    /// Comparative query
    Comparative,
    /// Temporal query
    Temporal,
    /// Spatial query
    Spatial,
    /// Analytical query
    Analytical,
    /// Creative query
    Creative,
    /// Factual query
    Factual,
    /// Opinion query
    Opinion,
    /// Procedural query
    Procedural,
    /// Causal query
    Causal,
    /// Hypothetical query
    Hypothetical,
    /// Definitional query
    Definitional,
    /// Classification query
    Classification,
    /// Recommendation query
    Recommendation,
    /// Troubleshooting query
    Troubleshooting,
    /// Exploratory query
    Exploratory,
    /// Confirmatory query
    Confirmatory,
    /// Other
    Other,
}

/// Query complexity levels
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum QueryComplexity {
    /// Simple single-hop query
    Simple,
    /// Medium complexity multi-hop query
    Medium,
    /// Complex reasoning query
    Complex,
    /// Very complex multi-step query
    VeryComplex,
    /// Expert-level query
    Expert,
    /// Research-level query
    Research,
    /// Ambiguous query
    Ambiguous,
    /// Multi-faceted query
    MultiFaceted,
    /// Interdisciplinary query
    Interdisciplinary,
    /// Open-ended query
    OpenEnded,
}

/// User expertise levels
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ExpertiseLevel {
    /// Beginner level
    Beginner,
    /// Intermediate level
    Intermediate,
    /// Advanced level
    Advanced,
    /// Expert level
    Expert,
    /// Professional level
    Professional,
    /// Academic level
    Academic,
    /// Research level
    Research,
    /// Domain expert
    DomainExpert,
}

/// Detail level preferences
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DetailLevel {
    /// Minimal details
    Minimal,
    /// Basic details
    Basic,
    /// Moderate details
    Moderate,
    /// Comprehensive details
    Comprehensive,
    /// Exhaustive details
    Exhaustive,
    /// Context-dependent
    ContextDependent,
    /// Adaptive
    Adaptive,
}

/// User feedback types
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UserFeedback {
    /// Thumbs up/down
    ThumbsUpDown(bool),
    /// Star rating (1-5)
    StarRating(u8),
    /// Relevance score (0.0-1.0)
    RelevanceScore(f64),
    /// Text feedback
    TextFeedback(String),
    /// Click-through behavior
    ClickThrough(bool),
    /// Dwell time (seconds)
    DwellTime(f64),
    /// Bounce rate
    BounceRate(f64),
    /// Conversion rate
    ConversionRate(f64),
    /// Custom feedback
    Custom(HashMap<String, serde_json::Value>),
}

/// Task types for context-aware embeddings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TaskType {
    /// Information retrieval
    InformationRetrieval,
    /// Question answering
    QuestionAnswering,
    /// Text classification
    TextClassification,
    /// Sentiment analysis
    SentimentAnalysis,
    /// Named entity recognition
    NamedEntityRecognition,
    /// Relation extraction
    RelationExtraction,
    /// Summarization
    Summarization,
    /// Translation
    Translation,
    /// Text generation
    TextGeneration,
    /// Dialogue systems
    DialogueSystems,
    /// Recommendation systems
    RecommendationSystems,
    /// Search ranking
    SearchRanking,
    /// Content moderation
    ContentModeration,
    /// Fact checking
    FactChecking,
    /// Knowledge graph completion
    KnowledgeGraphCompletion,
    /// Semantic parsing
    SemanticParsing,
    /// Text similarity
    TextSimilarity,
    /// Document clustering
    DocumentClustering,
    /// Topic modeling
    TopicModeling,
    /// Anomaly detection
    AnomalyDetection,
    /// Trend analysis
    TrendAnalysis,
    /// Time series forecasting
    TimeSeriesForecasting,
    /// Image captioning
    ImageCaptioning,
    /// Visual question answering
    VisualQuestionAnswering,
    /// Cross-modal retrieval
    CrossModalRetrieval,
    /// Multimodal classification
    MultimodalClassification,
    /// Code generation
    CodeGeneration,
    /// Code completion
    CodeCompletion,
    /// Bug detection
    BugDetection,
    /// Test generation
    TestGeneration,
    /// Documentation generation
    DocumentationGeneration,
    /// Academic research
    AcademicResearch,
    /// Literature review
    LiteratureReview,
    /// Patent analysis
    PatentAnalysis,
    /// Legal document analysis
    LegalDocumentAnalysis,
    /// Medical diagnosis
    MedicalDiagnosis,
    /// Drug discovery
    DrugDiscovery,
    /// Financial analysis
    FinancialAnalysis,
    /// Risk assessment
    RiskAssessment,
    /// Fraud detection
    FraudDetection,
    /// Market analysis
    MarketAnalysis,
    /// Customer segmentation
    CustomerSegmentation,
    /// Personalization
    Personalization,
    /// Content recommendation
    ContentRecommendation,
    /// Product recommendation
    ProductRecommendation,
    /// News recommendation
    NewsRecommendation,
    /// Music recommendation
    MusicRecommendation,
    /// Video recommendation
    VideoRecommendation,
    /// Book recommendation
    BookRecommendation,
    /// Job recommendation
    JobRecommendation,
    /// Travel recommendation
    TravelRecommendation,
    /// Restaurant recommendation
    RestaurantRecommendation,
    /// Movie recommendation
    MovieRecommendation,
    /// E-commerce search
    EcommerceSearch,
    /// Academic search
    AcademicSearch,
    /// Enterprise search
    EnterpriseSearch,
    /// Web search
    WebSearch,
    /// Image search
    ImageSearch,
    /// Video search
    VideoSearch,
    /// Audio search
    AudioSearch,
    /// Code search
    CodeSearch,
    /// Custom task
    Custom(String),
}

/// Time periods for temporal context
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TimePeriod {
    /// Real-time (current moment)
    RealTime,
    /// Recent (last hour)
    Recent,
    /// Today
    Today,
    /// This week
    ThisWeek,
    /// This month
    ThisMonth,
    /// This quarter
    ThisQuarter,
    /// This year
    ThisYear,
    /// Last week
    LastWeek,
    /// Last month
    LastMonth,
    /// Last quarter
    LastQuarter,
    /// Last year
    LastYear,
    /// Historical (more than a year ago)
    Historical,
    /// Seasonal
    Seasonal,
    /// Cyclic
    Cyclic,
    /// Trending
    Trending,
    /// Custom period
    Custom { start: DateTime<Utc>, end: DateTime<Utc> },
}

/// Trend directions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TrendDirection {
    /// Increasing trend
    Increasing,
    /// Decreasing trend
    Decreasing,
    /// Stable trend
    Stable,
    /// Volatile trend
    Volatile,
    /// Seasonal trend
    Seasonal,
    /// Cyclic trend
    Cyclic,
    /// No clear trend
    None,
}

/// Adaptation types for contextual learning
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AdaptationType {
    /// Query-based adaptation
    Query,
    /// User-based adaptation
    User,
    /// Task-based adaptation
    Task,
    /// Temporal adaptation
    Temporal,
    /// Interactive adaptation
    Interactive,
    /// Domain adaptation
    Domain,
    /// Cross-domain adaptation
    CrossDomain,
    /// Multi-task adaptation
    MultiTask,
    /// Continual adaptation
    Continual,
    /// Personalization adaptation
    Personalization,
    /// Contextual adaptation
    Contextual,
    /// Hybrid adaptation
    Hybrid,
}

/// Processing strategies for different contexts
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ProcessingStrategy {
    /// Eager processing (process all contexts)
    Eager,
    /// Lazy processing (process on demand)
    Lazy,
    /// Selective processing (process based on importance)
    Selective,
    /// Adaptive processing (adjust based on resources)
    Adaptive,
    /// Hierarchical processing (process in stages)
    Hierarchical,
    /// Parallel processing (process contexts in parallel)
    Parallel,
    /// Sequential processing (process contexts sequentially)
    Sequential,
    /// Pipelined processing (process in pipeline)
    Pipelined,
    /// Streaming processing (process continuously)
    Streaming,
    /// Batch processing (process in batches)
    Batch,
    /// Real-time processing (process immediately)
    RealTime,
    /// Offline processing (process offline)
    Offline,
}