Skip to main content

Reflex

Struct Reflex 

Source
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

Source

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
Hide additional 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}
Source

pub fn with_compiled_model(compiled_instinct: CompiledInstinct) -> Self

Source

pub fn predict(&self, state: &str) -> Result<CompiledResult, String>

Sub-10µs inference executing directly on the loaded compiled instinct head.

Source

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
Hide additional 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}
Source

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}
Source

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].

Source

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}
Source

pub fn encode(&self, text: &str) -> [f32; 384]

Encodes input text into an L2-normalized 384-dimensional vector.

Source

pub fn similarity(&self, text_a: &str, text_b: &str) -> f32

Computes cosine similarity between two text strings.

Trait Implementations§

Source§

impl Clone for Reflex

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Reflex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Reflex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.