pub struct Reflex {
pub compiled_instinct: Option<CompiledInstinct>,
/* private fields */
}Expand description
Universal System-1 AI Runtime client.
Fields§
§compiled_instinct: Option<CompiledInstinct>Implementations§
Source§impl Reflex
impl Reflex
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/bench.rs (line 10)
5fn main() {
6 let args: Vec<String> = env::args().collect();
7 let iters: usize = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(5000);
8 let sample = "Urgent: Suspicious activity on your account. Click here to cancel wire #8129!";
9
10 let rx = Reflex::new();
11 let encoder = SemanticVectorEncoder::new();
12 let suite = GuardrailSuite::new();
13
14 // 1. Encode
15 let t0 = Instant::now();
16 for _ in 0..iters {
17 let _ = encoder.encode(sample);
18 }
19 let t_enc = t0.elapsed().as_secs_f64();
20
21 // 2. Noul
22 let t0 = Instant::now();
23 for _ in 0..iters {
24 let _ = rx.noul("Is this a security threat or phishing scam?", sample);
25 }
26 let t_noul = t0.elapsed().as_secs_f64();
27
28 // 3. Guardrail
29 let t0 = Instant::now();
30 for _ in 0..iters {
31 let _ = suite.evaluate(sample);
32 }
33 let t_guard = t0.elapsed().as_secs_f64();
34
35 let encode_us = (t_enc / iters as f64) * 1_000_000.0;
36 let noul_us = (t_noul / iters as f64) * 1_000_000.0;
37 let guard_us = (t_guard / iters as f64) * 1_000_000.0;
38 let throughput_ops = iters as f64 / t_noul;
39
40 println!(
41 r#"{{"encode_us": {:.2}, "noul_us": {:.2}, "guard_us": {:.2}, "throughput_ops": {:.2}}}"#,
42 encode_us, noul_us, guard_us, throughput_ops
43 );
44}More examples
examples/quickstart.rs (line 11)
6fn main() {
7 println!("==================================================================");
8 println!("🦀 Reflex Rust SDK (reflex-rs) Quickstart");
9 println!("==================================================================");
10
11 let rx = Reflex::new();
12 let state = "Customer: I was billed $299 twice on my Visa card today. Refund immediately!";
13
14 // 1. Noul Boolean Primitive (<15µs)
15 let noul = rx.noul("Is the customer demanding a refund or chargeback?", state);
16 println!("\n1. Noul Boolean Decision:");
17 println!(" • Probability : {:.4}", noul.probability);
18 println!(" • Is True? : {}", noul.is_true);
19 println!(" • Confidence : {:.4}", noul.confidence);
20 println!(" • Uncertain? : {}", noul.is_uncertain);
21
22 // 2. Choice Multi-Class Rubric (<15µs)
23 let options = vec![
24 "billing".to_string(),
25 "technical_support".to_string(),
26 "sales".to_string(),
27 ];
28 let choice = rx.choice("Select operational department queue", options, state);
29 println!("\n2. Choice Rubric Selection:");
30 println!(" • Selected : {}", choice.selected);
31 println!(" • Confidence : {:.4}", choice.confidence);
32 for (opt, prob) in &choice.distribution {
33 println!(" - {:<18} : {:.4}", opt, prob);
34 }
35
36 // 3. Instant Guardrails (<1µs)
37 let guard = rx.guardrail(state);
38 println!("\n3. Guardrail Security Audit:");
39 println!(" • Is Safe? : {}", guard.is_safe);
40 println!(" • Blocked? : {}", guard.blocked);
41 println!(" • Risk Score : {:.2}", guard.risk_score);
42
43 println!("\n==================================================================");
44 println!("✅ Rust System-1 execution complete. Zero external crate dependencies.");
45 println!("==================================================================");
46}pub fn with_compiled_model(compiled_instinct: CompiledInstinct) -> Self
Sourcepub fn predict(&self, state: &str) -> Result<CompiledResult, String>
pub fn predict(&self, state: &str) -> Result<CompiledResult, String>
Sub-10µs inference executing directly on the loaded compiled instinct head.
Sourcepub fn noul(&self, instructions: impl Into<String>, state: &str) -> NoulResult
pub fn noul(&self, instructions: impl Into<String>, state: &str) -> NoulResult
Evaluates a Noul (probabilistic boolean) against a state string.
Examples found in repository?
examples/bench.rs (line 24)
5fn main() {
6 let args: Vec<String> = env::args().collect();
7 let iters: usize = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(5000);
8 let sample = "Urgent: Suspicious activity on your account. Click here to cancel wire #8129!";
9
10 let rx = Reflex::new();
11 let encoder = SemanticVectorEncoder::new();
12 let suite = GuardrailSuite::new();
13
14 // 1. Encode
15 let t0 = Instant::now();
16 for _ in 0..iters {
17 let _ = encoder.encode(sample);
18 }
19 let t_enc = t0.elapsed().as_secs_f64();
20
21 // 2. Noul
22 let t0 = Instant::now();
23 for _ in 0..iters {
24 let _ = rx.noul("Is this a security threat or phishing scam?", sample);
25 }
26 let t_noul = t0.elapsed().as_secs_f64();
27
28 // 3. Guardrail
29 let t0 = Instant::now();
30 for _ in 0..iters {
31 let _ = suite.evaluate(sample);
32 }
33 let t_guard = t0.elapsed().as_secs_f64();
34
35 let encode_us = (t_enc / iters as f64) * 1_000_000.0;
36 let noul_us = (t_noul / iters as f64) * 1_000_000.0;
37 let guard_us = (t_guard / iters as f64) * 1_000_000.0;
38 let throughput_ops = iters as f64 / t_noul;
39
40 println!(
41 r#"{{"encode_us": {:.2}, "noul_us": {:.2}, "guard_us": {:.2}, "throughput_ops": {:.2}}}"#,
42 encode_us, noul_us, guard_us, throughput_ops
43 );
44}More examples
examples/quickstart.rs (line 15)
6fn main() {
7 println!("==================================================================");
8 println!("🦀 Reflex Rust SDK (reflex-rs) Quickstart");
9 println!("==================================================================");
10
11 let rx = Reflex::new();
12 let state = "Customer: I was billed $299 twice on my Visa card today. Refund immediately!";
13
14 // 1. Noul Boolean Primitive (<15µs)
15 let noul = rx.noul("Is the customer demanding a refund or chargeback?", state);
16 println!("\n1. Noul Boolean Decision:");
17 println!(" • Probability : {:.4}", noul.probability);
18 println!(" • Is True? : {}", noul.is_true);
19 println!(" • Confidence : {:.4}", noul.confidence);
20 println!(" • Uncertain? : {}", noul.is_uncertain);
21
22 // 2. Choice Multi-Class Rubric (<15µs)
23 let options = vec![
24 "billing".to_string(),
25 "technical_support".to_string(),
26 "sales".to_string(),
27 ];
28 let choice = rx.choice("Select operational department queue", options, state);
29 println!("\n2. Choice Rubric Selection:");
30 println!(" • Selected : {}", choice.selected);
31 println!(" • Confidence : {:.4}", choice.confidence);
32 for (opt, prob) in &choice.distribution {
33 println!(" - {:<18} : {:.4}", opt, prob);
34 }
35
36 // 3. Instant Guardrails (<1µs)
37 let guard = rx.guardrail(state);
38 println!("\n3. Guardrail Security Audit:");
39 println!(" • Is Safe? : {}", guard.is_safe);
40 println!(" • Blocked? : {}", guard.blocked);
41 println!(" • Risk Score : {:.2}", guard.risk_score);
42
43 println!("\n==================================================================");
44 println!("✅ Rust System-1 execution complete. Zero external crate dependencies.");
45 println!("==================================================================");
46}Sourcepub fn choice(
&self,
instructions: impl Into<String>,
options: Vec<String>,
state: &str,
) -> ChoiceResult
pub fn choice( &self, instructions: impl Into<String>, options: Vec<String>, state: &str, ) -> ChoiceResult
Evaluates a Choice rubric selection across options.
Examples found in repository?
examples/quickstart.rs (line 28)
6fn main() {
7 println!("==================================================================");
8 println!("🦀 Reflex Rust SDK (reflex-rs) Quickstart");
9 println!("==================================================================");
10
11 let rx = Reflex::new();
12 let state = "Customer: I was billed $299 twice on my Visa card today. Refund immediately!";
13
14 // 1. Noul Boolean Primitive (<15µs)
15 let noul = rx.noul("Is the customer demanding a refund or chargeback?", state);
16 println!("\n1. Noul Boolean Decision:");
17 println!(" • Probability : {:.4}", noul.probability);
18 println!(" • Is True? : {}", noul.is_true);
19 println!(" • Confidence : {:.4}", noul.confidence);
20 println!(" • Uncertain? : {}", noul.is_uncertain);
21
22 // 2. Choice Multi-Class Rubric (<15µs)
23 let options = vec![
24 "billing".to_string(),
25 "technical_support".to_string(),
26 "sales".to_string(),
27 ];
28 let choice = rx.choice("Select operational department queue", options, state);
29 println!("\n2. Choice Rubric Selection:");
30 println!(" • Selected : {}", choice.selected);
31 println!(" • Confidence : {:.4}", choice.confidence);
32 for (opt, prob) in &choice.distribution {
33 println!(" - {:<18} : {:.4}", opt, prob);
34 }
35
36 // 3. Instant Guardrails (<1µs)
37 let guard = rx.guardrail(state);
38 println!("\n3. Guardrail Security Audit:");
39 println!(" • Is Safe? : {}", guard.is_safe);
40 println!(" • Blocked? : {}", guard.blocked);
41 println!(" • Risk Score : {:.2}", guard.risk_score);
42
43 println!("\n==================================================================");
44 println!("✅ Rust System-1 execution complete. Zero external crate dependencies.");
45 println!("==================================================================");
46}Sourcepub fn score(
&self,
instructions: impl Into<String>,
min_val: f32,
max_val: f32,
state: &str,
) -> ScoreResult
pub fn score( &self, instructions: impl Into<String>, min_val: f32, max_val: f32, state: &str, ) -> ScoreResult
Evaluates a continuous Score on [min_val, max_val].
Sourcepub fn guardrail(&self, text: &str) -> GuardrailResult
pub fn guardrail(&self, text: &str) -> GuardrailResult
Inspects input text for security threats, jailbreaks, and PII.
Examples found in repository?
examples/quickstart.rs (line 37)
6fn main() {
7 println!("==================================================================");
8 println!("🦀 Reflex Rust SDK (reflex-rs) Quickstart");
9 println!("==================================================================");
10
11 let rx = Reflex::new();
12 let state = "Customer: I was billed $299 twice on my Visa card today. Refund immediately!";
13
14 // 1. Noul Boolean Primitive (<15µs)
15 let noul = rx.noul("Is the customer demanding a refund or chargeback?", state);
16 println!("\n1. Noul Boolean Decision:");
17 println!(" • Probability : {:.4}", noul.probability);
18 println!(" • Is True? : {}", noul.is_true);
19 println!(" • Confidence : {:.4}", noul.confidence);
20 println!(" • Uncertain? : {}", noul.is_uncertain);
21
22 // 2. Choice Multi-Class Rubric (<15µs)
23 let options = vec![
24 "billing".to_string(),
25 "technical_support".to_string(),
26 "sales".to_string(),
27 ];
28 let choice = rx.choice("Select operational department queue", options, state);
29 println!("\n2. Choice Rubric Selection:");
30 println!(" • Selected : {}", choice.selected);
31 println!(" • Confidence : {:.4}", choice.confidence);
32 for (opt, prob) in &choice.distribution {
33 println!(" - {:<18} : {:.4}", opt, prob);
34 }
35
36 // 3. Instant Guardrails (<1µs)
37 let guard = rx.guardrail(state);
38 println!("\n3. Guardrail Security Audit:");
39 println!(" • Is Safe? : {}", guard.is_safe);
40 println!(" • Blocked? : {}", guard.blocked);
41 println!(" • Risk Score : {:.2}", guard.risk_score);
42
43 println!("\n==================================================================");
44 println!("✅ Rust System-1 execution complete. Zero external crate dependencies.");
45 println!("==================================================================");
46}Sourcepub fn encode(&self, text: &str) -> [f32; 384]
pub fn encode(&self, text: &str) -> [f32; 384]
Encodes input text into an L2-normalized 384-dimensional vector.
Sourcepub fn similarity(&self, text_a: &str, text_b: &str) -> f32
pub fn similarity(&self, text_a: &str, text_b: &str) -> f32
Computes cosine similarity between two text strings.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Reflex
impl RefUnwindSafe for Reflex
impl Send for Reflex
impl Sync for Reflex
impl Unpin for Reflex
impl UnsafeUnpin for Reflex
impl UnwindSafe for Reflex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more