MCPcopy Create free account
hub / github.com/asg017/sqlite-vss / vectorFromBlobValue

Function vectorFromBlobValue

src/sqlite-vector.cpp:53–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53vec_ptr vectorFromBlobValue(sqlite3_value *value, const char **pzErrMsg) {
54
55 int size = sqlite3_value_bytes(value);
56 char header;
57 char type;
58
59 if (size < (2)) {
60 *pzErrMsg = "Vector blob size less than header length";
61 return nullptr;
62 }
63
64 const void *pBlob = sqlite3_value_blob(value);
65 memcpy(&header, ((char *)pBlob + 0), sizeof(char));
66 memcpy(&type, ((char *)pBlob + 1), sizeof(char));
67
68 if (header != VECTOR_BLOB_HEADER_BYTE) {
69 *pzErrMsg = "Blob not well-formatted vector blob";
70 return nullptr;
71 }
72
73 if (type != VECTOR_BLOB_HEADER_TYPE) {
74 *pzErrMsg = "Blob type not right";
75 return nullptr;
76 }
77
78 int numElements = (size - 2) / sizeof(float);
79 float *vec = (float *)((char *)pBlob + 2);
80 return vec_ptr(new vector<float>(vec, vec + numElements));
81}
82
83vec_ptr vectorFromRawBlobValue(sqlite3_value *value, const char **pzErrMsg) {
84

Callers 2

valueAsVectorFunction · 0.85
vector_from_blobFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected