Try to look up an enriched int8 vector for `token` in the token_vectors * table. On success, writes the de-quantized float representation to * `out` and returns true. */
| 12107 | * table. On success, writes the de-quantized float representation to |
| 12108 | * `out` and returns true. */ |
| 12109 | static bool vs_load_enriched_vector(cbm_store_t *s, const char *project, const char *token, |
| 12110 | float *out) { |
| 12111 | sqlite3_stmt *tv_stmt = NULL; |
| 12112 | const char *tv_sql = "SELECT vector, idf FROM token_vectors" |
| 12113 | " WHERE project = ?1 AND token = ?2 LIMIT 1"; |
| 12114 | if (sqlite3_prepare_v2(s->db, tv_sql, SQLITE_AUTO_LEN, &tv_stmt, NULL) != SQLITE_OK) { |
| 12115 | return false; |
| 12116 | } |
| 12117 | bool found = false; |
| 12118 | sqlite3_bind_text(tv_stmt, SKIP_ONE, project, SQLITE_AUTO_LEN, SQLITE_STATIC); |
| 12119 | sqlite3_bind_text(tv_stmt, ST_COL_2, token, SQLITE_AUTO_LEN, SQLITE_STATIC); |
| 12120 | if (sqlite3_step(tv_stmt) == SQLITE_ROW) { |
| 12121 | const int8_t *vec = (const int8_t *)sqlite3_value_blob(sqlite3_column_value(tv_stmt, 0)); |
| 12122 | int vec_len = sqlite3_column_bytes(tv_stmt, 0); |
| 12123 | if (vec && vec_len == VS_VEC_DIM) { |
| 12124 | for (int d = 0; d < VS_VEC_DIM; d++) { |
| 12125 | out[d] = (float)vec[d] / CBM_STORE_INT8_MAX; |
| 12126 | } |
| 12127 | found = true; |
| 12128 | } |
| 12129 | } |
| 12130 | sqlite3_finalize(tv_stmt); |
| 12131 | return found; |
| 12132 | } |
| 12133 | |
| 12134 | /* Sparse-random-index fallback for tokens not present in the enriched table. */ |
| 12135 | static void vs_fill_sparse_random(const char *token, float *out) { |
no outgoing calls
no test coverage detected