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

Function valueAsVector

src/sqlite-vector.cpp:114–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114static vec_ptr valueAsVector(sqlite3_value *value) {
115
116 // Option 1: If the value is a "vectorf32v0" pointer, create vector from
117 // that
118 auto vec = (VectorFloat *)sqlite3_value_pointer(value, VECTOR_FLOAT_POINTER_NAME);
119
120 if (vec != nullptr)
121 return vec_ptr(new vector<float>(vec->data, vec->data + vec->size));
122
123 vec_ptr pVec;
124
125 // Option 2: value is a blob in vector format
126 if (sqlite3_value_type(value) == SQLITE_BLOB) {
127
128 const char *pzErrMsg = nullptr;
129
130 if ((pVec = vectorFromBlobValue(value, &pzErrMsg)) != nullptr)
131 return pVec;
132
133 if ((pVec = vectorFromRawBlobValue(value, &pzErrMsg)) != nullptr)
134 return pVec;
135 }
136
137 // Option 3: if value is a JSON array coercible to float vector, use that
138 if (sqlite3_value_type(value) == SQLITE_TEXT) {
139
140 if ((pVec = vectorFromTextValue(value)) != nullptr)
141 return pVec;
142 else
143 return nullptr;
144 }
145
146 // Else, value isn't a vector
147 return nullptr;
148}
149
150#pragma endregion
151

Callers 5

vector_debugFunction · 0.85
vector_value_atFunction · 0.85
vector_to_jsonFunction · 0.85
vector_to_blobFunction · 0.85
vector_to_rawFunction · 0.85

Calls 3

vectorFromBlobValueFunction · 0.85
vectorFromRawBlobValueFunction · 0.85
vectorFromTextValueFunction · 0.85

Tested by

no test coverage detected