Bridge — Java vespajlib Tensor to C++ vespa/eval Tensor Binary Wire Contract

Tensors constructed or embedded in the Java stateless container (container-jdisc / utility-libs) must cross the process boundary into C++ content nodes (content-nodes) for both document feeding (Document tensor fields) and query ranking (input.query(q_vec) properties) without losing dimension type or cell precision (double, float, bfloat16, int8).

Side A — Java Container Producer (vespa/vespajlib)

  • Anchor package: vespa/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java
  • Tensor.from(TensorType, ...) or container embedders (vespa/container-onnxruntime) produce IndexedTensor, MappedTensor, or MixedTensor instances.
  • TypedBinaryFormat.encode(tensor) serializes the format tag (1 = sparse, 2 = dense, 3 = mixed, 6 = typed cell-type header) followed by dimension sizes, string label tables, and raw cell values.

Wire Protocol — Typed Binary Tensor Format

  • Format Tag & Cell-Type Encoding: Encodes whether dimensions are trivial, sparse (mapped), dense (indexed), or mixed (mapped outer + indexed inner), plus cell value encoding (0 = double, 1 = float, 2 = bfloat16, 3 = int8).
  • Travels inside vespa/document field payloads during feeding and inside fef::Properties (vespa/searchlib/src/vespa/searchlib/fef/) during query dispatch.

Side B — C++ Content Node Consumer (vespa/eval)

  • Anchor package: vespa/eval/src/vespa/eval/eval/serialization/typed_binary_format.cpp and vespa/eval/src/vespa/eval/eval/fast_value.cpp
  • vespalib::eval::TypedBinaryFormat::deserialize reconstructs a C++ FastValueIndex / Value::UP directly backed by contiguous cell arrays (std::span<const float>, BFloat16, Int8Float) ready for TensorFunction execution or HNSW distance calculation (see vespa-tensor-type-system-and-algebra).