Create bin/brain_index_training.rs
Browse files
src/bin/brain_index_training.rs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// brain_index_training — Index pruned training data to FLINT brain
|
| 2 |
+
// Copyright 2026 Joseph Stone — All Rights Reserved
|
| 3 |
+
//
|
| 4 |
+
// Links against spf_smart_gate to use brain_local::brain_store() directly.
|
| 5 |
+
// Indexes 3,908 training entries from brain_index_pruned.jsonl to brain.
|
| 6 |
+
//
|
| 7 |
+
// Usage: cargo run --bin brain_index_training
|
| 8 |
+
|
| 9 |
+
use serde::Deserialize;
|
| 10 |
+
use std::fs::File;
|
| 11 |
+
use std::io::{BufRead, BufReader};
|
| 12 |
+
|
| 13 |
+
#[derive(Debug, Deserialize)]
|
| 14 |
+
#[allow(dead_code)]
|
| 15 |
+
struct BrainEntry {
|
| 16 |
+
label: i32,
|
| 17 |
+
source: String,
|
| 18 |
+
text: String,
|
| 19 |
+
tool: String,
|
| 20 |
+
weight: f32,
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
fn main() {
|
| 24 |
+
let collection = "flint_episodic";
|
| 25 |
+
let input_path = "/data/data/com.termux/files/home/SPFsmartGATE/LIVE/TMP/stoneshell-brain/training_data/raw/brain_index_pruned.jsonl";
|
| 26 |
+
|
| 27 |
+
println!("[*] brain_index_training — Index training data to brain");
|
| 28 |
+
println!("[*] Input: {}", input_path);
|
| 29 |
+
println!("[*] Collection: {}", collection);
|
| 30 |
+
println!("");
|
| 31 |
+
|
| 32 |
+
// Initialize brain (same as main SPF binary does)
|
| 33 |
+
spf_smart_gate::brain_local::init_brain();
|
| 34 |
+
println!("[+] Brain initialized");
|
| 35 |
+
|
| 36 |
+
// Read JSONL
|
| 37 |
+
let file = File::open(&input_path).expect("Failed to open input file");
|
| 38 |
+
let reader = BufReader::new(file);
|
| 39 |
+
|
| 40 |
+
let mut count = 0;
|
| 41 |
+
let mut success = 0;
|
| 42 |
+
let mut error_count = 0;
|
| 43 |
+
|
| 44 |
+
for line in reader.lines() {
|
| 45 |
+
let line = line.expect("Failed to read line");
|
| 46 |
+
if line.trim().is_empty() { continue; }
|
| 47 |
+
|
| 48 |
+
match serde_json::from_str::<BrainEntry>(&line) {
|
| 49 |
+
Ok(entry) => {
|
| 50 |
+
// Create title from label + tool
|
| 51 |
+
let title = format!("[{:+}] {}", entry.label, entry.tool);
|
| 52 |
+
|
| 53 |
+
// Call brain_store directly
|
| 54 |
+
let result = spf_smart_gate::brain_local::brain_store(&entry.text, &title, collection);
|
| 55 |
+
|
| 56 |
+
count += 1;
|
| 57 |
+
if result.starts_with("Error") || result.starts_with("Failed") {
|
| 58 |
+
error_count += 1;
|
| 59 |
+
if error_count <= 5 {
|
| 60 |
+
println!(" [!] Entry {} error: {}", count, result);
|
| 61 |
+
}
|
| 62 |
+
} else {
|
| 63 |
+
success += 1;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if count % 500 == 0 {
|
| 67 |
+
println!(" Processed: {}/{} (success: {}, errors: {})",
|
| 68 |
+
count, count, success, error_count);
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
Err(e) => {
|
| 72 |
+
error_count += 1;
|
| 73 |
+
if error_count <= 5 {
|
| 74 |
+
println!(" [!] Parse error: {}", e);
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
println!("\n[=] INDEXING COMPLETE");
|
| 81 |
+
println!(" Total entries: {}", count);
|
| 82 |
+
println!(" Success: {}", success);
|
| 83 |
+
println!(" Errors: {}", error_count);
|
| 84 |
+
println!("\n Training data indexed to 'flint_episodic' collection");
|
| 85 |
+
println!(" FLINT can now recall these patterns on similar queries");
|
| 86 |
+
}
|