Skip to content

Fix cryptic SQLite error when remote embedder is unreachable - #10

Closed
krisajenkins wants to merge 1 commit into
martintrojer:mainfrom
krisajenkins:fix-remote-embedder-error
Closed

krisajenkins wants to merge 1 commit into
martintrojer:mainfrom
krisajenkins:fix-remote-embedder-error

Conversation

@krisajenkins

Copy link
Copy Markdown
Contributor

Summary

  • Propagate errors from embed_batch when embedding_dim is still unknown, instead of silently falling back to a zero vector with a guessed dimension
  • Read HTTP error response bodies and extract the server's error message (supports OpenAI-style, Ollama, and plain text formats) — previously ureq's http_status_as_error discarded the body, so errors just said "http status: 404"
  • Defensive check in initialize_embedder: bail with a clear message if embedding_dim is 0 after the probe

Before:

vec0 constructor error: could not parse vector column 'embedding float[0] distance_metric=cosine': Error code 1: SQL error or missing database

After:

Failed to connect to external embedder: Embeddings API returned HTTP 404: model "mxbai-embed-large" not found, try pulling it first

Test plan

  • vecgrep --reindex with a valid remote embedder config (Ollama + mxbai-embed-large) succeeds
  • vecgrep --reindex with an unavailable model gives a clear error pointing at the model/URL
  • vecgrep --reindex with Ollama not running gives a clear connection error
  • cargo test passes (same pre-existing failures only)
  • cargo clippy -- -D warnings is clean

When the remote embedder (Ollama) returned an HTTP error (e.g. model not
found, server down), the zero-vector fallback in embed_batch silently
swallowed the error. This meant the probe embed in main.rs "succeeded"
without discovering the embedding dimension, leaving it at 0. The 0 was
then passed to SQLite's vec0 table constructor as `float[0]`, producing
the unhelpful error:

  vec0 constructor error: could not parse vector column
  'embedding float[0] distance_metric=cosine'

Three fixes:

1. Propagate errors from embed_batch when embedding_dim is still unknown.
   The zero-vector fallback is only safe after we've discovered the real
   dimension from at least one successful embed call.

2. Read HTTP error response bodies and extract the server's error message
   (supports OpenAI-style, Ollama, and plain text formats). Previously
   ureq's http_status_as_error discarded the body, so errors just said
   "http status: 404". Now they say e.g.:

     Embeddings API returned HTTP 404: model "mxbai-embed-large" not
     found, try pulling it first

3. Defensive check in main.rs: bail with a clear message if embedding_dim
   is still 0 after the probe, pointing at the model name and URL.
@martintrojer

Copy link
Copy Markdown
Owner

@copilot fix merge errors and run cargo fmt

martintrojer added a commit that referenced this pull request Mar 16, 2026
- Check HTTP status codes from remote embedder and extract human-readable
  error messages from OpenAI/Ollama-style JSON error responses
- Validate embedding dimension is non-zero after probe
- Propagate errors early when embedding_dim is unknown (can't create
  valid zero vectors without knowing the dimension)

Co-authored-by: Kris Jenkins <krisajenkins@users.noreply.github.com>
@martintrojer

Copy link
Copy Markdown
Owner

Merged in ef9038a — thanks @krisajenkins!

martintrojer added a commit that referenced this pull request Mar 16, 2026
- query_context_length: explicitly check HTTP status after
  http_status_as_error(false) change, instead of relying on JSON
  parse failure for error responses
- Remove unreachable dim=0 check in main.rs — the embed_batch
  early-propagation fix means the probe always errors before
  returning a zero dimension
- Add 5 tests for extract_error_message (OpenAI, simple, Ollama,
  plain text, truncation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants