| 112 | } |
| 113 | |
| 114 | static 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 |
no test coverage detected