-
Notifications
You must be signed in to change notification settings - Fork 0
RISC Thought Engine: softmax fix + highheelbgz encoding proof #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| FROM rust:1.82-bookworm AS builder | ||
| WORKDIR /app | ||
|
|
||
| # Dependencies first (cached layer) | ||
| COPY Cargo.toml Cargo.lock ./ | ||
| COPY crates/thinking-engine/Cargo.toml crates/thinking-engine/ | ||
| COPY crates/bgz-tensor/Cargo.toml crates/bgz-tensor/ | ||
| COPY crates/highheelbgz/Cargo.toml crates/highheelbgz/ | ||
| RUN mkdir -p crates/thinking-engine/src && echo "fn main() {}" > crates/thinking-engine/src/lib.rs \ | ||
| && mkdir -p crates/bgz-tensor/src && echo "" > crates/bgz-tensor/src/lib.rs \ | ||
| && mkdir -p crates/highheelbgz/src && echo "" > crates/highheelbgz/src/lib.rs \ | ||
| && cargo build --release --manifest-path crates/thinking-engine/Cargo.toml 2>/dev/null || true | ||
|
|
||
| # Source code | ||
| COPY crates/ crates/ | ||
|
|
||
| # Download codebooks from GitHub Release | ||
| ADD https://github.com/AdaWorldAPI/lance-graph/releases/download/v0.2.0-7lane-codebooks/qwen3-vl-embedding-7lane.tar.gz /tmp/ | ||
| ADD https://github.com/AdaWorldAPI/lance-graph/releases/download/v0.2.0-7lane-codebooks/jina-v5-7lane.tar.gz /tmp/ | ||
| ADD https://github.com/AdaWorldAPI/lance-graph/releases/download/v0.2.0-7lane-codebooks/jina-reranker-v3-BF16-7lane.tar.gz /tmp/ | ||
| RUN cd /app/crates/thinking-engine/data && \ | ||
| tar xzf /tmp/qwen3-vl-embedding-7lane.tar.gz && \ | ||
| tar xzf /tmp/jina-v5-7lane.tar.gz && \ | ||
| tar xzf /tmp/jina-reranker-v3-BF16-7lane.tar.gz && \ | ||
| rm /tmp/*.tar.gz | ||
|
|
||
| # Build thinking engine | ||
| RUN cargo build --release --manifest-path crates/thinking-engine/Cargo.toml | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The runtime stage copies Useful? React with 👍 / 👎. |
||
|
|
||
| # Runtime image | ||
| FROM debian:bookworm-slim | ||
| RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* | ||
| COPY --from=builder /app/crates/thinking-engine/target/release/examples/playground /usr/local/bin/thinking-engine | ||
| COPY --from=builder /app/crates/thinking-engine/data/*-7lane /app/data/ | ||
| EXPOSE 8080 | ||
| ENTRYPOINT ["thinking-engine"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # Thinking Engine — Quickstart (LM Studio-style) | ||
|
|
||
| > Load a model. Type text. See thoughts. No GPU needed. | ||
|
|
||
| ## 1. Install | ||
|
|
||
| ```bash | ||
| # Clone | ||
| git clone https://github.com/AdaWorldAPI/lance-graph.git | ||
| cd lance-graph | ||
|
|
||
| # Download codebooks (770 KB per model, from GitHub Release) | ||
| cd crates/thinking-engine/data | ||
| curl -LO https://github.com/AdaWorldAPI/lance-graph/releases/download/v0.2.0-7lane-codebooks/qwen3-vl-embedding-7lane.tar.gz | ||
| curl -LO https://github.com/AdaWorldAPI/lance-graph/releases/download/v0.2.0-7lane-codebooks/jina-v5-7lane.tar.gz | ||
| curl -LO https://github.com/AdaWorldAPI/lance-graph/releases/download/v0.2.0-7lane-codebooks/jina-reranker-v3-BF16-7lane.tar.gz | ||
| tar xzf qwen3-vl-embedding-7lane.tar.gz | ||
| tar xzf jina-v5-7lane.tar.gz | ||
| tar xzf jina-reranker-v3-BF16-7lane.tar.gz | ||
| cd ../../.. | ||
| ``` | ||
|
|
||
| ## 2. Run (interactive, like LM Studio) | ||
|
|
||
| ```bash | ||
| cargo run --release --manifest-path crates/thinking-engine/Cargo.toml --example playground | ||
| ``` | ||
|
|
||
| Type any text → see which codebook atoms light up, how energy flows through the distance table, which peaks emerge after 10 cycles of signed softmax thinking. | ||
|
|
||
| ## 3. Run benchmarks | ||
|
|
||
| ```bash | ||
| # Does thinking beat plain cosine? (honest answer) | ||
| cargo run --release --example benchmark_thinking \ | ||
| --manifest-path crates/thinking-engine/Cargo.toml | ||
|
|
||
| # 7-lane encoding (which formats preserve ground truth?) | ||
| cargo run --release --features calibration --example seven_lane_encoder \ | ||
| --manifest-path crates/thinking-engine/Cargo.toml -- qwen3-vl-embedding | ||
|
|
||
| # Forward pass: real 2048D embeddings from Qwen3-VL | ||
| cargo run --release --features calibration --example qwen3_vl_forward \ | ||
| --manifest-path crates/thinking-engine/Cargo.toml | ||
| ``` | ||
|
|
||
| ## 4. Docker | ||
|
|
||
| ```bash | ||
| cd crates/thinking-engine | ||
| docker build -t thinking-engine . | ||
|
Comment on lines
+50
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The quickstart tells users to run Useful? React with 👍 / 👎. |
||
| docker run -it thinking-engine | ||
| ``` | ||
|
|
||
| ## 5. Use as library | ||
|
|
||
| ```rust | ||
| use thinking_engine::f32_engine::F32ThinkingEngine; | ||
|
|
||
| // Load precomputed f32 cosine table (256 KB) | ||
| let table: Vec<f32> = load_f32_table("data/qwen3-vl-embedding-7lane/cosine_matrix_256x256.f32"); | ||
| let mut engine = F32ThinkingEngine::new(table); | ||
|
|
||
| // Perturb with codebook indices from tokenized input | ||
| engine.perturb(&[42, 100, 150]); | ||
|
|
||
| // Think: 10 cycles of signed softmax (T=0.1) | ||
| let result = engine.think(10); | ||
|
|
||
| // Get top-5 peaks | ||
| let peaks = engine.top_k(5); | ||
| for (atom, energy) in &peaks { | ||
| println!("Atom {} energy {:.4}", atom, energy); | ||
| } | ||
| ``` | ||
|
|
||
| ## 6. Online learning (table improves with use) | ||
|
|
||
| ```rust | ||
| use thinking_engine::contrastive_learner::ContrastiveLearner; | ||
|
|
||
| let table = load_f32_table("data/qwen3-vl-embedding-7lane/cosine_matrix_256x256.f32"); | ||
| let mut learner = ContrastiveLearner::new(table, 0.01); | ||
|
|
||
| // Each forward pass teaches the table | ||
| let real_cosine = forward_pass_cosine("text A", "text B"); | ||
| let centroid_a = codebook_lookup("text A"); | ||
| let centroid_b = codebook_lookup("text B"); | ||
| let error = learner.update_pair(centroid_a, centroid_b, real_cosine); | ||
| println!("Table error: {:.4}", error); | ||
|
|
||
| // After learning, build engine from improved table | ||
| let engine = F32ThinkingEngine::new(learner.table().to_vec()); | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| Text → Tokenize (Qwen3 BPE) → Codebook lookup (256 centroids) | ||
| → F32ThinkingEngine.perturb() → .think(10) | ||
| → Signed MatVec + Softmax(T=0.1) per cycle | ||
| → Top-K peaks = thought output | ||
|
|
||
| The distance table IS the brain. | ||
| Each MatVec cycle spreads energy through cosine similarity. | ||
| Softmax concentrates on best matches (not ReLU which destroys information). | ||
| 10 cycles: 70-77% agreement with ground truth embedding cosine. | ||
| ``` | ||
|
|
||
| ## Key Results | ||
|
|
||
| | Metric | Value | | ||
| |--------|-------| | ||
| | Table format | f32 (Pearson r=0.9999 vs ground truth) | | ||
| | Normalization | Softmax T=0.1 (not ReLU) | | ||
| | Top-5 agreement | 70% (Qwen3-VL), 77% (Reranker) | | ||
| | Entropy reduction | -21% to -31% (focuses, doesn't diffuse) | | ||
| | Peak diversity | 100% (no attractor collapse) | | ||
| | Speed | ~600μs/query (256 centroids, CPU) | | ||
| | Table size | 256 KB (f32) or 64 KB (i8 signed) | | ||
| | Models | 3 pretrained codebooks in GitHub Release | | ||
|
|
||
| ## Models Available | ||
|
|
||
| | Model | Params | Dims | Cosine Range | Best For | | ||
| |-------|--------|------|--------------|----------| | ||
| | Qwen3-VL-Embedding-2B | 2B | 2048D | [-0.85, 0.54] | Multimodal (text+vision) | | ||
| | Jina v5 | 0.6B | 1024D | [-0.19, 0.68] | Text embedding | | ||
| | Jina Reranker v3 | 0.6B | 1024D | [-0.89, 0.83] | Cross-encoder (50% inhibition) | | ||
|
|
||
| ## What Failed (honest) | ||
|
|
||
| - u8 CDF tables: destroy value geometry (Pearson 0.80) | ||
| - γ+φ golden ratio: identical to CDF (zero added value) | ||
| - ReLU normalization: attractor collapse (power iteration) | ||
| - Multi-lens superposition: Cronbach α < 0.37 (models don't agree) | ||
| - Gestalt awareness: zero improvement | ||
| - Inhibition leak: zero improvement | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crates/thinking-engine/Cargo.tomldeclaresrust-version = "1.94", but this Dockerfile pins the builder image to Rust 1.82; Cargo will refuse to compile when the compiler is below the package’srust-version. As written, the image build is blocked before the thinking-engine binary is produced, so the base image/toolchain needs to be upgraded to match the crate requirement.Useful? React with 👍 / 👎.