Skip to content

fix(embeddings): fail loud instead of returning zero-vector HF embeddings (closes #167)#184

Merged
stevei101 merged 5 commits into
developfrom
fix/167-fail-loud-zero-embeddings
Jun 4, 2026
Merged

fix(embeddings): fail loud instead of returning zero-vector HF embeddings (closes #167)#184
stevei101 merged 5 commits into
developfrom
fix/167-fail-loud-zero-embeddings

Conversation

@stevei101
Copy link
Copy Markdown
Contributor

Summary

  • HuggingFaceEmbeddings::embed now returns Err(GraphRAGError::Embedding) instead of silently emitting vec![0.0; dims] when Candle inference is invoked. Closes graphrag-core: HuggingFace embeddings + neural.rs are stubs (return zero vectors) #167.
  • graphrag-core/src/embeddings/neural.rs rewritten from a one-line // TODO into a module-level doc that names the gap and points callers at the working HttpEmbeddingProvider alternatives.
  • Two regression tests cover both the not-initialized and marked-initialized paths, asserting the error and its message.
  • Drive-by: fix ///!//! at the top of huggingface.rs (clippy suspicious_doc_comments).

Why

The previous behaviour passed zero vectors through the rest of the pipeline (chunking, vector store, similarity), producing structurally-clean retrieval results with no semantic meaning. The only signal was a log::warn!, which is easy to miss in production logs. This was misleading enough that the README quickstart had to be rewritten away from HuggingFace in a follow-up to PR #164.

Real Candle-backed inference is the next step on the same issue and on phase 1.1 of the meta-epic (#182 / TDD). Failing loud is the prerequisite — it stops silently-wrong embeddings from shipping while the real implementation gets written.

Test plan

  • cargo test -p graphrag-core --features huggingface-hub --lib embeddings::huggingface — 5/5 pass (3 pre-existing + 2 new regression tests)
  • cargo test -p graphrag-core --lib — 363/363 pass
  • cargo clippy -p graphrag-core --features huggingface-hub --all-targets -- -D warnings clean
  • CI green on PR

Refs

🤖 Generated with Claude Code

principle-lgtm and others added 5 commits June 2, 2026 19:49
…ings

Closes #167.

`HuggingFaceEmbeddings::embed` previously returned `Ok(vec![0.0; dims])`
behind the `neural-embeddings` feature flag, with only a `log::warn!` to
hint at the placeholder behaviour. Zero vectors pass cleanly through the
pipeline (chunking, vector store, similarity), producing
semantically-meaningless retrieval results that look structurally fine.

This was misleading enough that the README quickstart had to be switched
away from HuggingFace in a follow-up to PR #164.

Now `embed` returns `Err(GraphRAGError::Embedding)` whenever Candle
inference is invoked, with a message pointing at the working
`HttpEmbeddingProvider` alternatives. Adds two regression tests covering
both the not-initialized and the marked-initialized paths.

`neural.rs` rewritten from a one-line `// TODO` to a module-level doc
comment that documents the gap, so the feature flag's promise lines up
with the surface the crate actually offers.

Drive-by: convert `///!` outer doc comments at the top of
`huggingface.rs` to `//!` inner doc comments (clippy
`suspicious_doc_comments`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The `nix-check` fmt derivation (`cargo fmt -- --check`) failed on
huggingface.rs:307 — a block match arm needs a trailing comma per the
repo's rustfmt config. This was the only formatting diff; fixing it
unblocks the fmt check (and lets the cancelled doc/tests/benches checks
actually run).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stevei101 stevei101 merged commit f248273 into develop Jun 4, 2026
1 check failed
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.

graphrag-core: HuggingFace embeddings + neural.rs are stubs (return zero vectors)

2 participants