Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tensor Data Model

Neumann uses a unified tensor-based data model that represents all data types as mathematical tensors.

Core Types

TensorValue

The fundamental value type:

VariantDescriptionExample
Scalar(ScalarValue)Single value42, "hello", true
Vector(Vec<f32>)Dense embedding[0.1, 0.2, 0.3]
Pointer(String)Reference to entity"user_123"
Pointers(Vec<String>)Multiple references["a", "b", "c"]

ScalarValue

Primitive values:

VariantRust TypeExample
Int(i64)64-bit integer42
Float(f64)64-bit float3.14
String(String)UTF-8 string"hello"
Bool(bool)Booleantrue
Bytes(Vec<u8>)Binary data[0x01, 0x02]
NullNull valueNULL

TensorData

A map of field names to TensorValues:

#![allow(unused)]
fn main() {
// Conceptually: HashMap<String, TensorValue>
let user = TensorData::new()
    .with("id", TensorValue::Scalar(ScalarValue::Int(1)))
    .with("name", TensorValue::Scalar(ScalarValue::String("Alice".into())))
    .with("embedding", TensorValue::Vector(vec![0.1, 0.2, 0.3]));
}

Sparse Vectors

For high-dimensional sparse data:

#![allow(unused)]
fn main() {
// Only stores non-zero values
let sparse = SparseVector::new(1000)  // 1000 dimensions
    .with_value(42, 0.5)
    .with_value(100, 0.3)
    .with_value(500, 0.8);
}

Operations

OperationDescription
cosine_similarityCosine distance between vectors
euclidean_distanceL2 distance
dot_productInner product
weighted_averageBlend multiple vectors
project_orthogonalRemove component

Type Mapping

Relational Engine

SQL TypeTensorValue
INTScalar(Int)
FLOATScalar(Float)
STRINGScalar(String)
BOOLScalar(Bool)
VECTOR(n)Vector

Graph Engine

Graph ElementTensorValue
Node IDScalar(String)
Edge targetPointer
PropertiesTensorData

Vector Engine

Vector TypeTensorValue
DenseVector
SparseSparseVector (internal)

Storage Layout

Data is stored in TensorStore as key-value pairs:

Key: "users/1"
Value: TensorData {
    "id": Scalar(Int(1)),
    "name": Scalar(String("Alice")),
    "embedding": Vector([0.1, 0.2, ...])
}