pub struct Schema {
pub dtype: DataType,
pub shape: Option<Vec<Dimension>>,
}Expand description
Describes the shape and type of a Value, without holding the actual data.
Used by:
- Filters: declare what they accept (input) and produce (output)
- Compiler: validate type compatibility between connected filters
- VirtualValue: know schema without materializing
- Cache metadata: describe stored entries
Fields§
§dtype: DataTypeThe primitive data type.
shape: Option<Vec<Dimension>>Shape dimensions. Empty for scalars, [n] for vectors, [r,c] for matrices, etc.
None means shape is dynamic/unknown.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn vector(dtype: DataType, len: usize) -> Self
pub fn vector(dtype: DataType, len: usize) -> Self
Create a schema for a 1D tensor (vector) of known length.
Sourcepub fn matrix(dtype: DataType, rows: usize, cols: usize) -> Self
pub fn matrix(dtype: DataType, rows: usize, cols: usize) -> Self
Create a schema for a 2D tensor (matrix) with known dimensions.
Sourcepub fn batched(dtype: DataType, feature_dims: &[usize]) -> Self
pub fn batched(dtype: DataType, feature_dims: &[usize]) -> Self
Create a schema for a tensor with a dynamic batch dimension.
Sourcepub fn text() -> Self
pub fn text() -> Self
Create a schema for UTF-8 text (shape is irrelevant).
This is what a prompt or a completion carries. An edge typed text
will not accept a tensor, which is how a mis-wired handoff between two
agent nodes becomes a compile error rather than a runtime surprise.
Sourcepub fn is_incompatible_with(&self, other: &Schema) -> bool
pub fn is_incompatible_with(&self, other: &Schema) -> bool
Is connecting these two definitely a mistake?
True when no reading of self could satisfy other — a tensor
arriving where a conversation is expected, say. The compiler refuses
to build such a graph, rather than warning and letting it fail
mid-run once tokens have been spent.
Sourcepub fn is_compatible_with(&self, other: &Schema) -> bool
pub fn is_compatible_with(&self, other: &Schema) -> bool
Check if this schema is compatible with another (can be connected in a pipeline).
Compatibility rules:
- Same dtype required (no implicit coercion)
- If both shapes are known, fixed dimensions must match
- Dynamic dimensions are compatible with any size
- Unknown shape (None) is compatible with anything of the same dtype