Repository navigation
fix(semantic): neutralize image data URIs before remote embedding requests - #819
Draft
citizenadam wants to merge 1 commit into
Draft
citizenadam wants to merge 1 commit into
citizenadam wants to merge 1 commit into
Conversation
…uests VLM-backed embedding deployments (for example NVIDIA's nemotron embed family) parse `data:image/<mime>;base64` anywhere in an `input` string as an image part, then reject the whole request when VLM serving is disabled: HTTP 400 image inputs require VLM serving to be enabled on this server Source code that builds screenshot, avatar or thumbnail data URIs contains that prefix, so a single such chunk failed every row of its batch and, with it, the entire semantic build. The build restarted from scratch next session and died at the same chunk again. Rewrite the `data:image/` prefix to `data-uri:image/` in the OpenAI-compatible request body only. The persisted chunk text, the local fastembed and ollama backends, and every non-image data URI stay byte-identical. The rewrite borrows when the prefix is absent, so the common row costs one substring scan and no allocation. Refs cortexkit#817
Contributor
|
#817 has the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Approved issue: #817
What changes
embed_textssends chunk text verbatim as the embeddingsinput. VLM-backedembedding deployments — NVIDIA's current
nemotron-*embed*models, forexample — parse
data:image/<mime>;base64anywhere in aninputstring as animage part and reject the whole request when VLM serving is disabled:
Source code legitimately builds such strings (
image_url=f"data:image/png;base64,{...}",screenshot helpers, docstrings naming the format), so one chunk killed its
batch and, with it, the entire semantic build — repeatedly, from chunk 0, every
session.
This change neutralizes the
data:image/prefix todata-uri:image/in theOpenAI-compatible request body only:
the original bytes;
fastembedandollamapayloads are unchanged, since neither interprets dataURIs;
text/plain,application/json,audio/*data URIs and the uppercase formare left alone — they already embed successfully against the same deployment,
so rewriting them would only perturb vectors;
substring scan and no allocation.
The trigger is a literal, case-sensitive prefix and the backend does not
validate the payload, so a plain
str::replaceis enough; no regex is neededon the request path.
embed_textsis the single request builder for both build batches andinteractive query embeds, so both are covered.
How it was checked
cargo fmt --check: clean.image_data_uri_tests, 7 passed / 0 failed): borrowedpass-through, source-line template literal, multiple occurrences per row,
docstring mention without a payload, non-image data URIs untouched, uppercase
untouched, and a serialized body assertion that no
data:image/survives.Run in the debug profile:
cargo test -p agent-file-tools --lib image_data_uri_tests.cargo test --releasecannot build this crate's lib tests at this commitbecause
storage_retention::test_volume_uuid_guardis#[cfg(debug_assertions)];that is unrelated to this change.
https://integrate.api.nvidia.com/v1withnvidia/nemotron-3-embed-1b, on a one-file repository containingf"data:image/png;base64,{payload.decode('ascii')}", viaaft index:kind=semantic status=gap usable=false reason="openai compatible request failed (HTTP 400 Bad Request): {\"message\": \"image inputs require VLM serving to be enabled on this server\" ...}", exit 2;kind=semantic status=success result_count=4, exit 0.through
aft indexinto the same storage the plugin uses:/mnt/s/ComfyUI:kind=search status=success result_count=1222,kind=semantic status=success result_count=20651(the stock binary failedthis root at batch 134/326 with the 400);
/go/career-ops:kind=search status=success result_count=3455,kind=semantic status=success result_count=3850.Exit 0, no build-breaker suspensions recorded afterwards.
Notes for review
applies only to text that no longer matches the data-URI grammar.
SynapseandOllamapayload builders are untouched; if a future backend isknown to parse data URIs, the helper is one call away.
AI assistance disclosure: this submission was produced with an AI coding agent
(DeepSeek V4.1 Flash driving an autonomous agent session). The agent reproduced
the failure end-to-end, wrote the patch and tests, and ran the verification
commands listed above; a human operator reviewed the diagnosis and directed the
approach. Review the diff with that in mind.
Summary by cubic
Fixes semantic embedding failures where VLM-backed deployments (e.g. NVIDIA's
nemotronembed) reject chunks containingdata:image/prefixes as image inputs, returning HTTP 400 and breaking the whole build.data:image/todata-uri:image/only in the OpenAI-compatible request body; persisted chunk text,fastembedandollamapayloads, and non-image data URIs stay byte-identical.Written for commit 4e48adf. Summary will update on new commits.