2024-07-12 08:50:42 -07:00
|
|
|
from typing import List
|
|
|
|
|
from struct import pack
|
|
|
|
|
|
2024-08-05 16:19:10 -07:00
|
|
|
|
2024-07-12 08:50:42 -07:00
|
|
|
def serialize_float32(vector: List[float]) -> bytes:
|
2024-08-05 16:19:10 -07:00
|
|
|
"""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-08-05 16:19:10 -07:00
|
|
|
|
2024-07-12 08:50:42 -07:00
|
|
|
def serialize_int8(vector: List[int]) -> bytes:
|
2024-08-05 16:19:10 -07:00
|
|
|
"""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)
|
|
|
|
|
|
|
|
|
|
|