Skip to content

fix: meta_fields_to_embed dropping falsy metadata - #11412

Merged
sjrl merged 2 commits into
deepset-ai:mainfrom
RitwijParmar:codex/haystack-preserve-falsy-meta-fields
Jun 3, 2026
Merged

sjrl merged 2 commits into
deepset-ai:mainfrom
RitwijParmar:codex/haystack-preserve-falsy-meta-fields

Conversation

@RitwijParmar

Copy link
Copy Markdown
Contributor

Summary

Fixes #11405.

Several components used a truthiness check while preparing meta_fields_to_embed values:

if key in doc.meta and doc.meta[key]

That silently dropped valid metadata values such as 0 and False, changing the text passed into embedding/ranking without warning. The affected paths now match the existing OpenAI/Azure embedder behavior and only skip metadata that is absent or explicitly None.

Updated components:

  • SentenceTransformersDocumentEmbedder
  • SentenceTransformersSparseDocumentEmbedder
  • SentenceTransformersSimilarityRanker
  • SentenceTransformersDiversityRanker
  • TransformersSimilarityRanker

Tests

  • .venv/bin/python -m pytest test/components/embedders/test_sentence_transformers_document_embedder.py::TestSentenceTransformersDocumentEmbedder::test_embed_metadata_preserves_falsy_values test/components/embedders/test_sentence_transformers_sparse_document_embedder.py::TestSentenceTransformersDocumentEmbedder::test_embed_metadata_preserves_falsy_values test/components/rankers/test_sentence_transformers_similarity.py::TestSentenceTransformersSimilarityRanker::test_embed_meta_preserves_falsy_values test/components/rankers/test_sentence_transformers_diversity.py::TestSentenceTransformersDiversityRanker::test_prepare_texts_to_embed_preserves_falsy_meta_values test/components/rankers/test_transformers_similarity.py::TestSimilarityRanker::test_embed_meta_preserves_falsy_values
  • python -m ruff check <changed files>
  • python -m ruff format --check <changed files>
  • git diff --check

@RitwijParmar
RitwijParmar requested a review from a team as a code owner May 26, 2026 18:53
@RitwijParmar
RitwijParmar requested review from sjrl and removed request for a team May 26, 2026 18:53
@vercel

vercel Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

@RitwijParmar is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented May 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/embedders
  sentence_transformers_document_embedder.py
  sentence_transformers_sparse_document_embedder.py
  haystack/components/rankers
  sentence_transformers_diversity.py
  sentence_transformers_similarity.py
  transformers_similarity.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl

sjrl commented May 27, 2026

Copy link
Copy Markdown
Contributor

Hey @RitwijParmar thanks for the contribution! Could you take a look at our contribution guidelines on how to add a release note? https://github.com/deepset-ai/haystack/blob/main/CONTRIBUTING.md#release-notes

@julian-risch julian-risch changed the title Fix meta_fields_to_embed dropping falsy metadata fix: meta_fields_to_embed dropping falsy metadata May 29, 2026
biswajeetdev

This comment was marked as spam.

@RitwijParmar

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer. I added the release note in bfc18f4.

Validated with:
/Users/ritwij/Library/Python/3.9/bin/uv run --with hatch hatch run reno lint -> passed

@github-actions github-actions Bot added the type:documentation Improvements on the docs label Jun 3, 2026

@sjrl sjrl 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.

Thanks for the contribution!

@sjrl
sjrl merged commit dd5efef into deepset-ai:main Jun 3, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

meta_fields_to_embed silently drops valid falsy metadata values (0, False)

4 participants