Skip to content

feat: BF16ThinkingEngine — distance table at source weight precision#125

Merged
AdaWorldAPI merged 1 commit into
mainfrom
claude/risc-thought-engine-TCZw7
Apr 6, 2026
Merged

feat: BF16ThinkingEngine — distance table at source weight precision#125
AdaWorldAPI merged 1 commit into
mainfrom
claude/risc-thought-engine-TCZw7

Conversation

@AdaWorldAPI
Copy link
Copy Markdown
Owner

bf16_engine.rs (8 tests):
BF16 distance table (u16 bit patterns, NOT integers)
bf16_to_f32 lossless (bit shift), sign bit = gate decision
cycle(): F32x16 SIMD with BF16→f32 conversion per lane
cycle_with_temperature(): softmax/T after BF16 accumulation
from_codebook(): build from ClamCodebook pairwise StackedN cosine
from_f32_cosines(), from_f64_cosines(): build from raw cosines
load()/save(): 256×256 × 2 bytes = 128 KB files

Tests verify:
- Real negative values in BF16 table (not CDF rank relabeling)
- Inhibition from negative BF16 entries
- Temperature differentiates (low T = fewer active, high T = more)
- Different inputs produce different peaks
- BF16 roundtrip error < 0.01 (1 ULP)

builder.rs:
TableType::BF16 added
BuiltEngine::BF16(BF16ThinkingEngine) with all match arms
Temporary u8→BF16 conversion path until BF16 lenses are baked

252 tests pass (+8 new).

https://claude.ai/code/session_019RzHP8tpJu55ESTxhfUy1A

bf16_engine.rs (8 tests):
  BF16 distance table (u16 bit patterns, NOT integers)
  bf16_to_f32 lossless (bit shift), sign bit = gate decision
  cycle(): F32x16 SIMD with BF16→f32 conversion per lane
  cycle_with_temperature(): softmax/T after BF16 accumulation
  from_codebook(): build from ClamCodebook pairwise StackedN cosine
  from_f32_cosines(), from_f64_cosines(): build from raw cosines
  load()/save(): 256×256 × 2 bytes = 128 KB files

  Tests verify:
    - Real negative values in BF16 table (not CDF rank relabeling)
    - Inhibition from negative BF16 entries
    - Temperature differentiates (low T = fewer active, high T = more)
    - Different inputs produce different peaks
    - BF16 roundtrip error < 0.01 (1 ULP)

builder.rs:
  TableType::BF16 added
  BuiltEngine::BF16(BF16ThinkingEngine) with all match arms
  Temporary u8→BF16 conversion path until BF16 lenses are baked

252 tests pass (+8 new).

https://claude.ai/code/session_019RzHP8tpJu55ESTxhfUy1A
@AdaWorldAPI AdaWorldAPI merged commit 22f0f7c into main Apr 6, 2026
AdaWorldAPI pushed a commit that referenced this pull request Apr 17, 2026
…eam #150

## Stale artifact removal (182 files, 3 MB)

`AdaWorldAPI-lance-graph-d9df43b/` was a committed snapshot of an older
upstream version (48 .rs files vs our 98). Full audit confirmed:
  - ZERO files exist only in the artifact (every file has a counterpart)
  - Every differing file: ours >= artifact in LOC (ours is strictly ahead)
  - All upstream features (#125 parameter_substitution, #140 lance_vector_search)
    are already in our src tree

The directory created GitHub path confusion — duplicate navigation paths
for datafusion_planner, spo, blasgraph, neighborhood, arigraph. Removing
it eliminates that confusion with zero content loss.

## Cherry-pick: spark_dialect.rs from upstream PR #150

The ONE file upstream has that we didn't:
  - `crates/lance-graph/src/spark_dialect.rs` (107 LOC)
    Spark SQL dialect for DataFusion unparser: backtick quoting, STRING
    type casting, EXTRACT for dates, BIGINT/INT types, LENGTH(), derived
    table aliases.
  - `crates/lance-graph/tests/test_to_spark_sql.rs` (293 LOC)
    Full test suite for Spark SQL output.
  - `pub mod spark_dialect;` added to lib.rs

Adapted from upstream's DF 50.3 to our DF 51 — same API surface, no
changes needed.

## Upstream audit result (for the record)

Upstream (lance-format/lance-graph) is at v0.5.4. Our fork is at v0.5.3
with newer deps (arrow 57 vs 56.2, datafusion 51 vs 50.3). Other than
spark_dialect, every upstream feature and fix is already present in our
source tree — parameter_substitution (#125), lance_vector_search (#140),
complex RETURN clauses (#142), duplicate columns fix (#128) are all in
`crates/lance-graph/src/`.

Their deleted `simple_executor` was a prototype cold-path executor we
never had. Our `ExecutionStrategy::DataFusion` path (6K LOC planner)
+ `ExecutionStrategy::BlasGraph` (semiring algebra) subsume it. The
user has flagged adding a deliberate `ExecutionStrategy::Simple` cold
path as a 4th strategy for trivial queries — that's a separate PR per
the documented matrix of execution strategies.

https://claude.ai/code/session_01NYGrxVopyszZYgLBxe4hgj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants