feat: dspy - Enable DSPy with dynamic context (e.g. from RAG)#3145
Open
tomasruizt wants to merge 2 commits intodeepset-ai:mainfrom
Open
feat: dspy - Enable DSPy with dynamic context (e.g. from RAG)#3145tomasruizt wants to merge 2 commits intodeepset-ai:mainfrom
tomasruizt wants to merge 2 commits intodeepset-ai:mainfrom
Conversation
Add a `pipeline_inputs` parameter to `DSPySignatureChatGenerator` listing signature input fields that should be exposed as Haystack pipeline input sockets via `component.set_input_type`. Without this, signature fields are only reachable through `**kwargs` on direct `run()` calls and are invisible to `Pipeline.connect()`, which makes RAG-style wiring (retriever.documents -> llm.context) impossible. Add a unit test that wires an `InMemoryBM25Retriever` to the chat generator inside a `Pipeline` and asserts the retrieved context reaching the DSPy module is question-dependent. Related to deepset-ai#1635.
|
|
Contributor
Coverage report (dspy)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Member
|
I'll take a look in the next few days... |
Member
|
@julian-risch I'd also appreciate your opinion |
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.
Related Issues
Context
The original DSPy + Haystack cookbook notebook demonstrates a RAG flow where a retriever dynamically looks up the context for each question. With the recently merged
DSPySignatureChatGenerator(#2831), this exact use case is not yet possible inside a HaystackPipeline:run()declares onlymessagesandgeneration_kwargsas input sockets.contextlive behind**kwargs, soPipeline.connect()cannot bind anything to them.The net effect: today the chat generator only works with static, hardcoded context (as in
test_run_with_input_mappingandtest_live_run_with_multi_field_signature). A retriever cannot dynamically supply question-dependent context.Proposed Changes
Add a
pipeline_inputs: list[str]parameter toDSPySignatureChatGenerator. When set, the listed signature input fields are registered as real Haystack input sockets viacomponent.set_input_type(self, name, str, ""). This unlocks the pipeline input/output discovery mechanism, so a retriever can be wired directly to the generator and the context is resolved at run time, per question. See the new unit testtest_rag_pipeline_question_dependent_contextfor a concrete usage example.The change should be backwards compatible: when
pipeline_inputsisNone, the existing behavior is unchanged. Let me know if this PR makes sense in your opinion @anakin87 @julian-rischHow did you test it?
test_rag_pipeline_question_dependent_contextthat wiresInMemoryBM25Retrieverto theDSPySignatureChatGeneratorinside aPipelineand asserts the retrieved context reaching the (mocked) DSPy module is question-dependent.hatch run test:unit— 39 passedhatch run test:types— no issueshatch run fmt— cleanChecklist
AI disclosure: Claude Code was used.