Skip to main content

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 engine;
49pub mod ewc;
50pub mod loops;
51pub mod lora;
52pub mod reasoning_bank;
53pub mod time_compat;
54pub mod trajectory;
55pub mod types;
56
57#[cfg(feature = "serde-support")]
58pub mod export;
59
60#[cfg(feature = "serde-support")]
61pub mod training;
62
63#[cfg(feature = "wasm")]
64pub mod wasm;
65
66#[cfg(feature = "napi")]
67pub mod napi_simple;
68
69// Re-export main types
70pub use engine::SonaEngine;
71pub use ewc::{EwcConfig, EwcPlusPlus, TaskFisher};
72pub use loops::{BackgroundLoop, InstantLoop, LoopCoordinator};
73pub use lora::{BaseLoRA, LoRAEngine, LoRALayer, MicroLoRA};
74pub use reasoning_bank::{PatternConfig, ReasoningBank};
75pub use trajectory::{TrajectoryBuffer, TrajectoryBuilder, TrajectoryIdGen};
76pub use types::{
77    LearnedPattern, LearningSignal, PatternType, QueryTrajectory, SignalMetadata, SonaConfig,
78    TrajectoryStep,
79};
80
81#[cfg(feature = "serde-support")]
82pub use export::{
83    DatasetExporter, ExportConfig, ExportError, ExportResult, ExportType, HuggingFaceExporter,
84    HuggingFaceHub, PretrainConfig, PretrainPipeline, SafeTensorsExporter,
85};
86
87#[cfg(feature = "serde-support")]
88pub use training::{
89    AgentExport, AgentFactory, AgentHandle, AgentStats, AgentType, AggregationResult, BatchConfig,
90    CoordinatorStats, DataSizeHint, EphemeralAgent, EpochStats, FederatedCoordinator,
91    FederatedTopology, ManagedAgent, PipelineStage, TaskDomain, TemplatePreset, TrainingMethod,
92    TrainingMetrics, TrainingPipeline, TrainingResult, TrainingTemplate, VerticalConfig,
93};
94
95#[cfg(feature = "wasm")]
96pub use wasm::WasmSonaEngine;