vec:base64-encode( $vector1 as vec:vector ) as xs:string
Returns the base64 encoding of the vector. Useful for compressing a high-dimensional float vector represented as a string into fewer characters.
Parameters | |
---|---|
vector1 | The vector to base64 encode. |
xquery version "1.0-ml"; let $vec1 := vec:vector((3.14,1.59,2.65)) return vec:base64-encode($vec1) => FYT6NiFJhGw=AwAAAA==AAAAAA==w/VIQB+Fyz+amSlA
xquery version "1.0-ml"; let $vec1 := vec:vector(xdmp:to-json(fn:doc('pronethalol.json'))/data/array-node{embedding}) return fn:string-length(vec:base64-encode($vec1)) || " VS " || fn:string-length(fn:string($vec1)) => 8220 VS 18229 (: This function compressed the string representation of the 1536 dimensional float vector in 'pronethalol.json' at array node 'embedding' from 18229 characters to 8220 characters. :)