Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

added tests and docs; applied reviews

zilto5d98a9f27a89
diff --git a/burr/integrations/haystack.py b/burr/integrations/haystack.py
index 88b5a84f..162092f5 100644
--- a/burr/integrations/haystack.py
+++ b/burr/integrations/haystack.py
@@ -1,4 +1,6 @@
-from typing import Any, Optional, Union
+import inspect
+from collections.abc import Mapping
+from typing import Any, Optional, Sequence, Union
from haystack import Pipeline
from haystack.core.component import Component
@@ -9,8 +11,16 @@ from burr.core.graph import Graph, GraphBuilder
from burr.core.state import State
+# TODO show OpenTelemetry integration
class HaystackAction(Action):
- """Create a Burr `Action` from a Haystack `Component`."""
+ """Burr ``Action`` wrapping a Haystack ``Component``.
+
+ Haystack ``Component`` is the basic block of a Haystack ``Pipeline``.
+ A ``Component`` is instantiated, then it receives inputs for its ``.run()`` method
+ and returns output values.
+
+ Learn more about components here: https://docs.haystack.deepset.ai/docs/custom-components
+ """
def __init__(
self,
@@ -20,46 +30,110 @@ class HaystackAction(Action):
name: Optional[str] = None,
bound_params: Optional[dict] = None,
):
- """
- Notes
- - need to figure out how to use bind
- - you can use `action.bind()` to set values of `Component.run()`.
+ """Create a Burr ``Action`` from a Haystack ``Component``.
+
+ :param component: Haystack ``Component`` to wrap
+ :param reads: State fields read and passed to ``Component.run()``
+ :param writes: State fields where results of ``Component.run()`` are written
+ :param name: Name of the action. Can be set later via ``.with_name()`` or in the
+ ``ApplicationBuilder``.
+ :param bound_params: Parameters to bind to the `Component.run()` method.
+
+ Basic example:
+
+ .. code-block:: python
+
+ from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
+ from haystack.document_stores.in_memory import InMemoryDocumentStore
+ from burr.core import ApplicationBuilder
+ from burr.integrations.haystack import HaystackAction
+
+ retrieve_documents = HaystackAction(
+ component=InMemoryEmbeddingRetriever(InMemoryDocumentStore()),
+ name="retrieve_documents",
+ reads=["query_embedding"],
+ writes=["documents"],
+ )
+
+ app = (
+ ApplicationBuilder()
+ .with_actions(retrieve_documents)
+ .with_transitions("retrieve_documents", "retrieve_documents")
+ .with_entrypoint("retrieve_documents")
+ .build()
+ )
"""
self._component = component
self._name = name
- self._reads = list(reads.keys()) if isinstance(reads, dict) else reads
- self._writes = list(writes.values()) if isinstance(writes, dict) else writes
self._bound_params = bound_params if bound_params is not None else {}
- self._socket_mapping = {}
- if isinstance(reads, dict):
- for state_field, socket_name in reads.items():
- self._socket_mapping[socket_name] = state_field
+ # NOTE input and output socket mappings are kept separately to avoid naming conflicts.
+ if isinstance(reads, Mapping):
+ self._input_socket_mapping = reads
+ self._reads = list(set(reads.values()))
+ elif isinstance(reads, Sequence):
+ self._input_socket_mapping = {socket_name: socket_name for socket_name in reads}
+ self._reads = reads
+ else:
+ raise TypeError(f"`reads` must be a sequence or mapping. Received: {type(reads)}")
+
+ self._validate_input_sockets()
+
+ if isinstance(writes, Mapping):
+ self._output_socket_mapping = writes
+ self._writes = list(writes.keys())
+ elif isinstance(writes, Sequence):
+ self._output_socket_mapping = {socket_name: socket_name for socket_name in writes}
+ self._writes = writes
+ else:
+ raise TypeError(f"`writes` must be a sequence or mapping. Received: {type(writes)}")
+
+ self._validate_output_sockets()
+
+ def _validate_input_sockets(self) -> None:
+ component_inputs = self._component.__haystack_input__._sockets_dict.keys()
+ for socket_name in self._input_socket_mapping.keys():
+ if socket_name not in component_inputs:
+ raise ValueError(
+ f"Socket `{socket_name}` not found in `Component` inputs: {component_inputs}"
+ )
+
+ def _validate_output_sockets(self) -> None:
+ component_outputs = self._component.__haystack_output__._sockets_dict.keys()
+ for socket_name in self._output_socket_mapping.values():
+ if socket_name not in component_outputs:
+ raise ValueError(
+ f"Socket `{socket_name}` not found in `Component` outputs: {component_outputs}"
+ )
- if isinstance(writes, dict):
- for socket_name, state_field in writes.items():
- self._socket_mapping[socket_name] = state_field
+ @property
+ def component(self) -> Component:
+ """Haystack `Component` used by this action."""
+ return self._component
@property
def reads(self) -> list[str]:
+ """State fields read and passed to `Component.run()`"""
return self._reads
@property
def writes(self) -> list[str]:
+ """State fields where results of `Component.run()` are written."""
return self._writes
@property
def inputs(self) -> tuple[dict[str, str], dict[str, str]]:
- """Return dictionaries of required and optional inputs."""
+ """Return dictionaries of required and optional inputs for `Component.run()`"""
required_inputs, optional_inputs = {}, {}
for socket_name, input_socket in self._component.__haystack_input__._sockets_dict.items():
- state_field_name = self._socket_mapping.get(socket_name, socket_name)
+ state_field_name = self._input_socket_mapping.get(socket_name, socket_name)
- if state_field_name in self.reads:
- continue
- elif state_field_name in self._bound_params:
+ # if we expect the value to come from state (previous actions) or it's a
+ # bound parameter, then this socket isn't a user-provided input
+ if state_field_name in self.reads or state_field_name in self._bound_params:
continue
+ # determine if input is required or optional based on the socket's default value
if input_socket.default_value == haystack_empty:
required_inputs[state_field_name] = input_socket.type
else:
@@ -68,47 +142,68 @@ class HaystackAction(Action):
return required_inputs, optional_inputs
def run(self, state: State, **run_kwargs) -> dict[str, Any]:
- """Call the Haystack `Component.run()` method. It returns a dictionary
- of results with mapping {socket_name: value}.
+ """Call the Haystack `Component.run()` method.
- Values come from 3 sources:
- - bound parameters (from HaystackAction instantiation, or by using `.bind()`)
+ :param state: State object of the application. It contains some input values
+ for ``Component.run()``.
+ :param run_kwargs: User-provided inputs for ``Component.run()``.
+ :return: Dictionary of results with mapping ``{socket_name: value}``.
+
+ Note, values come from 3 sources:
- state (from previous actions)
- - run_kwargs (inputs from `Application.run()`)
+ - run_kwargs (inputs from ``Application.run()``)
+ - bound parameters (from ``HaystackAction`` instantiation)
"""
values = {}
# here, precedence matters. Alternatively, we could unpack all dictionaries at once
# which would throw an error for key collisions
- for param, value in self._bound_params.items():
- values[param] = value
+ for input_socket_name, value in self._bound_params.items():
+ values[input_socket_name] = value
- for param in self.reads:
- values[param] = state[param]
+ for input_socket_name, state_field_name in self._input_socket_mapping.items():
+ try:
+ values[input_socket_name] = state[state_field_name]
+ except KeyError as e:
+ raise ValueError(f"No value found in state for field: {state_field_name}") from e
- for param, value in run_kwargs.items():
- values[param] = value
+ for input_socket_name, value in run_kwargs.items():
+ values[input_socket_name] = value
return self._component.run(**values)
def update(self, result: dict, state: State) -> State:
- """Update the state using the results of `Component.run()`."""
+ """Update the state using the results of ``Component.run()``.
+ The output socket name is mapped to the Burr state field name.
+
+ Values returned by ``Component.run()`` that aren't in ``writes`` are ignored.
+ """
+ # TODO we could want to handle ``.update()`` and ``.append()`` differently
state_update = {}
- for socket_name, value in result.items():
- state_field_name = self._socket_mapping.get(socket_name, socket_name)
- if state_field_name in self.writes:
- state_update[state_field_name] = value
+ for state_field_name, output_socket_name in self._output_socket_mapping.items():
+ if state_field_name in self.writes:
+ try:
+ state_update[state_field_name] = result[output_socket_name]
+ except KeyError as e:
+ raise ValueError(
+ f"Socket `{output_socket_name}` missing from output of `Component.run()`"
+ ) from e
+ print(state_update)
return state.update(**state_update)
- def bind(self, **kwargs):
- """Bind a parameter for the `Component.run()` call."""
- self._bound_params.update(**kwargs)
- return self
+ def get_source(self) -> str:
+ """Return the source code of the Haystack ``Component``.
+
+ NOTE. This doesn't include the initialization parameters of the ``Component``.
+ This can be obtained using``HaystackAction().component.to_dict()``, but this
+ method might is not implemented for all components.
+ """
+ return inspect.getsource(self._component.__class__)
-def _socket_name_mapping(pipeline) -> dict[str, str]:
- """Map socket names to a single state field name.
+def _socket_name_mapping(sockets_connections: list[tuple[str, str]]) -> dict[str, str]:
+ """Map socket names to a single socket name.
In Haystack, components communicate via sockets. A socket called
"embedding" in one component can be renamed to "query_embedding" when
@@ -119,27 +214,22 @@ def _socket_name_mapping(pipeline) -> dict[str, str]:
creates a mapping {socket_name: state_field} to rename sockets when creating
the Burr `Graph`.
"""
- sockets_connections = [
- (edge_data["from_socket"].name, edge_data["to_socket"].name)
- for _, _, edge_data in pipeline.graph.edges.data()
- ]
- mapping = {}
-
+ all_connections: dict[str, set[str]] = {}
for from_, to in sockets_connections:
- if from_ not in mapping:
- mapping[from_] = {from_}
- mapping[from_].add(to)
+ if from_ not in all_connections:
+ all_connections[from_] = {from_}
+ all_connections[from_].add(to)
- if to not in mapping:
- mapping[to] = {to}
- mapping[to].add(from_)
+ if to not in all_connections:
+ all_connections[to] = {to}
+ all_connections[to].add(from_)
- result = {}
- for key, values in mapping.items():
+ reduced_mapping: dict[str, str] = {}
+ for key, values in all_connections.items():
unique_name = min(values)
- result[key] = unique_name
+ reduced_mapping[key] = unique_name
- return result
+ return reduced_mapping
def _connected_inputs(pipeline) -> dict[str, list[str]]:
@@ -167,30 +257,47 @@ def _connected_outputs(pipeline) -> dict[str, list[str]]:
def haystack_pipeline_to_burr_graph(pipeline: Pipeline) -> Graph:
"""Convert a Haystack `Pipeline` to a Burr `Graph`.
+ NOTE. This currently doesn't support Haystack pipelines with
+ parallel branches. Learn more https://docs.haystack.deepset.ai/docs/pipelines#branching
+
From the Haystack `Pipeline`, we can easily retrieve transitions.
For actions, we need to create `HaystackAction` from components
and map their sockets to Burr state fields
+
+ EXPERIMENTAL: This feature is experimental and may change in the future.
+ Changes to Haystack or Burr could impact this function. Please let us know if
+ you encounter any issues.
"""
- socket_mapping = _socket_name_mapping(pipeline)
- connected_inputs = _connected_inputs(pipeline)
- connected_outputs = _connected_outputs(pipeline)
+
+ # get all socket connections in the pipeline
+ sockets_connections = [
+ (edge_data["from_socket"].name, edge_data["to_socket"].name)
+ for _, _, edge_data in pipeline.graph.edges.data()
+ ]
+ socket_mapping = _socket_name_mapping(sockets_connections)
transitions = [(from_, to) for from_, to, _ in pipeline.graph.edges]
+ # get all input and output sockets that are connected to other components
+ connected_inputs = _connected_inputs(pipeline)
+ connected_outputs = _connected_outputs(pipeline)
+
actions = []
for component_name, component in pipeline.walk():
- inputs_from_state = [
- socket_mapping[socket_name] for socket_name in connected_inputs[component_name]
- ]
- outputs_to_state = [
- socket_mapping[socket_name] for socket_name in connected_outputs[component_name]
- ]
+ inputs_mapping = {
+ socket_name: socket_mapping[socket_name]
+ for socket_name in connected_inputs[component_name]
+ }
+ outputs_mapping = {
+ socket_mapping[socket_name]: socket_name
+ for socket_name in connected_outputs[component_name]
+ }
haystack_action = HaystackAction(
name=component_name,
component=component,
- reads=inputs_from_state,
- writes=outputs_to_state,
+ reads=inputs_mapping,
+ writes=outputs_mapping,
)
actions.append(haystack_action)
diff --git a/docs/reference/integrations/haystack.rst b/docs/reference/integrations/haystack.rst
new file mode 100644
index 00000000..045a099b
--- /dev/null
+++ b/docs/reference/integrations/haystack.rst
@@ -0,0 +1,9 @@
+========
+Haystack
+========
+
+The Haystack integration allows you to use ``Component`` as Burr ``Action`` using the ``HaystackAction`` construct. You can visit the examples in ``burr/examples/haystack-integration`` for a notebook tutorial.
+
+.. autoclass:: burr.integrations.haystack.HaystackAction
+
+.. autofunction:: burr.integrations.haystack.haystack_pipeline_to_burr_graph
diff --git a/examples/haystack-integration/__init__.py b/examples/haystack-integration/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/examples/haystack-integration/application.py b/examples/haystack-integration/application.py
new file mode 100644
index 00000000..584ad93f
--- /dev/null
+++ b/examples/haystack-integration/application.py
@@ -0,0 +1,77 @@
+import os
+
+from haystack.components.builders import PromptBuilder
+from haystack.components.embedders import SentenceTransformersTextEmbedder
+from haystack.components.generators import OpenAIGenerator
+from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
+from haystack.document_stores.in_memory import InMemoryDocumentStore
+
+from burr.core import ApplicationBuilder, State, action
+from burr.integrations.haystack import HaystackAction
+
+# dummy OpenAI key to avoid raising an error
+os.environ["OPENAI_API_KEY"] = "sk-..."
+
+
+embed_text = HaystackAction(
+ component=SentenceTransformersTextEmbedder(model="sentence-transformers/all-MiniLM-L6-v2"),
+ name="embed_text",
+ reads=[],
+ writes={"embedding": "query_embedding"},
+)
+
+
+retrieve_documents = HaystackAction(
+ component=InMemoryEmbeddingRetriever(InMemoryDocumentStore()),
+ name="retrieve_documents",
+ reads=["query_embedding"],
+ writes=["documents"],
+)
+
+
+build_prompt = HaystackAction(
+ component=PromptBuilder(template="Document: {{documents}} Question: {{question}}"),
+ name="build_prompt",
+ reads=["documents"],
+ writes={"prompt": "question_prompt"},
+)
+
+
+generate_answer = HaystackAction(
+ component=OpenAIGenerator(model="gpt-4o-mini"),
+ name="generate_answer",
+ reads={"question_prompt": "prompt"},
+ writes={"text": "answer"},
+)
+
+
+@action(reads=["answer"], writes=[])
+def display_answer(state: State) -> State:
+ print(state["answer"])
+ return state
+
+
+def build_application():
+ return (
+ ApplicationBuilder()
+ .with_actions(
+ embed_text,
+ retrieve_documents,
+ build_prompt,
+ generate_answer,
+ display_answer,
+ )
+ .with_transitions(
+ ("embed_text", "retrieve_documents"),
+ ("retrieve_documents", "build_prompt"),
+ ("build_prompt", "generate_answer"),
+ ("generate_answer", "display_answer"),
+ )
+ .with_entrypoint("embed_text")
+ .build()
+ )
+
+
+if __name__ == "__main__":
+ app = build_application()
+ app.visualize(include_state=True)
diff --git a/examples/haystack-integration/notebook.ipynb b/examples/haystack-integration/notebook.ipynb
index 4578d1ac..2bbed2a4 100644
--- a/examples/haystack-integration/notebook.ipynb
+++ b/examples/haystack-integration/notebook.ipynb
@@ -21,7 +21,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 1,
"metadata": {},
"outputs": [
{
@@ -91,7 +91,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 2,
"metadata": {},
"outputs": [
{
@@ -172,10 +172,10 @@
"</svg>\n"
],
"text/plain": [
- "<graphviz.graphs.Digraph at 0x7f923da79a90>"
+ "<graphviz.graphs.Digraph at 0x7f49360dea10>"
]
},
- "execution_count": 3,
+ "execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
@@ -267,7 +267,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -301,13 +301,13 @@
"Note that some for some `HaystackAction`, `reads` and `writes` are dictionaries instead of the usual lists. This helps map the values from the Burr `State` to the Haystack `Component.run()` parameters and outputs. \n",
"\n",
"For example, in `generate_answer`:\n",
- " - `reads={\"question_prompt\": \"prompt\"}` maps the state to the run method `Component.run(prompt=state[\"question_prompt\"])`\n",
- " - `writes={\"text\": \"answer\"}` maps the results of `.run()` to the state update `state.update(answer=Component.run(...)[\"text\"])`"
+ " - `reads={\"prompt\": \"question_prompt\"}` takes the value `State[\"question_prompt\"]` and assigns it to `Component.run(prompt=...)`\n",
+ " - `writes={\"answer\": \"replies\"}` takes the value `Component.run(...)[\"replies\"]` and assigns it to `state.update(answer=...)`"
]
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 4,
"metadata": {},
"outputs": [
{
@@ -319,193 +319,193 @@
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
- "<svg width=\"1464pt\" height=\"375pt\"\n",
- " viewBox=\"0.00 0.00 1463.50 375.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+ "<svg width=\"1400pt\" height=\"375pt\"\n",
+ " viewBox=\"0.00 0.00 1400.00 375.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 371)\">\n",
"<title>%3</title>\n",
- "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-371 1459.5,-371 1459.5,4 -4,4\"/>\n",
+ "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-371 1396,-371 1396,4 -4,4\"/>\n",
"<!-- embed_text -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>embed_text</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1443.5,-301C1443.5,-301 1217.5,-301 1217.5,-301 1211.5,-301 1205.5,-295 1205.5,-289 1205.5,-289 1205.5,-276 1205.5,-276 1205.5,-270 1211.5,-264 1217.5,-264 1217.5,-264 1443.5,-264 1443.5,-264 1449.5,-264 1455.5,-270 1455.5,-276 1455.5,-276 1455.5,-289 1455.5,-289 1455.5,-295 1449.5,-301 1443.5,-301\"/>\n",
- "<text text-anchor=\"middle\" x=\"1330.5\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">embed_text(): query_embedding</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1380,-301C1380,-301 1154,-301 1154,-301 1148,-301 1142,-295 1142,-289 1142,-289 1142,-276 1142,-276 1142,-270 1148,-264 1154,-264 1154,-264 1380,-264 1380,-264 1386,-264 1392,-270 1392,-276 1392,-276 1392,-289 1392,-289 1392,-295 1386,-301 1380,-301\"/>\n",
+ "<text text-anchor=\"middle\" x=\"1267\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">embed_text(): query_embedding</text>\n",
"</g>\n",
"<!-- retrieve_documents -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>retrieve_documents</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1144,-235C1144,-235 785,-235 785,-235 779,-235 773,-229 773,-223 773,-223 773,-210 773,-210 773,-204 779,-198 785,-198 785,-198 1144,-198 1144,-198 1150,-198 1156,-204 1156,-210 1156,-210 1156,-223 1156,-223 1156,-229 1150,-235 1144,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"964.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">retrieve_documents(query_embedding): documents</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1126.5,-235C1126.5,-235 767.5,-235 767.5,-235 761.5,-235 755.5,-229 755.5,-223 755.5,-223 755.5,-210 755.5,-210 755.5,-204 761.5,-198 767.5,-198 767.5,-198 1126.5,-198 1126.5,-198 1132.5,-198 1138.5,-204 1138.5,-210 1138.5,-210 1138.5,-223 1138.5,-223 1138.5,-229 1132.5,-235 1126.5,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"947\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">retrieve_documents(query_embedding): documents</text>\n",
"</g>\n",
"<!-- embed_text&#45;&gt;retrieve_documents -->\n",
"<g id=\"edge11\" class=\"edge\">\n",
"<title>embed_text&#45;&gt;retrieve_documents</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M1230,-263.93C1181.9,-255.51 1124.16,-245.42 1074.84,-236.79\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"1075.22,-233.31 1064.77,-235.03 1074.02,-240.2 1075.22,-233.31\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M1179.14,-263.93C1137.42,-255.58 1087.44,-245.59 1044.55,-237.01\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"1045.16,-233.56 1034.67,-235.03 1043.79,-240.43 1045.16,-233.56\"/>\n",
"</g>\n",
"<!-- input__text -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>input__text</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1378,-367 1283,-367 1283,-330 1378,-330 1378,-367\"/>\n",
- "<text text-anchor=\"middle\" x=\"1330.5\" y=\"-344.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: text</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1314.5,-367 1219.5,-367 1219.5,-330 1314.5,-330 1314.5,-367\"/>\n",
+ "<text text-anchor=\"middle\" x=\"1267\" y=\"-344.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: text</text>\n",
"</g>\n",
"<!-- input__text&#45;&gt;embed_text -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>input__text&#45;&gt;embed_text</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M1330.5,-329.67C1330.5,-323.99 1330.5,-317.55 1330.5,-311.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"1334,-311.23 1330.5,-301.23 1327,-311.23 1334,-311.23\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M1267,-329.67C1267,-323.99 1267,-317.55 1267,-311.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"1270.5,-311.23 1267,-301.23 1263.5,-311.23 1270.5,-311.23\"/>\n",
"</g>\n",
"<!-- build_prompt -->\n",
"<g id=\"node8\" class=\"node\">\n",
"<title>build_prompt</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M751.5,-169C751.5,-169 447.5,-169 447.5,-169 441.5,-169 435.5,-163 435.5,-157 435.5,-157 435.5,-144 435.5,-144 435.5,-138 441.5,-132 447.5,-132 447.5,-132 751.5,-132 751.5,-132 757.5,-132 763.5,-138 763.5,-144 763.5,-144 763.5,-157 763.5,-157 763.5,-163 757.5,-169 751.5,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"599.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">build_prompt(documents): question_prompt</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M752,-169C752,-169 448,-169 448,-169 442,-169 436,-163 436,-157 436,-157 436,-144 436,-144 436,-138 442,-132 448,-132 448,-132 752,-132 752,-132 758,-132 764,-138 764,-144 764,-144 764,-157 764,-157 764,-163 758,-169 752,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"600\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">build_prompt(documents): question_prompt</text>\n",
"</g>\n",
"<!-- retrieve_documents&#45;&gt;build_prompt -->\n",
"<g id=\"edge12\" class=\"edge\">\n",
"<title>retrieve_documents&#45;&gt;build_prompt</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M864.28,-197.93C816.3,-189.51 758.73,-179.42 709.54,-170.79\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"709.95,-167.31 699.5,-169.03 708.74,-174.21 709.95,-167.31\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M851.72,-197.93C806.2,-189.53 751.6,-179.46 704.9,-170.85\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"705.53,-167.41 695.07,-169.03 704.26,-174.29 705.53,-167.41\"/>\n",
"</g>\n",
- "<!-- input__top_k -->\n",
+ "<!-- input__return_embedding -->\n",
"<g id=\"node4\" class=\"node\">\n",
- "<title>input__top_k</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"684,-301 579,-301 579,-264 684,-264 684,-301\"/>\n",
- "<text text-anchor=\"middle\" x=\"631.5\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: top_k</text>\n",
+ "<title>input__return_embedding</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"710.5,-301 515.5,-301 515.5,-264 710.5,-264 710.5,-301\"/>\n",
+ "<text text-anchor=\"middle\" x=\"613\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: return_embedding</text>\n",
"</g>\n",
- "<!-- input__top_k&#45;&gt;retrieve_documents -->\n",
+ "<!-- input__return_embedding&#45;&gt;retrieve_documents -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
- "<title>input__top_k&#45;&gt;retrieve_documents</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M684.17,-266.23C687.32,-265.44 690.45,-264.69 693.5,-264 739.8,-253.52 791.03,-244.17 836.37,-236.65\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"836.95,-240.1 846.25,-235.02 835.81,-233.19 836.95,-240.1\"/>\n",
+ "<title>input__return_embedding&#45;&gt;retrieve_documents</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M704.71,-263.93C748.34,-255.57 800.64,-245.55 845.46,-236.96\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"846.33,-240.35 855.5,-235.03 845.02,-233.48 846.33,-240.35\"/>\n",
"</g>\n",
"<!-- input__scale_score -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>input__scale_score</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"848.5,-301 702.5,-301 702.5,-264 848.5,-264 848.5,-301\"/>\n",
- "<text text-anchor=\"middle\" x=\"775.5\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: scale_score</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"875,-301 729,-301 729,-264 875,-264 875,-301\"/>\n",
+ "<text text-anchor=\"middle\" x=\"802\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: scale_score</text>\n",
"</g>\n",
"<!-- input__scale_score&#45;&gt;retrieve_documents -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>input__scale_score&#45;&gt;retrieve_documents</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M827.4,-263.93C850.84,-255.99 878.71,-246.55 903.17,-238.27\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"904.37,-241.56 912.72,-235.03 902.13,-234.93 904.37,-241.56\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M842.01,-263.84C859.28,-256.22 879.66,-247.22 897.84,-239.2\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"899.39,-242.34 907.12,-235.1 896.56,-235.94 899.39,-242.34\"/>\n",
"</g>\n",
- "<!-- input__return_embedding -->\n",
+ "<!-- input__filters -->\n",
"<g id=\"node6\" class=\"node\">\n",
- "<title>input__return_embedding</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1062,-301 867,-301 867,-264 1062,-264 1062,-301\"/>\n",
- "<text text-anchor=\"middle\" x=\"964.5\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: return_embedding</text>\n",
+ "<title>input__filters</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1000.5,-301 893.5,-301 893.5,-264 1000.5,-264 1000.5,-301\"/>\n",
+ "<text text-anchor=\"middle\" x=\"947\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: filters</text>\n",
"</g>\n",
- "<!-- input__return_embedding&#45;&gt;retrieve_documents -->\n",
+ "<!-- input__filters&#45;&gt;retrieve_documents -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
- "<title>input__return_embedding&#45;&gt;retrieve_documents</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M964.5,-263.67C964.5,-257.99 964.5,-251.55 964.5,-245.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"968,-245.23 964.5,-235.23 961,-245.23 968,-245.23\"/>\n",
+ "<title>input__filters&#45;&gt;retrieve_documents</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M947,-263.67C947,-257.99 947,-251.55 947,-245.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"950.5,-245.23 947,-235.23 943.5,-245.23 950.5,-245.23\"/>\n",
"</g>\n",
- "<!-- input__filters -->\n",
+ "<!-- input__top_k -->\n",
"<g id=\"node7\" class=\"node\">\n",
- "<title>input__filters</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1187,-301 1080,-301 1080,-264 1187,-264 1187,-301\"/>\n",
- "<text text-anchor=\"middle\" x=\"1133.5\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: filters</text>\n",
+ "<title>input__top_k</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1123.5,-301 1018.5,-301 1018.5,-264 1123.5,-264 1123.5,-301\"/>\n",
+ "<text text-anchor=\"middle\" x=\"1071\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: top_k</text>\n",
"</g>\n",
- "<!-- input__filters&#45;&gt;retrieve_documents -->\n",
+ "<!-- input__top_k&#45;&gt;retrieve_documents -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
- "<title>input__filters&#45;&gt;retrieve_documents</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M1086.87,-263.84C1066.28,-256.04 1041.9,-246.81 1020.34,-238.65\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"1021.57,-235.37 1010.98,-235.1 1019.09,-241.91 1021.57,-235.37\"/>\n",
+ "<title>input__top_k&#45;&gt;retrieve_documents</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M1036.79,-263.84C1022.42,-256.43 1005.55,-247.72 990.33,-239.86\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"991.59,-236.58 981.1,-235.1 988.38,-242.8 991.59,-236.58\"/>\n",
"</g>\n",
"<!-- generate_answer -->\n",
"<g id=\"node12\" class=\"node\">\n",
"<title>generate_answer</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M470,-103C470,-103 165,-103 165,-103 159,-103 153,-97 153,-91 153,-91 153,-78 153,-78 153,-72 159,-66 165,-66 165,-66 470,-66 470,-66 476,-66 482,-72 482,-78 482,-78 482,-91 482,-91 482,-97 476,-103 470,-103\"/>\n",
- "<text text-anchor=\"middle\" x=\"317.5\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">generate_answer(question_prompt): answer</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M470.5,-103C470.5,-103 165.5,-103 165.5,-103 159.5,-103 153.5,-97 153.5,-91 153.5,-91 153.5,-78 153.5,-78 153.5,-72 159.5,-66 165.5,-66 165.5,-66 470.5,-66 470.5,-66 476.5,-66 482.5,-72 482.5,-78 482.5,-78 482.5,-91 482.5,-91 482.5,-97 476.5,-103 470.5,-103\"/>\n",
+ "<text text-anchor=\"middle\" x=\"318\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">generate_answer(question_prompt): answer</text>\n",
"</g>\n",
"<!-- build_prompt&#45;&gt;generate_answer -->\n",
"<g id=\"edge13\" class=\"edge\">\n",
"<title>build_prompt&#45;&gt;generate_answer</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M522.07,-131.93C485.7,-123.67 442.19,-113.8 404.66,-105.28\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"405.28,-101.83 394.76,-103.03 403.74,-108.66 405.28,-101.83\"/>\n",
- "</g>\n",
- "<!-- input__template -->\n",
- "<g id=\"node9\" class=\"node\">\n",
- "<title>input__template</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"391,-235 262,-235 262,-198 391,-198 391,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"326.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template</text>\n",
- "</g>\n",
- "<!-- input__template&#45;&gt;build_prompt -->\n",
- "<g id=\"edge6\" class=\"edge\">\n",
- "<title>input__template&#45;&gt;build_prompt</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M391.37,-199.92C394.12,-199.27 396.84,-198.63 399.5,-198 436.92,-189.16 478.31,-179.52 513.69,-171.32\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"514.54,-174.71 523.49,-169.04 512.96,-167.89 514.54,-174.71\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M522.57,-131.93C486.2,-123.67 442.69,-113.8 405.16,-105.28\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"405.78,-101.83 395.26,-103.03 404.24,-108.66 405.78,-101.83\"/>\n",
"</g>\n",
"<!-- input__template_variables -->\n",
- "<g id=\"node10\" class=\"node\">\n",
+ "<g id=\"node9\" class=\"node\">\n",
"<title>input__template_variables</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"608,-235 409,-235 409,-198 608,-198 608,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"508.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template_variables</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"443.5,-235 244.5,-235 244.5,-198 443.5,-198 443.5,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"344\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template_variables</text>\n",
"</g>\n",
"<!-- input__template_variables&#45;&gt;build_prompt -->\n",
- "<g id=\"edge7\" class=\"edge\">\n",
+ "<g id=\"edge6\" class=\"edge\">\n",
"<title>input__template_variables&#45;&gt;build_prompt</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M533.85,-197.67C543.89,-190.61 555.57,-182.39 566.28,-174.86\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"568.44,-177.63 574.6,-169.01 564.41,-171.9 568.44,-177.63\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M414.29,-197.93C447.03,-189.74 486.14,-179.97 520,-171.5\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"521.01,-174.85 529.87,-169.03 519.31,-168.06 521.01,-174.85\"/>\n",
"</g>\n",
"<!-- input__question -->\n",
- "<g id=\"node11\" class=\"node\">\n",
+ "<g id=\"node10\" class=\"node\">\n",
"<title>input__question</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"754.5,-235 626.5,-235 626.5,-198 754.5,-198 754.5,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"690.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: question</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"590,-235 462,-235 462,-198 590,-198 590,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"526\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: question</text>\n",
"</g>\n",
"<!-- input__question&#45;&gt;build_prompt -->\n",
- "<g id=\"edge8\" class=\"edge\">\n",
+ "<g id=\"edge7\" class=\"edge\">\n",
"<title>input__question&#45;&gt;build_prompt</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M665.15,-197.67C655.11,-190.61 643.43,-182.39 632.72,-174.86\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"634.59,-171.9 624.4,-169.01 630.56,-177.63 634.59,-171.9\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M546.61,-197.67C554.46,-190.89 563.53,-183.04 571.95,-175.76\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"574.48,-178.2 579.75,-169.01 569.9,-172.91 574.48,-178.2\"/>\n",
+ "</g>\n",
+ "<!-- input__template -->\n",
+ "<g id=\"node11\" class=\"node\">\n",
+ "<title>input__template</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"737.5,-235 608.5,-235 608.5,-198 737.5,-198 737.5,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"673\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template</text>\n",
+ "</g>\n",
+ "<!-- input__template&#45;&gt;build_prompt -->\n",
+ "<g id=\"edge8\" class=\"edge\">\n",
+ "<title>input__template&#45;&gt;build_prompt</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M652.67,-197.67C644.93,-190.89 635.98,-183.04 627.67,-175.76\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"629.8,-172.97 619.97,-169.01 625.19,-178.23 629.8,-172.97\"/>\n",
"</g>\n",
"<!-- display_answer -->\n",
"<g id=\"node15\" class=\"node\">\n",
"<title>display_answer</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M405,-37C405,-37 230,-37 230,-37 224,-37 218,-31 218,-25 218,-25 218,-12 218,-12 218,-6 224,0 230,0 230,0 405,0 405,0 411,0 417,-6 417,-12 417,-12 417,-25 417,-25 417,-31 411,-37 405,-37\"/>\n",
- "<text text-anchor=\"middle\" x=\"317.5\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">display_answer(answer): </text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M405.5,-37C405.5,-37 230.5,-37 230.5,-37 224.5,-37 218.5,-31 218.5,-25 218.5,-25 218.5,-12 218.5,-12 218.5,-6 224.5,0 230.5,0 230.5,0 405.5,0 405.5,0 411.5,0 417.5,-6 417.5,-12 417.5,-12 417.5,-25 417.5,-25 417.5,-31 411.5,-37 405.5,-37\"/>\n",
+ "<text text-anchor=\"middle\" x=\"318\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">display_answer(answer): </text>\n",
"</g>\n",
"<!-- generate_answer&#45;&gt;display_answer -->\n",
"<g id=\"edge14\" class=\"edge\">\n",
"<title>generate_answer&#45;&gt;display_answer</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M317.5,-65.67C317.5,-59.99 317.5,-53.55 317.5,-47.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"321,-47.23 317.5,-37.23 314,-47.23 321,-47.23\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M318,-65.67C318,-59.99 318,-53.55 318,-47.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"321.5,-47.23 318,-37.23 314.5,-47.23 321.5,-47.23\"/>\n",
"</g>\n",
- "<!-- input__generation_kwargs -->\n",
+ "<!-- input__streaming_callback -->\n",
"<g id=\"node13\" class=\"node\">\n",
- "<title>input__generation_kwargs</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"199,-169 0,-169 0,-132 199,-132 199,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"99.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: generation_kwargs</text>\n",
+ "<title>input__streaming_callback</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"200,-169 0,-169 0,-132 200,-132 200,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"100\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: streaming_callback</text>\n",
"</g>\n",
- "<!-- input__generation_kwargs&#45;&gt;generate_answer -->\n",
+ "<!-- input__streaming_callback&#45;&gt;generate_answer -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
- "<title>input__generation_kwargs&#45;&gt;generate_answer</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M159.36,-131.93C186.76,-123.88 219.4,-114.3 247.89,-105.94\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"249.17,-109.21 257.78,-103.03 247.19,-102.49 249.17,-109.21\"/>\n",
+ "<title>input__streaming_callback&#45;&gt;generate_answer</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M159.86,-131.93C187.26,-123.88 219.9,-114.3 248.39,-105.94\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"249.67,-109.21 258.28,-103.03 247.69,-102.49 249.67,-109.21\"/>\n",
"</g>\n",
- "<!-- input__streaming_callback -->\n",
+ "<!-- input__generation_kwargs -->\n",
"<g id=\"node14\" class=\"node\">\n",
- "<title>input__streaming_callback</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"417.5,-169 217.5,-169 217.5,-132 417.5,-132 417.5,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"317.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: streaming_callback</text>\n",
+ "<title>input__generation_kwargs</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"417.5,-169 218.5,-169 218.5,-132 417.5,-132 417.5,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"318\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: generation_kwargs</text>\n",
"</g>\n",
- "<!-- input__streaming_callback&#45;&gt;generate_answer -->\n",
+ "<!-- input__generation_kwargs&#45;&gt;generate_answer -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
- "<title>input__streaming_callback&#45;&gt;generate_answer</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M317.5,-131.67C317.5,-125.99 317.5,-119.55 317.5,-113.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"321,-113.23 317.5,-103.23 314,-113.23 321,-113.23\"/>\n",
+ "<title>input__generation_kwargs&#45;&gt;generate_answer</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M318,-131.67C318,-125.99 318,-119.55 318,-113.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"321.5,-113.23 318,-103.23 314.5,-113.23 321.5,-113.23\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
- "<graphviz.graphs.Digraph at 0x7f923db16590>"
+ "<graphviz.graphs.Digraph at 0x7f4936158c90>"
]
},
- "execution_count": 6,
+ "execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@@ -517,7 +517,7 @@
" component=SentenceTransformersTextEmbedder(model=\"sentence-transformers/all-MiniLM-L6-v2\"),\n",
" name=\"embed_text\",\n",
" reads=[],\n",
- " writes={\"embedding\": \"query_embedding\"},\n",
+ " writes={\"query_embedding\": \"embedding\"},\n",
")\n",
"\n",
"retrieve_documents = HaystackAction(\n",
@@ -531,14 +531,14 @@
" component=PromptBuilder(template=\"Document: {{documents}} Question: {{question}}\"),\n",
" name=\"build_prompt\",\n",
" reads=[\"documents\"],\n",
- " writes={\"prompt\": \"question_prompt\"},\n",
+ " writes={\"question_prompt\": \"prompt\"},\n",
")\n",
"\n",
"generate_answer = HaystackAction(\n",
" component=OpenAIGenerator(model=\"gpt-4o-mini\"),\n",
" name=\"generate_answer\",\n",
- " reads={\"question_prompt\": \"prompt\"},\n",
- " writes={\"text\": \"answer\"}\n",
+ " reads={\"prompt\": \"question_prompt\"},\n",
+ " writes={\"answer\": \"replies\"}\n",
")\n",
"\n",
"@action(reads=[\"answer\"], writes=[])\n",
@@ -583,7 +583,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -595,193 +595,181 @@
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
- "<svg width=\"1521pt\" height=\"309pt\"\n",
- " viewBox=\"0.00 0.00 1520.50 309.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+ "<svg width=\"1286pt\" height=\"309pt\"\n",
+ " viewBox=\"0.00 0.00 1286.00 309.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 305)\">\n",
"<title>%3</title>\n",
- "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-305 1516.5,-305 1516.5,4 -4,4\"/>\n",
+ "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-305 1282,-305 1282,4 -4,4\"/>\n",
"<!-- text_embedder -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>text_embedder</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1500.5,-235C1500.5,-235 1298.5,-235 1298.5,-235 1292.5,-235 1286.5,-229 1286.5,-223 1286.5,-223 1286.5,-210 1286.5,-210 1286.5,-204 1292.5,-198 1298.5,-198 1298.5,-198 1500.5,-198 1500.5,-198 1506.5,-198 1512.5,-204 1512.5,-210 1512.5,-210 1512.5,-223 1512.5,-223 1512.5,-229 1506.5,-235 1500.5,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"1399.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">text_embedder(): embedding</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1266,-235C1266,-235 1064,-235 1064,-235 1058,-235 1052,-229 1052,-223 1052,-223 1052,-210 1052,-210 1052,-204 1058,-198 1064,-198 1064,-198 1266,-198 1266,-198 1272,-198 1278,-204 1278,-210 1278,-210 1278,-223 1278,-223 1278,-229 1272,-235 1266,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"1165\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">text_embedder(): embedding</text>\n",
"</g>\n",
"<!-- retriever -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>retriever</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M992,-169C992,-169 759,-169 759,-169 753,-169 747,-163 747,-157 747,-157 747,-144 747,-144 747,-138 753,-132 759,-132 759,-132 992,-132 992,-132 998,-132 1004,-138 1004,-144 1004,-144 1004,-157 1004,-157 1004,-163 998,-169 992,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"875.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">retriever(embedding): documents</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M973.5,-169C973.5,-169 740.5,-169 740.5,-169 734.5,-169 728.5,-163 728.5,-157 728.5,-157 728.5,-144 728.5,-144 728.5,-138 734.5,-132 740.5,-132 740.5,-132 973.5,-132 973.5,-132 979.5,-132 985.5,-138 985.5,-144 985.5,-144 985.5,-157 985.5,-157 985.5,-163 979.5,-169 973.5,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"857\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">retriever(embedding): documents</text>\n",
"</g>\n",
"<!-- text_embedder&#45;&gt;retriever -->\n",
- "<g id=\"edge12\" class=\"edge\">\n",
+ "<g id=\"edge11\" class=\"edge\">\n",
"<title>text_embedder&#45;&gt;retriever</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M1286.19,-199.14C1283.27,-198.75 1280.36,-198.37 1277.5,-198 1190.15,-186.69 1091.94,-175.3 1014.46,-166.63\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"1014.48,-163.11 1004.15,-165.48 1013.7,-170.06 1014.48,-163.11\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M1080.43,-197.93C1040.45,-189.62 992.58,-179.67 951.42,-171.12\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"951.88,-167.64 941.38,-169.03 950.46,-174.5 951.88,-167.64\"/>\n",
"</g>\n",
"<!-- input__text -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>input__text</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1447,-301 1352,-301 1352,-264 1447,-264 1447,-301\"/>\n",
- "<text text-anchor=\"middle\" x=\"1399.5\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: text</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1212.5,-301 1117.5,-301 1117.5,-264 1212.5,-264 1212.5,-301\"/>\n",
+ "<text text-anchor=\"middle\" x=\"1165\" y=\"-278.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: text</text>\n",
"</g>\n",
"<!-- input__text&#45;&gt;text_embedder -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>input__text&#45;&gt;text_embedder</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M1399.5,-263.67C1399.5,-257.99 1399.5,-251.55 1399.5,-245.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"1403,-245.23 1399.5,-235.23 1396,-245.23 1403,-245.23\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M1165,-263.67C1165,-257.99 1165,-251.55 1165,-245.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"1168.5,-245.23 1165,-235.23 1161.5,-245.23 1168.5,-245.23\"/>\n",
"</g>\n",
"<!-- prompt_builder -->\n",
- "<g id=\"node9\" class=\"node\">\n",
+ "<g id=\"node8\" class=\"node\">\n",
"<title>prompt_builder</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M699,-103C699,-103 448,-103 448,-103 442,-103 436,-97 436,-91 436,-91 436,-78 436,-78 436,-72 442,-66 448,-66 448,-66 699,-66 699,-66 705,-66 711,-72 711,-78 711,-78 711,-91 711,-91 711,-97 705,-103 699,-103\"/>\n",
- "<text text-anchor=\"middle\" x=\"573.5\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">prompt_builder(documents): prompt</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M698.5,-103C698.5,-103 447.5,-103 447.5,-103 441.5,-103 435.5,-97 435.5,-91 435.5,-91 435.5,-78 435.5,-78 435.5,-72 441.5,-66 447.5,-66 447.5,-66 698.5,-66 698.5,-66 704.5,-66 710.5,-72 710.5,-78 710.5,-78 710.5,-91 710.5,-91 710.5,-97 704.5,-103 698.5,-103\"/>\n",
+ "<text text-anchor=\"middle\" x=\"573\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">prompt_builder(documents): prompt</text>\n",
"</g>\n",
"<!-- retriever&#45;&gt;prompt_builder -->\n",
- "<g id=\"edge13\" class=\"edge\">\n",
+ "<g id=\"edge12\" class=\"edge\">\n",
"<title>retriever&#45;&gt;prompt_builder</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M792.58,-131.93C753.38,-123.62 706.44,-113.67 666.08,-105.12\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"666.75,-101.68 656.24,-103.03 665.29,-108.53 666.75,-101.68\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M779.02,-131.93C742.39,-123.67 698.57,-113.8 660.78,-105.28\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"661.33,-101.82 650.81,-103.03 659.79,-108.65 661.33,-101.82\"/>\n",
"</g>\n",
- "<!-- input__scale_score -->\n",
+ "<!-- input__return_embedding -->\n",
"<g id=\"node4\" class=\"node\">\n",
+ "<title>input__return_embedding</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"620.5,-235 425.5,-235 425.5,-198 620.5,-198 620.5,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"523\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: return_embedding</text>\n",
+ "</g>\n",
+ "<!-- input__return_embedding&#45;&gt;retriever -->\n",
+ "<g id=\"edge2\" class=\"edge\">\n",
+ "<title>input__return_embedding&#45;&gt;retriever</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M614.71,-197.93C658.34,-189.57 710.64,-179.55 755.46,-170.96\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"756.33,-174.35 765.5,-169.03 755.02,-167.48 756.33,-174.35\"/>\n",
+ "</g>\n",
+ "<!-- input__scale_score -->\n",
+ "<g id=\"node5\" class=\"node\">\n",
"<title>input__scale_score</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"595.5,-235 449.5,-235 449.5,-198 595.5,-198 595.5,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"522.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: scale_score</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"785,-235 639,-235 639,-198 785,-198 785,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"712\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: scale_score</text>\n",
"</g>\n",
"<!-- input__scale_score&#45;&gt;retriever -->\n",
- "<g id=\"edge2\" class=\"edge\">\n",
+ "<g id=\"edge3\" class=\"edge\">\n",
"<title>input__scale_score&#45;&gt;retriever</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M595.79,-199.89C599.07,-199.24 602.32,-198.61 605.5,-198 655.44,-188.44 710.75,-178.75 758.24,-170.72\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"758.97,-174.14 768.25,-169.03 757.81,-167.24 758.97,-174.14\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M752.01,-197.84C769.28,-190.22 789.66,-181.22 807.84,-173.2\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"809.39,-176.34 817.12,-169.1 806.56,-169.94 809.39,-176.34\"/>\n",
"</g>\n",
"<!-- input__filters -->\n",
- "<g id=\"node5\" class=\"node\">\n",
+ "<g id=\"node6\" class=\"node\">\n",
"<title>input__filters</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"721,-235 614,-235 614,-198 721,-198 721,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"667.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: filters</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"910.5,-235 803.5,-235 803.5,-198 910.5,-198 910.5,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"857\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: filters</text>\n",
"</g>\n",
"<!-- input__filters&#45;&gt;retriever -->\n",
- "<g id=\"edge3\" class=\"edge\">\n",
+ "<g id=\"edge4\" class=\"edge\">\n",
"<title>input__filters&#45;&gt;retriever</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M721.07,-199.02C747.77,-190.8 780.32,-180.78 808.65,-172.07\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"809.95,-175.33 818.47,-169.05 807.89,-168.64 809.95,-175.33\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M857,-197.67C857,-191.99 857,-185.55 857,-179.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"860.5,-179.23 857,-169.23 853.5,-179.23 860.5,-179.23\"/>\n",
"</g>\n",
"<!-- input__top_k -->\n",
- "<g id=\"node6\" class=\"node\">\n",
+ "<g id=\"node7\" class=\"node\">\n",
"<title>input__top_k</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"844,-235 739,-235 739,-198 844,-198 844,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"791.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: top_k</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1033.5,-235 928.5,-235 928.5,-198 1033.5,-198 1033.5,-235\"/>\n",
+ "<text text-anchor=\"middle\" x=\"981\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: top_k</text>\n",
"</g>\n",
"<!-- input__top_k&#45;&gt;retriever -->\n",
- "<g id=\"edge4\" class=\"edge\">\n",
- "<title>input__top_k&#45;&gt;retriever</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M814.9,-197.67C824.08,-190.68 834.74,-182.56 844.54,-175.09\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"846.68,-177.86 852.52,-169.01 842.44,-172.29 846.68,-177.86\"/>\n",
- "</g>\n",
- "<!-- input__return_embedding -->\n",
- "<g id=\"node7\" class=\"node\">\n",
- "<title>input__return_embedding</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1057,-235 862,-235 862,-198 1057,-198 1057,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"959.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: return_embedding</text>\n",
- "</g>\n",
- "<!-- input__return_embedding&#45;&gt;retriever -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
- "<title>input__return_embedding&#45;&gt;retriever</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M936.1,-197.67C926.92,-190.68 916.26,-182.56 906.46,-175.09\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"908.56,-172.29 898.48,-169.01 904.32,-177.86 908.56,-172.29\"/>\n",
- "</g>\n",
- "<!-- input__query_embedding -->\n",
- "<g id=\"node8\" class=\"node\">\n",
- "<title>input__query_embedding</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"1268.5,-235 1074.5,-235 1074.5,-198 1268.5,-198 1268.5,-235\"/>\n",
- "<text text-anchor=\"middle\" x=\"1171.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: query_embedding</text>\n",
- "</g>\n",
- "<!-- input__query_embedding&#45;&gt;retriever -->\n",
- "<g id=\"edge6\" class=\"edge\">\n",
- "<title>input__query_embedding&#45;&gt;retriever</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M1090.23,-197.93C1051.89,-189.64 1005.99,-179.71 966.49,-171.17\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"967.11,-167.73 956.59,-169.03 965.63,-174.57 967.11,-167.73\"/>\n",
+ "<title>input__top_k&#45;&gt;retriever</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M946.79,-197.84C932.42,-190.43 915.55,-181.72 900.33,-173.86\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"901.59,-170.58 891.1,-169.1 898.38,-176.8 901.59,-170.58\"/>\n",
"</g>\n",
"<!-- llm -->\n",
- "<g id=\"node13\" class=\"node\">\n",
+ "<g id=\"node12\" class=\"node\">\n",
"<title>llm</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M362,-37C362,-37 273,-37 273,-37 267,-37 261,-31 261,-25 261,-25 261,-12 261,-12 261,-6 267,0 273,0 273,0 362,0 362,0 368,0 374,-6 374,-12 374,-12 374,-25 374,-25 374,-31 368,-37 362,-37\"/>\n",
- "<text text-anchor=\"middle\" x=\"317.5\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">llm(prompt): </text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M362.5,-37C362.5,-37 273.5,-37 273.5,-37 267.5,-37 261.5,-31 261.5,-25 261.5,-25 261.5,-12 261.5,-12 261.5,-6 267.5,0 273.5,0 273.5,0 362.5,0 362.5,0 368.5,0 374.5,-6 374.5,-12 374.5,-12 374.5,-25 374.5,-25 374.5,-31 368.5,-37 362.5,-37\"/>\n",
+ "<text text-anchor=\"middle\" x=\"318\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">llm(prompt): </text>\n",
"</g>\n",
"<!-- prompt_builder&#45;&gt;llm -->\n",
- "<g id=\"edge14\" class=\"edge\">\n",
+ "<g id=\"edge13\" class=\"edge\">\n",
"<title>prompt_builder&#45;&gt;llm</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M503.21,-65.93C466.14,-56.66 420.9,-45.35 384.35,-36.21\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"384.84,-32.73 374.29,-33.7 383.14,-39.52 384.84,-32.73\"/>\n",
- "</g>\n",
- "<!-- input__template -->\n",
- "<g id=\"node10\" class=\"node\">\n",
- "<title>input__template</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"365,-169 236,-169 236,-132 365,-132 365,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"300.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template</text>\n",
- "</g>\n",
- "<!-- input__template&#45;&gt;prompt_builder -->\n",
- "<g id=\"edge7\" class=\"edge\">\n",
- "<title>input__template&#45;&gt;prompt_builder</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M365.37,-133.92C368.12,-133.27 370.84,-132.63 373.5,-132 410.92,-123.16 452.31,-113.52 487.69,-105.32\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"488.54,-108.71 497.49,-103.04 486.96,-101.89 488.54,-108.71\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M502.98,-65.93C466.06,-56.66 420.99,-45.35 384.59,-36.21\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"385.12,-32.74 374.56,-33.7 383.41,-39.53 385.12,-32.74\"/>\n",
"</g>\n",
"<!-- input__template_variables -->\n",
- "<g id=\"node11\" class=\"node\">\n",
+ "<g id=\"node9\" class=\"node\">\n",
"<title>input__template_variables</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"582,-169 383,-169 383,-132 582,-132 582,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"482.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template_variables</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"416.5,-169 217.5,-169 217.5,-132 416.5,-132 416.5,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"317\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template_variables</text>\n",
"</g>\n",
"<!-- input__template_variables&#45;&gt;prompt_builder -->\n",
- "<g id=\"edge8\" class=\"edge\">\n",
+ "<g id=\"edge6\" class=\"edge\">\n",
"<title>input__template_variables&#45;&gt;prompt_builder</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M507.85,-131.67C517.89,-124.61 529.57,-116.39 540.28,-108.86\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"542.44,-111.63 548.6,-103.01 538.41,-105.9 542.44,-111.63\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M387.29,-131.93C420.03,-123.74 459.14,-113.97 493,-105.5\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"494.01,-108.85 502.87,-103.03 492.31,-102.06 494.01,-108.85\"/>\n",
"</g>\n",
"<!-- input__question -->\n",
- "<g id=\"node12\" class=\"node\">\n",
+ "<g id=\"node10\" class=\"node\">\n",
"<title>input__question</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"728.5,-169 600.5,-169 600.5,-132 728.5,-132 728.5,-169\"/>\n",
- "<text text-anchor=\"middle\" x=\"664.5\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: question</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"563,-169 435,-169 435,-132 563,-132 563,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"499\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: question</text>\n",
"</g>\n",
"<!-- input__question&#45;&gt;prompt_builder -->\n",
- "<g id=\"edge9\" class=\"edge\">\n",
+ "<g id=\"edge7\" class=\"edge\">\n",
"<title>input__question&#45;&gt;prompt_builder</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M639.15,-131.67C629.11,-124.61 617.43,-116.39 606.72,-108.86\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"608.59,-105.9 598.4,-103.01 604.56,-111.63 608.59,-105.9\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M519.61,-131.67C527.46,-124.89 536.53,-117.04 544.95,-109.76\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"547.48,-112.2 552.75,-103.01 542.9,-106.91 547.48,-112.2\"/>\n",
"</g>\n",
- "<!-- input__generation_kwargs -->\n",
- "<g id=\"node14\" class=\"node\">\n",
- "<title>input__generation_kwargs</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"199,-103 0,-103 0,-66 199,-66 199,-103\"/>\n",
- "<text text-anchor=\"middle\" x=\"99.5\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: generation_kwargs</text>\n",
+ "<!-- input__template -->\n",
+ "<g id=\"node11\" class=\"node\">\n",
+ "<title>input__template</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"710.5,-169 581.5,-169 581.5,-132 710.5,-132 710.5,-169\"/>\n",
+ "<text text-anchor=\"middle\" x=\"646\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: template</text>\n",
"</g>\n",
- "<!-- input__generation_kwargs&#45;&gt;llm -->\n",
- "<g id=\"edge10\" class=\"edge\">\n",
- "<title>input__generation_kwargs&#45;&gt;llm</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M159.36,-65.93C187.78,-57.58 221.85,-47.58 251.07,-39\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"252.17,-42.33 260.78,-36.15 250.2,-35.61 252.17,-42.33\"/>\n",
+ "<!-- input__template&#45;&gt;prompt_builder -->\n",
+ "<g id=\"edge8\" class=\"edge\">\n",
+ "<title>input__template&#45;&gt;prompt_builder</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M625.67,-131.67C617.93,-124.89 608.98,-117.04 600.67,-109.76\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"602.8,-106.97 592.97,-103.01 598.19,-112.23 602.8,-106.97\"/>\n",
"</g>\n",
"<!-- input__streaming_callback -->\n",
- "<g id=\"node15\" class=\"node\">\n",
+ "<g id=\"node13\" class=\"node\">\n",
"<title>input__streaming_callback</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"417.5,-103 217.5,-103 217.5,-66 417.5,-66 417.5,-103\"/>\n",
- "<text text-anchor=\"middle\" x=\"317.5\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: streaming_callback</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"200,-103 0,-103 0,-66 200,-66 200,-103\"/>\n",
+ "<text text-anchor=\"middle\" x=\"100\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: streaming_callback</text>\n",
"</g>\n",
"<!-- input__streaming_callback&#45;&gt;llm -->\n",
- "<g id=\"edge11\" class=\"edge\">\n",
+ "<g id=\"edge9\" class=\"edge\">\n",
"<title>input__streaming_callback&#45;&gt;llm</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M317.5,-65.67C317.5,-59.99 317.5,-53.55 317.5,-47.33\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"321,-47.23 317.5,-37.23 314,-47.23 321,-47.23\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M159.86,-65.93C188.28,-57.58 222.35,-47.58 251.57,-39\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"252.67,-42.33 261.28,-36.15 250.7,-35.61 252.67,-42.33\"/>\n",
+ "</g>\n",
+ "<!-- input__generation_kwargs -->\n",
+ "<g id=\"node14\" class=\"node\">\n",
+ "<title>input__generation_kwargs</title>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"417.5,-103 218.5,-103 218.5,-66 417.5,-66 417.5,-103\"/>\n",
+ "<text text-anchor=\"middle\" x=\"318\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: generation_kwargs</text>\n",
+ "</g>\n",
+ "<!-- input__generation_kwargs&#45;&gt;llm -->\n",
+ "<g id=\"edge10\" class=\"edge\">\n",
+ "<title>input__generation_kwargs&#45;&gt;llm</title>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M318,-65.67C318,-59.99 318,-53.55 318,-47.33\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"321.5,-47.23 318,-37.23 314.5,-47.23 321.5,-47.23\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
- "<graphviz.graphs.Digraph at 0x7f923dadb810>"
+ "<graphviz.graphs.Digraph at 0x7f4937a72dd0>"
]
},
- "execution_count": 7,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
diff --git a/tests/integrations/test_burr_haystack.py b/tests/integrations/test_burr_haystack.py
new file mode 100644
index 00000000..3ddb124b
--- /dev/null
+++ b/tests/integrations/test_burr_haystack.py
@@ -0,0 +1,253 @@
+from haystack import Pipeline, component
+from haystack.components.embedders import SentenceTransformersTextEmbedder
+from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
+from haystack.document_stores.in_memory import InMemoryDocumentStore
+
+from burr.core import State, action
+from burr.core.graph import GraphBuilder
+from burr.integrations.haystack import HaystackAction, haystack_pipeline_to_burr_graph
+
+
+@component
+class MockComponent:
+ def __init__(self, required_init: str, optional_init: str = "default"):
+ self.required_init = required_init
+ self.optional_init = optional_init
+
+ @component.output_types(output_1=str, output_2=str)
+ def run(self, required_input: str, optional_input: str = "default") -> dict:
+ return {
+ "output_1": required_input,
+ "output_2": optional_input,
+ }
+
+
+@action(reads=["query_embedding"], writes=["documents"])
+def retrieve_documents(state: State) -> State:
+ query_embedding = state["query_embedding"]
+
+ document_store = InMemoryDocumentStore()
+ retriever = InMemoryEmbeddingRetriever(document_store)
+
+ results = retriever.run(query_embedding=query_embedding)
+ return state.update(documents=results["documents"])
+
+
+haystack_retrieve_documents = HaystackAction(
+ component=InMemoryEmbeddingRetriever(InMemoryDocumentStore()),
+ name="retrieve_documents",
+ reads=["query_embedding"],
+ writes=["documents"],
+)
+
+
+def test_input_socket_mapping():
+ # {input_socket_name: state_field}
+ reads = {"required_input": "foo"}
+
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"), name="mock", reads=reads, writes=[]
+ )
+
+ assert haction.reads == list(set(reads.values())) == ["foo"]
+
+
+def test_input_socket_sequence():
+ # {input_socket_name: input_socket_name}
+ reads = ["required_input"]
+
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"), name="mock", reads=reads, writes=[]
+ )
+
+ assert haction.reads == list(reads) == ["required_input"]
+
+
+def test_output_socket_mapping():
+ # {state_field: output_socket_name}
+ writes = {"bar": "output_1"}
+
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"), name="mock", reads=[], writes=writes
+ )
+
+ assert haction.writes == list(writes.keys()) == ["bar"]
+
+
+def test_output_socket_sequence():
+ # {output_socket_name: output_socket_name}
+ writes = ["output_1"]
+
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"), name="mock", reads=[], writes=writes
+ )
+
+ assert haction.writes == writes == ["output_1"]
+
+
+def test_get_component_source():
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"), name="mock", reads=[], writes=[]
+ )
+
+ expected_source = """\
+@component
+class MockComponent:
+ def __init__(self, required_init: str, optional_init: str = "default"):
+ self.required_init = required_init
+ self.optional_init = optional_init
+
+ @component.output_types(output_1=str, output_2=str)
+ def run(self, required_input: str, optional_input: str = "default") -> dict:
+ return {
+ "output_1": required_input,
+ "output_2": optional_input,
+ }
+"""
+
+ assert haction.get_source() == expected_source
+
+
+def test_run_with_external_inputs():
+ state = State(initial_values={})
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"), name="mock", reads=[], writes=[]
+ )
+
+ results = haction.run(state=state, required_input="as_input")
+
+ assert results == {"output_1": "as_input", "output_2": "default"}
+
+
+def test_run_with_state_inputs():
+ state = State(initial_values={"foo": "bar"})
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"),
+ name="mock",
+ reads={"required_input": "foo"},
+ writes=[],
+ )
+
+ results = haction.run(state=state)
+
+ assert results == {"output_1": "bar", "output_2": "default"}
+
+
+def test_run_with_bound_params():
+ state = State(initial_values={})
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"),
+ name="mock",
+ reads=[],
+ writes=[],
+ bound_params={"required_input": "baz"},
+ )
+
+ results = haction.run(state=state)
+
+ assert results == {"output_1": "baz", "output_2": "default"}
+
+
+def test_run_mixed_params():
+ state = State(initial_values={"foo": "bar"})
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"),
+ name="mock",
+ reads={"required_input": "foo"},
+ writes=[],
+ bound_params={"optional_input": "baz"},
+ )
+
+ results = haction.run(state=state)
+
+ assert results == {"output_1": "bar", "output_2": "baz"}
+
+
+def test_run_with_sequence():
+ state = State(initial_values={"required_input": "bar"})
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"),
+ name="mock",
+ reads=["required_input"],
+ writes=[],
+ )
+
+ results = haction.run(state=state)
+
+ assert results == {"output_1": "bar", "output_2": "default"}
+
+
+def test_update_with_writes_mapping():
+ state = State(initial_values={})
+ results = {"output_1": 1, "output_2": 2}
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"),
+ name="mock",
+ reads=[],
+ writes={"foo": "output_1"},
+ )
+
+ new_state = haction.update(result=results, state=state)
+
+ assert new_state["foo"] == 1
+
+
+def test_update_with_writes_sequence():
+ state = State(initial_values={})
+ results = {"output_1": 1, "output_2": 2}
+ haction = HaystackAction(
+ component=MockComponent(required_init="init"),
+ name="mock",
+ reads=[],
+ writes=["output_1"],
+ )
+
+ new_state = haction.update(result=results, state=state)
+
+ assert new_state["output_1"] == 1
+
+
+def test_pipeline_converter():
+ # create haystack Pipeline
+ retriever = InMemoryEmbeddingRetriever(InMemoryDocumentStore())
+ text_embedder = SentenceTransformersTextEmbedder(model="sentence-transformers/all-MiniLM-L6-v2")
+
+ basic_rag_pipeline = Pipeline()
+ basic_rag_pipeline.add_component("text_embedder", text_embedder)
+ basic_rag_pipeline.add_component("retriever", retriever)
+ basic_rag_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")
+
+ # create Burr application
+ embed_text = HaystackAction(
+ component=text_embedder,
+ name="text_embedder",
+ reads=[],
+ writes={"query_embedding": "embedding"},
+ )
+
+ retrieve_documents = HaystackAction(
+ component=retriever,
+ name="retriever",
+ reads=["query_embedding"],
+ writes=["documents"],
+ )
+
+ burr_graph = (
+ GraphBuilder()
+ .with_actions(embed_text, retrieve_documents)
+ .with_transitions(("text_embedder", "retriever"))
+ .build()
+ )
+
+ # convert the Haystack Pipeline to a Burr graph
+ haystack_graph = haystack_pipeline_to_burr_graph(basic_rag_pipeline)
+
+ converted_action_names = [action.name for action in haystack_graph.actions]
+ for graph_action in burr_graph.actions:
+ assert graph_action.name in converted_action_names
+
+ for burr_t in burr_graph.transitions:
+ assert any(
+ burr_t.from_.name == haystack_t.from_.name and burr_t.to.name == haystack_t.to.name
+ for haystack_t in haystack_graph.transitions
+ )