@@ -31,25 +31,39 @@ pub mod vector_search;
3131
3232mod utils;
3333
34+ /// Environment variable that gates registration of the tensor scalar-fn array plugins (the array
35+ /// encodings that let [`CosineSimilarity`], [`InnerProduct`], [`L2Denorm`], [`L2Norm`], and
36+ /// [`SorfTransform`] persist in a Vortex file). When unset, only the scalar functions themselves
37+ /// are registered; readers of files containing serialized tensor scalar-fn arrays will fail to
38+ /// deserialize. Opt-in by setting the variable to any non-empty value.
39+ pub const SCALAR_FN_ARRAY_TENSOR_PLUGIN_ENV : & str = "VX_SCALAR_FN_ARRAY_TENSOR_PLUGIN" ;
40+
3441/// Initialize the Vortex tensor library with a Vortex session.
3542pub fn initialize ( session : & VortexSession ) {
3643 session. dtypes ( ) . register ( Vector ) ;
3744 session. dtypes ( ) . register ( FixedShapeTensor ) ;
3845
3946 let session_fns = session. scalar_fns ( ) ;
40- let session_arrays = session. arrays ( ) ;
4147
4248 session_fns. register ( CosineSimilarity ) ;
4349 session_fns. register ( InnerProduct ) ;
4450 session_fns. register ( L2Denorm ) ;
4551 session_fns. register ( L2Norm ) ;
4652 session_fns. register ( SorfTransform ) ;
4753
48- session_arrays. register ( ScalarFnArrayPlugin :: new ( CosineSimilarity ) ) ;
49- session_arrays. register ( ScalarFnArrayPlugin :: new ( InnerProduct ) ) ;
50- session_arrays. register ( ScalarFnArrayPlugin :: new ( L2Denorm ) ) ;
51- session_arrays. register ( ScalarFnArrayPlugin :: new ( L2Norm ) ) ;
52- session_arrays. register ( ScalarFnArrayPlugin :: new ( SorfTransform ) ) ;
54+ // Registering the scalar-fn array plugins lets the tensor scalar fns be serialized as array
55+ // encodings inside Vortex files. Gate this on an env var so applications that do not intend
56+ // to persist these encodings do not pay the registry cost or widen their stable-encoding
57+ // surface unintentionally.
58+ if std:: env:: var_os ( SCALAR_FN_ARRAY_TENSOR_PLUGIN_ENV ) . is_some_and ( |v| !v. is_empty ( ) ) {
59+ let session_arrays = session. arrays ( ) ;
60+
61+ session_arrays. register ( ScalarFnArrayPlugin :: new ( CosineSimilarity ) ) ;
62+ session_arrays. register ( ScalarFnArrayPlugin :: new ( InnerProduct ) ) ;
63+ session_arrays. register ( ScalarFnArrayPlugin :: new ( L2Denorm ) ) ;
64+ session_arrays. register ( ScalarFnArrayPlugin :: new ( L2Norm ) ) ;
65+ session_arrays. register ( ScalarFnArrayPlugin :: new ( SorfTransform ) ) ;
66+ }
5367}
5468
5569#[ cfg( test) ]
0 commit comments