langflow
langflow copied to clipboard
What is the input value for vector store search when running as json flow?
Summary
Overall question: How do I know what is a valid input key and valid output component for my flows when exporting them to json to run?
I have a simple flow, with an OpenAIEmbeddings component hooked up to an AstraDBSearch. I have no other values set in my flow when I export it to json.
The given python code is:
from langflow.load import run_flow_from_json
TWEAKS = {
"OpenAIEmbeddings-sSuTz": {},
"AstraDBSearch-avH6c": {}
}
result = run_flow_from_json(flow="Untitled document (24).json",
input_value="message",
tweaks=TWEAKS)
Once I add in my API keys / endpoint, I still have an empty input value
. That makes sense to me, as I imagine I can do:
result = run_flow_from_json(flow="Untitled document (24).json",
input_value="message", # I would hope that this `input_value` is used as the `input_value` to `AstraDBSearch`.
tweaks=TWEAKS)
However, it fails to build, saying:
ValueError: Error running graph: Error building vertex Astra DB Search: AstraDBSearchComponent.build() missing 1 required positional argument: 'input_value'
Now, just for the sake of the argument, I added it directly to the tweaks instead:
"AstraDBSearch-avH6c": {
...
"input_value": "<my search query>",
},
result = run_flow_from_json(flow=flow, input_value="<does it matter what goes here now>", tweaks=TWEAKS)
Now, I get the error:
AttributeError: 'RunOutputs' object has no attribute 'output'
So questions for that are:
- What purpose does the
input_value
inrun_flow_from_json
serve in this context? - What is the output error - is it telling me that the vector search component is not a valid output component?
** Version **
- latest dev branch
- python 3.11.2
To Reproduce create flow, export to json, try run as json
Thanks!
Additional context
The input_value
in the run_flow_from_json
function is meant to be the initial input for the flow, which gets processed by the components in your setup. For your case, this means the input_value
would be the text input for the OpenAIEmbeddings
component, which then generates embeddings to be used by the AstraDBSearch
component for searching within Astra DB.
Regarding the AttributeError: 'RunOutputs' object has no attribute 'output'
error, it seems there's an attempt to access a non-existent output
attribute on the RunOutputs
object. Instead, you should access the outputs
attribute, which is a list containing the results. Here's how you can iterate over the outputs to access the results:
for result_data in result.outputs:
if result_data is not None:
print(result_data.results)
Ensure that the output_component
parameter in your run_flow_from_json
call matches the ID of the component you expect to produce the output, such as your AstraDBSearch
component. This setup is crucial for correctly retrieving the output from your flow.
result = run_flow_from_json(
flow='my_flow.json',
input_value='my_input',
output_component='AstraDBSearch-avH6c', # Ensure this matches your component's ID
tweaks=TWEAKS,
)
Make sure your component IDs and the way you access the output data align with your flow's configuration and the RunOutputs
object structure.
Details
Sources
- src/backend/base/langflow/processing/load.py
- src/backend/base/langflow/graph/schema.py
- src/backend/base/langflow/components/vectorsearch/AstraDBSearch.py
- src/backend/base/langflow/components/embeddings/OpenAIEmbeddings.py
- src/backend/langflow/components/embeddings/OpenAIEmbeddings.py
- src/backend/base/langflow/processing/process.py
- tests/test_process.py
About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
I see -- that's my mistake. The outputs
issue was on my end.
However, I did have to add the output_component
parameter in order to receive the correct outputs. Leaving it out still built and ran, but the output was empty:
[RunOutputs(inputs={'input_value': '<does this matter?>'}, outputs=[])]
Adding the output_component
like:
result = run_flow_from_json(
flow=flow,
input_value="<does this matter?>",
output_component="AstraDBSearch-avH6c",
tweaks=TWEAKS,
)
correctly produced outputs
.
@dosu thanks, the issue relating to the output
was my mistake.
However, I am still curious about how I can run the flow by using the input_value
from the run_flow_from_json
function as the input to the my AstraDBSearch
component.
To use the input_value
from the run_flow_from_json
function as the input for your AstraDBSearch
component, it's important to understand that this value is intended to be the initial input for the entire flow. This means it should be the text input for the OpenAIEmbeddings
component, which then processes this input to generate embeddings. These embeddings are subsequently used by the AstraDBSearch
component for searching within Astra DB.
The input_value
parameter in the run_flow_from_json
function is directly passed to the initial component of your flow, which in your setup is likely the OpenAIEmbeddings
component. The flow then automatically manages the passage of data between components, so the output from OpenAIEmbeddings
becomes the input for AstraDBSearch
.
If you're encountering issues with the input_value
not being recognized or used correctly by the AstraDBSearch
component, ensure that your flow is correctly set up to pass the output of OpenAIEmbeddings
as the input to AstraDBSearch
. This typically involves configuring the flow in such a way that the data output from one component is correctly mapped as the input to the next.
Regarding the tweaks and adjustments you've attempted by directly modifying the TWEAKS
dictionary, it's crucial to remember that these tweaks should not be used to pass fundamental input values between components. Instead, the TWEAKS
dictionary is intended for runtime modifications or adjustments to the flow's execution, such as changing component parameters or settings dynamically.
For your specific case, ensure that:
- The
input_value
you provide when callingrun_flow_from_json
is the text you want to process withOpenAIEmbeddings
. - Your flow is correctly configured so that the output from
OpenAIEmbeddings
is automatically used as the input forAstraDBSearch
. - Any tweaks you apply via the
TWEAKS
dictionary are appropriate adjustments to component settings, rather than attempts to manually pass data between components.
This approach should allow you to run your flow as intended, with the input_value
provided at the start being correctly utilized by both the OpenAIEmbeddings
and AstraDBSearch
components according to the flow's configuration.
Details
Sources
- src/backend/base/langflow/components/vectorsearch/AstraDBSearch.py
- src/backend/base/langflow/processing/load.py
- src/backend/base/langflow/schema/graph.py
About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
Hi @jordanrfrazier
Do you still need any support with this issue?
Hi @carlosrcoelho, I haven't tried running json as a flow in a while, so unsure. We can probably close this and I'll open a new one if I run into issues in the newer versions.