Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dbmem-rembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ int dbmem_remote_compute_embedding (dbmem_remote_engine_t *engine, const char *t
}
}

// Some providers do not return output_dimension; fallback to embedding array length.
if (n_embd == 0 && emb_count > 0) {
n_embd = (int)emb_count;
}
Comment on lines +509 to +512
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new fallback triggers whenever n_embd == 0, which also happens if output_dimension is present but non-numeric/invalid (since atoi() returns 0). That changes behavior from “reject invalid output_dimension” to “silently ignore it”. Consider tracking whether the output_dimension key was actually present (e.g., bool saw_output_dimension) and only falling back when it’s absent, and/or validating token type + parsing with strtol to detect invalid values explicitly.

Copilot uses AI. Check for mistakes.

if (emb_start < 0 || emb_count == 0 || n_embd == 0) {
dbmem_context_set_error(engine->context, "Missing embedding data in API response");
return -1;
Comment on lines 514 to 516
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure n_embd matches the actual parsed embedding length (emb_count) before returning success. If output_dimension is larger than emb_count, downstream code uses result->n_embd to size the blob (e.g., sqlite3_bind_blob(..., result->n_embd * sizeof(float), ...)), which would read past the allocated engine->embedding buffer. Suggest validating n_embd == (int)emb_count (or at least n_embd <= emb_count) and returning an error on mismatch, or overriding n_embd with emb_count when they differ.

Copilot uses AI. Check for mistakes.
Expand Down
Loading