File size: 2,892 Bytes
f82a6cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// brain_index_training — Index pruned training data to FLINT brain
// Copyright 2026 Joseph Stone — All Rights Reserved
//
// Links against spf_smart_gate to use brain_local::brain_store() directly.
// Indexes 3,908 training entries from brain_index_pruned.jsonl to brain.
//
// Usage: cargo run --bin brain_index_training

use serde::Deserialize;
use std::fs::File;
use std::io::{BufRead, BufReader};

#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct BrainEntry {
    label: i32,
    source: String,
    text: String,
    tool: String,
    weight: f32,
}

fn main() {
    let collection = "flint_episodic";
    let input_path = "/data/data/com.termux/files/home/SPFsmartGATE/LIVE/TMP/stoneshell-brain/training_data/raw/brain_index_pruned.jsonl";

    println!("[*] brain_index_training — Index training data to brain");
    println!("[*] Input: {}", input_path);
    println!("[*] Collection: {}", collection);
    println!("");

    // Initialize brain (same as main SPF binary does)
    spf_smart_gate::brain_local::init_brain();
    println!("[+] Brain initialized");

    // Read JSONL
    let file = File::open(&input_path).expect("Failed to open input file");
    let reader = BufReader::new(file);

    let mut count = 0;
    let mut success = 0;
    let mut error_count = 0;

    for line in reader.lines() {
        let line = line.expect("Failed to read line");
        if line.trim().is_empty() { continue; }

        match serde_json::from_str::<BrainEntry>(&line) {
            Ok(entry) => {
                // Create title from label + tool
                let title = format!("[{:+}] {}", entry.label, entry.tool);

                // Call brain_store directly
                let result = spf_smart_gate::brain_local::brain_store(&entry.text, &title, collection);

                count += 1;
                if result.starts_with("Error") || result.starts_with("Failed") {
                    error_count += 1;
                    if error_count <= 5 {
                        println!("  [!] Entry {} error: {}", count, result);
                    }
                } else {
                    success += 1;
                }

                if count % 500 == 0 {
                    println!("  Processed: {}/{} (success: {}, errors: {})",
                        count, count, success, error_count);
                }
            }
            Err(e) => {
                error_count += 1;
                if error_count <= 5 {
                    println!("  [!] Parse error: {}", e);
                }
            }
        }
    }

    println!("\n[=] INDEXING COMPLETE");
    println!("  Total entries: {}", count);
    println!("  Success: {}", success);
    println!("  Errors: {}", error_count);
    println!("\n  Training data indexed to 'flint_episodic' collection");
    println!("  FLINT can now recall these patterns on similar queries");
}