MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / vs_append_result

Function vs_append_result

src/store/store.c:12246–12280  ·  view source on GitHub ↗

Append one candidate row read from the scan statement into `*results`, * growing the array geometrically on demand. Returns CBM_STORE_OK, or * CBM_STORE_ERR on allocation failure — in which case `*results` still owns * exactly `*count` complete rows (a row is only counted once every string * copy succeeded), so the caller's usual free path stays valid. */

Source from the content-addressed store, hash-verified

12244 * exactly `*count` complete rows (a row is only counted once every string
12245 * copy succeeded), so the caller's usual free path stays valid. */
12246static int vs_append_result(cbm_vector_result_t **results, int *count, int *cap, sqlite3_stmt *stmt,
12247 const int8_t (*kw_vecs)[VS_VEC_DIM], const double *kw_norms,
12248 int actual_kw) {
12249 if (*count >= *cap) {
12250 int nc = *cap < CBM_SZ_16 ? CBM_SZ_16 : *cap * ST_COL_2;
12251 cbm_vector_result_t *grown = realloc(*results, (size_t)nc * sizeof(cbm_vector_result_t));
12252 if (!grown) {
12253 return CBM_STORE_ERR;
12254 }
12255 *results = grown;
12256 *cap = nc;
12257 }
12258 cbm_vector_result_t *row = &(*results)[*count];
12259 row->node_id = sqlite3_column_int64(stmt, 0);
12260 const char *name = (const char *)sqlite3_column_text(stmt, SKIP_ONE);
12261 const char *qn = (const char *)sqlite3_column_text(stmt, ST_COL_2);
12262 const char *fp = (const char *)sqlite3_column_text(stmt, ST_COL_3);
12263 const char *label = (const char *)sqlite3_column_text(stmt, ST_COL_4);
12264 row->name = strdup(name ? name : "");
12265 row->qualified_name = strdup(qn ? qn : "");
12266 row->file_path = strdup(fp ? fp : "");
12267 row->label = strdup(label ? label : "");
12268 if (!row->name || !row->qualified_name || !row->file_path || !row->label) {
12269 free(row->name);
12270 free(row->qualified_name);
12271 free(row->file_path);
12272 free(row->label);
12273 return CBM_STORE_ERR;
12274 }
12275 const int8_t *node_vec = (const int8_t *)sqlite3_column_blob(stmt, ST_COL_6);
12276 int node_vec_len = sqlite3_column_bytes(stmt, ST_COL_6);
12277 row->score = vs_min_cosine_score(node_vec, node_vec_len, kw_vecs, kw_norms, actual_kw);
12278 (*count)++;
12279 return CBM_STORE_OK;
12280}
12281
12282/* A lean index carries no node_vectors table at all. That is an empty
12283 * semantic universe, not a scan failure, and callers must be able to tell

Callers 1

cbm_store_vector_searchFunction · 0.85

Calls 1

vs_min_cosine_scoreFunction · 0.85

Tested by

no test coverage detected