diff --git a/marklogic/vectors.py b/marklogic/vectors.py index f166f63..ede8d97 100644 --- a/marklogic/vectors.py +++ b/marklogic/vectors.py @@ -1,45 +1,43 @@ +""" +Supports encoding and decoding vectors using the same approach as the vec:base64-encode and vec:base64-decode +functions supported by the MarkLogic server. +""" + import base64 import struct from typing import List -class VectorUtil: +def base64_encode(vector: List[float]) -> str: """ - Supports encoding and decoding vectors using the same approach as the vec:base64-encode and vec:base64-decode - functions supported by the MarkLogic server. + Encodes a list of floats as a base64 string compatible with MarkLogic's vec:base64-encode. """ + dimensions = len(vector) + # version (int32, 0) + dimensions (int32) + floats (little-endian) + buffer = struct.pack(" str: - """ - Encodes a list of floats as a base64 string compatible with MarkLogic's vec:base64-encode. - """ - dimensions = len(vector) - # version (int32, 0) + dimensions (int32) + floats (little-endian) - buffer = struct.pack(" List[float]: - """ - Decodes a base64 string to a list of floats compatible with MarkLogic's vec:base64-decode. - """ - buffer = base64.b64decode(encoded_vector) - if len(buffer) < 8: - raise ValueError( - "Buffer is too short to contain version and dimensions." - ) - version, dimensions = struct.unpack(" List[float]: + """ + Decodes a base64 string to a list of floats compatible with MarkLogic's vec:base64-decode. + """ + buffer = base64.b64decode(encoded_vector) + if len(buffer) < 8: + raise ValueError( + "Buffer is too short to contain version and dimensions." + ) + version, dimensions = struct.unpack("