Skip to content

serve: select embedding prefixes with prompt_name - #414

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:serve-embedding-prompt-name
Oct 17, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:serve-embedding-prompt-name

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Part of #59 (plan and PR order in #190), follow-up 4: named query and document prefixes.

What and why

prompt_name selects a prefix from the embedding model's config_sentence_transformers.json. Both /v1/embeddings and /embedding apply the prefix before tokenization, using the names and bytes from the config. Requests without prompt_name keep their input unchanged.

The existing model-file owner reads the config once at startup, beside a local embedding model or from its HF repository. If the repository has no config, its model card's single base_model supplies it. The same lookup works from verified cached files under HF_HUB_OFFLINE or during a network outage. If neither config can be found, lookup leaves no named prefixes; malformed files still refuse startup. The embedding model's /v1/models metadata lists prompt_names.

Unknown names and non-string names return OpenAI-shaped 400 errors. Named prompts accept text strings and batches of strings. Token IDs and media inputs remain available without prompt_name.

Release notes: Added: Select embedding query and document prefixes with prompt_name.

Code shape

  • No second copy. The HF card reader and model-file fetch owner handle the metadata.
  • Model code holds only architecture facts. No model-specific prefix or name is hardcoded.
  • Dead code is gone.
  • No silent failure. Malformed configs refuse startup; invalid prompt requests run no embedding pass.
  • Comments state what is true now.
  • No relaxed gate.
  • cargo fmt and cargo clippy: formatting applied; static review is pending.

Duplication found or removed: the existing model-card fetch and front-matter parser now serve both callers.

What I ran

RUSTFLAGS=-Ctarget-cpu=native cargo test -p bloomery-gpu-gates --test sentence_prompts -- --nocapture passed all 20 startup combinations at 3a8c3ef3. The restart regression first resolves a GGUF and its prompt metadata online, then repeats startup with the cache, with HF_HUB_OFFLINE=1 and with an unreachable hub. It covers a repo's own config, a base-model config, a missing card, a missing base config and malformed config JSON. Restoring each of the three original missing-file guards made its offline restart fail with Offline { cache: NoFile }.

RUSTFLAGS=-Ctarget-cpu=native cargo test -p bloomery-gpu-gates --lib model_file::tests -- --nocapture passed all 3 unit tests on the same head. just check-levers also passed. The restart harness uses child processes and directory fixtures, with no new environment reads or allow-list entries.

The earlier host suite at a660c8aa passed 63 HF tests, 10 embedding API tests and 2 model-file tests. The config fallback changes leave HF parsing and HTTP prompt handling unchanged.

Both card comparisons ran on 4a7d1e00 and are carried to 3a8c3ef3: the fix changes startup handling of missing optional files, with no change to prefix application, tokenization or the encoder. The restart harness adds no production code. Each builds bloomery-serve through cargo oxide with glm5next,clef,mimo2,gemma-embedding2 (sm_121 on GB10, sm_86 on RTX 5090). A sentence-transformers 6.1.0 capture module records the text passed by encode(prompt_name=...), without loading its model weights. The HTTP comparison checks each configured prompt, plus empty text, Unicode and whitespace cases for query and document.

The named and manually prefixed requests to the same Bloomery binary produced identical vectors on both HTTP routes. Bloomery and llama-server ran sequentially on each card, using mainline llama.cpp 6868a52cb337450658006ad2f9281c2eb63f1666 with manually prefixed input. The last column reports the minimum cosine against that reference.

Card and model Cases Input-byte mismatches Named/manual vector mismatches Minimum cosine vs llama.cpp
GB10, EmbeddingGemma 2 Q8_0 26 0 0 0.999554461909
GB10, EmbeddingGemma v1 Q8_0 20 0 0 0.999624802777
RTX 5090, EmbeddingGemma 2 Q8_0 26 0 0 0.999554461909
RTX 5090, EmbeddingGemma v1 Q8_0 20 0 0 0.999648318514

Across both cards and both models, prompt selection added 0 byte mismatches against sentence-transformers and 0 vector mismatches against manually prefixed Bloomery input (92 cases total).

Hardware: NVIDIA GB10, driver 595.84; NVIDIA GeForce RTX 5090, driver 595.99.02. Both embedding models used Q8_0. The EmbeddingGemma 2 config is pinned at 914f7f89142e33e77833254d9c9b90c3cef7303b; the v1 config is pinned at 57c266a740f537b4dc058e1b0cda161fd15afa75.

Reproduce

Place the model's config_sentence_transformers.json beside the embedding GGUF, then start the server with --embd-model FILE as described in docs/serving.md.

curl http://localhost:8080/v1/embeddings \
  -H 'Content-Type: application/json' \
  -d '{"input":"Where is Paris?","prompt_name":"query"}'

What I ran into

These metadata details do not block the PR. The GGUF repositories' model cards name a base model without requiring base_model_relation: quantized. Prefix lookup follows that single base model, while the decision-head reader keeps its existing quantized-only rule.

The v1 config's Google download requires authorization. The comparison used the public unsloth/embeddinggemma-300m copy at bfa3c846ac738e62aa61806ef9112d34acb1dc5a, whose Git blob SHA-1 matches Google's published file entry (3552ab1b79dc8571d0ecf200db12e5208eda5bdd).

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card serve The HTTP server: crates/serve tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 17, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: CLEAN: No proven behavior or quality defect was found in the changed code.

Checked

Duplicates: 17 new functions and constants checked; no duplicate owner found. Dryer reported zero pairs. Card fetching and front-matter parsing reuse existing owners.

Complexity: sentence_prompts new → 18, source selection and optional HF/base lookup before the existing JSON parser; answer 20 → 27, request validation at the shared HTTP owner; Flags::read 27 → 28, error propagation from one startup call.

Silent failure: 7 default/absence sites followed. Missing optional metadata produces no prompt names; selecting an absent name returns 400. Malformed configs and other fetch/read errors refuse startup. Invalid batch elements and context overflow are rejected before any embedding pass.

Tests: Static mutation inspection covered all 7 added or changed tests. Local startup: crates/gpu-gates/src/model_file.rs:254, discard parsing errors → malformed-file assertion fails. Optional-file classification: crates/gpu-gates/src/model_file.rs:270, drop the offline arm → wrapped-error assertion fails. Restart harness: crates/gpu-gates/src/model_file.rs:223 and the guards at 231/279, restore direct-only missing-file matching → offline restart fails. Prefix parser: crates/hf/src/sentence_transformers.rs:16, trim prefix values → byte assertions fail. Card parser: crates/hf/src/card.rs:16, require a quantized relation → relation-free base assertion fails. HTTP prompts: crates/serve/src/embeddings.rs:144, omit the prefix → recorded-token assertion fails. Discovery: crates/serve/src/api.rs:1822, omit prompt_names → exact metadata assertion fails.

Gates: No band, tolerance, lint or existing case removed or relaxed. The serve recipe adds the restart regression. The PR reports FAIL-first for all three missing-file guards.

Escape catalog: C1–C4 do not match the changed recipe or the fixture's shell script.

Adversarial checks: Offline fallback preserves cached prompts; malformed metadata refuses startup; a mixed batch runs no pass; empty batches and prefixed context overflow are rejected. Concurrent requests read an immutable prompt map.

Notes

Dryer excluded gpu-gates; its changed owners were checked manually. Review was static; builds and tests were not run.
GPU comparison summaries lack the required just gate-* commands with output and complete base/head evidence.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/model_file.rs, crates/gpu-gates/src/side_seat.rs, crates/gpu-gates/tests/sentence_prompts.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit a6fa3ee into midagedev:main Oct 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card serve The HTTP server: crates/serve tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant