Find answers from the community

Updated 2 years ago

Save encoding

Another question: What encoding does index.save_to_string() and index.load_from_string() default to?
L
k
5 comments
Should be utf8 I think
gotcha, thanks πŸ˜„
@Logan M I think it might be ASCII actually (I could be mistaken). It looks like this is the save_to_string method:
Plain Text
def save_to_string(self, **save_kwargs: Any) -> str:
    """Save to string.

    This method stores the index into a JSON string.

    NOTE: save_to_string should not be used for indices composed on top
    of other indices. Please define a `ComposableGraph` and use
    `save_to_string` and `load_from_string` on that instead.

    Returns:
        str: The JSON string of the index.

    """
    out_dict = self.save_to_dict(**save_kwargs)
    return json.dumps(out_dict, **save_kwargs)

json.dumps forces ascii by default unless you specify ensure_ascii=False. I'm just doing index.save_to_string(ensure_ascii=False).encode("utf-8") now in case πŸ˜„
Ohhhh wow, right it's json dumps πŸ™ƒ
Add a reply
Sign up and join the conversation on Discord