langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
50.04k stars 7.15k forks source link

The input variable in the http node in the workflow does not have the result of the knowledge_retrieval node #7077

Closed youqugit closed 2 months ago

youqugit commented 2 months ago

Self Checks

Dify version

0.6.14

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

The input variable in the http node in the workflow does not have the result of the knowledge_retrieval node. image

✔️ Expected Behavior

There should be this option knowledge retrieval result Array[Object] image

❌ Actual Behavior

No response

dosubot[bot] commented 2 months ago

@youqugit Hello there! I'm a bot designed to help you solve bugs, answer questions, and become a contributor. I'm here to assist you while you wait for a human maintainer.

To ensure that the HTTP node correctly receives the result from the knowledge_retrieval node in your Dify version 0.6.14 self-hosted workflow, you need to configure the output variable result from the knowledge_retrieval node and pass it to the HTTP node. Here is how you can do it:

  1. Configure the Knowledge Retrieval Node:

    • Ensure that the knowledge_retrieval node is set up to retrieve relevant text segments from the knowledge base using the query variable (e.g., sys.query).
    • The output variable result will contain the retrieved text segments.
  2. Pass the Output to the HTTP Node:

    • Configure the HTTP node to receive the result from the knowledge_retrieval node. This involves setting up the HTTP node to accept the result as part of its input.

Here is an example configuration:

nodes:
  - id: knowledge_retrieval
    type: knowledge_retrieval
    config:
      query_variable: sys.query
      knowledge_base: your_knowledge_base_id
      recall_mode: your_recall_mode
      settings: your_settings
    output:
      result: knowledge_retrieval_result

  - id: http_node
    type: http
    config:
      url: your_http_endpoint
      method: POST
      headers:
        Content-Type: application/json
      body:
        result: ${knowledge_retrieval_result}

In this configuration:

Additionally, ensure that the knowledge_retrieval node is correctly implemented to handle the retrieval process and return the results. The KnowledgeRetrievalNode class in Dify handles the retrieval process and returns the results in the result variable. Here is a snippet of the relevant part of the implementation:

class KnowledgeRetrievalNode(BaseNode):
    _node_data_cls = KnowledgeRetrievalNodeData
    node_type = NodeType.KNOWLEDGE_RETRIEVAL

    def _run(self, variable_pool: VariablePool) -> NodeRunResult:
        node_data: KnowledgeRetrievalNodeData = cast(self._node_data_cls, self.node_data)

        # extract variables
        query = variable_pool.get_variable_value(variable_selector=node_data.query_variable_selector)
        variables = {
            'query': query
        }
        if not query:
            return NodeRunResult(
                status=WorkflowNodeExecutionStatus.FAILED,
                inputs=variables,
                error="Query is required."
            )
        # retrieve knowledge
        try:
            results = self._fetch_dataset_retriever(
                node_data=node_data, query=query
            )
            outputs = {
                'result': results
            }
            return NodeRunResult(
                status=WorkflowNodeExecutionStatus.SUCCEEDED,
                inputs=variables,
                process_data=None,
                outputs=outputs
            )

        except Exception as e:
            return NodeRunResult(
                status=WorkflowNodeExecutionStatus.FAILED,
                inputs=variables,
                error=str(e)
            )

By following these steps and ensuring the correct implementation of the KnowledgeRetrievalNode, you can ensure that the HTTP node correctly receives the result from the knowledge_retrieval node [1][2][3].

To continue talking to Dosu, mention @dosu.

crazywoola commented 2 months ago

Because the output of the Knowledge retrieval is not plain text, it return results in array, so you could use a code node or jinja node to extract things as you want, then they are able to be referenced node.