File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 55'use strict' ;
66const { Buffer } = require ( 'buffer' ) ;
77
8+ /**
9+ * Provides functions to encode and decode vectors.
10+ * MarkLogic 12 or higher needed.
11+ * @namespace vectorUtil
12+ */
13+
14+ /**
15+ * Converts an array of vector float values into an encoded string.
16+ * Encoding vectors before writing them to documents in MarkLogic 12
17+ * helps reduce the amount of disk space and memory consumed by vectors.
18+ * @method vectorUtil#base64Encode
19+ * @since 3.7.0
20+ * @param {float[] } vector - an array of float values
21+ * @returns {string } an encoded string value.
22+ */
823const base64Encode = ( vector ) => {
924 const dimensions = vector . length ;
1025 const buffer = Buffer . alloc ( 8 + 4 * dimensions ) ;
@@ -19,6 +34,13 @@ const base64Encode = (vector) => {
1934 return buffer . toString ( 'base64' ) ;
2035} ;
2136
37+ /**
38+ * Converts an encoded string value to an array of vectors.
39+ * @method vectorUtil#base64Decode
40+ * @since 3.7.0
41+ * @param {string } encodedVector - an encoded string value.
42+ * @returns {float[] } an array of float values.
43+ */
2244const base64Decode = ( encodedVector ) => {
2345
2446 const buffer = Buffer . from ( encodedVector , 'base64' ) ;
You can’t perform that action at this time.
0 commit comments