Repository navigation
Conversation
generate_text unwrapped the generator's run() output as pipeline output (nested under the component name), but component-level run() returns replies at the top level, so the sync path always returned empty text. Read the replies directly, as agenerate_text does via the pipeline. Pin the ai-frameworks extra to haystack-ai<3 as well: both haystack wrappers are written against the 2.x API (top-level AsyncPipeline and string-prompt generators), which haystack-ai 3.x removed.
This branch has not been deployed
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.
Issue Link / Problem Description
HaystackLLMWrapper.generate_textalways returned empty text.Root cause:
generate_textcalls the generator component'srun()directly, but unwrapped the result as pipeline output —component_output.get("llm", {}).get("replies", [])atsrc/ragas/llms/haystack_wrapper.py:107. A component-levelrun()returns replies at the top level of the dict; onlyPipeline/AsyncPipelineruns nest component output under the component name. Verified against the installed haystack-ai 2.31.0:So the sync path always produced
"", whileagenerate_text(src/ragas/llms/haystack_wrapper.py:127-129), which goes through the pipeline, worked.Second problem: with the extra unpinned,
pip install ragas[ai-frameworks]currently resolves haystack-ai 3.x (3.3.0 today), which removed bothhaystack.AsyncPipelineand thehaystack.components.generators.openai|azure|hugging_face_*modules the wrapper imports — soHaystackLLMWrapper.__init__raises the misleadingImportError: Haystack is not installed...even though haystack is installed.src/ragas/embeddings/haystack_wrapper.py:58imports the same removed API.Changes Made
src/ragas/llms/haystack_wrapper.py:generate_textnow reads replies from the component output directly (component_output.get("replies", [])), mirroring whatagenerate_textachieves through the pipeline.pyproject.toml: pinned theai-frameworksextra tohaystack-ai<3. Both haystack wrappers are written against the 2.x API (top-levelAsyncPipeline, string-prompt generators), which 3.x removed, so the extra otherwise installs a version the wrappers cannot import. A 3.x port (chat generators, message-based API) would be a rewrite of both wrappers and is left as a separate effort.tests/unit/llms/test_haystack_wrapper.py: new regression tests forgenerate_textandagenerate_text, using fakes that mirror the component/pipeline output contracts (CI's minimal dev install does not include haystack-ai, so the tests fake the 2.x import surface and run regardless of the installed haystack version).Testing
How to Test
uv pip install "haystack-ai<3"(resolves 2.31.0), then constructHaystackLLMWrapper(haystack_generator=OpenAIGenerator(api_key=Secret.from_token("dummy")))— imports and construction succeed (with the unpinned extra, 3.3.0 installs and construction raises the misleadingImportError)OpenAIGenerator.runpatched to return{"replies": ["real reply"], "meta": [{}]}:wrapper.generate_text(StringPromptValue(text="hi"))returns"real reply"; before the fix it returned""Commands and results (fresh
.venv, Python 3.13,uv pip install -e ".[dev-minimal]"; locally alsolangchain-community==0.4.0, since 0.4.2 removedlangchain_community.chat_models.vertexaiwhichragas/llms/base.py:12imports — pre-existing and unrelated):pytest tests/unit/llms/test_haystack_wrapper.py -v:FAILED ...::test_generate_text_returns_component_reply - AssertionError: assert '' == 'hello world'(1 failed, 1 passed)2 passedpytest tests/unit/llms/ -q:58 passedpytest tests/unit/test_import.py -q:3 passed, 1 failed— the failure (test_wrappers_with_missing_haystack,ModuleNotFoundError: No module named 'llama_index') is pre-existing:llama_indexis not part of the dev-minimal install, and the test fails identically on the unpatched treeruff check src docs tests --exclude src/ragas/_version.py --config pyproject.toml:All checks passed!ruff format --checkon the two changed Python files:2 files already formatted(the repo-wide check also flags 88 pre-existing markdown formatting issues underdocs/, outside this diff)pyright -p pyproject.toml src: 5 pre-existing errors insrc/ragas/cli.pyandsrc/ragas/integrations/tracing/{langfuse,mlflow}.py(files this PR does not touch);haystack_wrapper.pyreports0 errorsReferences
haystack.components.generators.chat.*and removed top-levelAsyncPipeline; the string-prompt generators the wrappers use are already deprecated in 2.x ("will be removed in Haystack 3.0")docs/howtos/integrations/haystack.mdcovers the separateragas-haystackpackage, not these in-repo wrappersScreenshots/Examples (if applicable)
With haystack-ai 2.31.0 and a generator whose
run()returns{"replies": ["real reply"], ...}:wrapper.generate_text(prompt)→Generation(text="")wrapper.generate_text(prompt)→Generation(text="real reply")