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