ruvector_sona/
lib.rs

1//! SONA (Self-Optimizing Neural Architecture)
2//!
3//! A lightweight adaptive learning system with ReasoningBank integration.
4//!
5//! ## Features
6//!
7//! - **Micro-LoRA**: Ultra-low rank (1-2) LoRA for instant learning
8//! - **Base-LoRA**: Standard LoRA for background learning
9//! - **EWC++**: Elastic Weight Consolidation to prevent catastrophic forgetting
10//! - **ReasoningBank**: Pattern extraction and similarity search
11//! - **Three Learning Loops**: Instant, Background, and Coordination loops
12//! - **WASM Support**: Run in browsers and edge devices (enable `wasm` feature)
13//!
14//! ## Example
15//!
16//! ```rust,ignore
17//! use sona::{SonaEngine, SonaConfig};
18//!
19//! // Create engine
20//! let engine = SonaEngine::new(SonaConfig {
21//!     hidden_dim: 256,
22//!     embedding_dim: 256,
23//!     ..Default::default()
24//! });
25//!
26//! // Begin trajectory
27//! let mut builder = engine.begin_trajectory(vec![0.1; 256]);
28//! builder.add_step(vec![0.5; 256], vec![], 0.8);
29//!
30//! // End trajectory
31//! engine.end_trajectory(builder, 0.85);
32//!
33//! // Apply learned transformations
34//! let input = vec![1.0; 256];
35//! let mut output = vec![0.0; 256];
36//! engine.apply_micro_lora(&input, &mut output);
37//! ```
38//!
39//! ## WASM Usage
40//!
41//! Enable the `wasm` feature and build with:
42//! ```bash
43//! wasm-pack build --target web --features wasm
44//! ```
45
46#![warn(missing_docs)]
47
48pub mod types;
49pub mod lora;
50pub mod trajectory;
51pub mod ewc;
52pub mod reasoning_bank;
53pub mod loops;
54pub mod engine;
55
56#[cfg(feature = "serde-support")]
57pub mod export;
58
59#[cfg(feature = "serde-support")]
60pub mod training;
61
62#[cfg(feature = "wasm")]
63pub mod wasm;
64
65#[cfg(feature = "napi")]
66pub mod napi_simple;
67
68// Re-export main types
69pub use types::{
70    LearningSignal, QueryTrajectory, TrajectoryStep,
71    LearnedPattern, PatternType, SignalMetadata, SonaConfig,
72};
73pub use lora::{MicroLoRA, BaseLoRA, LoRAEngine, LoRALayer};
74pub use trajectory::{TrajectoryBuffer, TrajectoryBuilder, TrajectoryIdGen};
75pub use ewc::{EwcConfig, EwcPlusPlus, TaskFisher};
76pub use reasoning_bank::{ReasoningBank, PatternConfig};
77pub use loops::{InstantLoop, BackgroundLoop, LoopCoordinator};
78pub use engine::SonaEngine;
79
80#[cfg(feature = "serde-support")]
81pub use export::{
82    HuggingFaceExporter, ExportConfig, ExportResult, ExportError, ExportType,
83    SafeTensorsExporter, DatasetExporter, HuggingFaceHub,
84    PretrainConfig, PretrainPipeline,
85};
86
87#[cfg(feature = "serde-support")]
88pub use training::{
89    TrainingTemplate, TemplatePreset, VerticalConfig,
90    AgentType, TaskDomain, TrainingMethod, DataSizeHint,
91    AgentFactory, ManagedAgent, AgentHandle, AgentStats,
92    TrainingPipeline, PipelineStage, BatchConfig,
93    TrainingMetrics, TrainingResult, EpochStats,
94    EphemeralAgent, FederatedCoordinator, AgentExport,
95    AggregationResult, CoordinatorStats, FederatedTopology,
96};
97
98#[cfg(feature = "wasm")]
99pub use wasm::WasmSonaEngine;