sqlite-vec/bindings/python/extra_init.py

15 lines
419 B
Python
Raw Normal View History

2024-07-12 08:50:42 -07:00
from typing import List
from struct import pack
2024-07-12 08:50:42 -07:00
def serialize_float32(vector: List[float]) -> bytes:
"""Serializes a list of floats into the "raw bytes" format sqlite-vec expects"""
2024-07-12 08:50:42 -07:00
return pack("%sf" % len(vector), *vector)
2024-07-12 08:50:42 -07:00
def serialize_int8(vector: List[int]) -> bytes:
"""Serializes a list of integers into the "raw bytes" format sqlite-vec expects"""
2024-07-12 08:50:42 -07:00
return pack("%sb" % len(vector), *vector)