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
48.07k stars 6.86k forks source link

1 validation error for DocumentContext score Input should be a valid number [type=float_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/float_type #9351

Closed sanjin1985 closed 5 hours ago

sanjin1985 commented 5 hours ago

Self Checks

Dify version

Version 0.9.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

dify_bug

✔️ Expected Behavior

how to resolve the problem?

❌ Actual Behavior

No response

dosubot[bot] commented 5 hours ago

Hello @sanjin1985! I'm here to help you with any bugs, questions, or contributions you have for Dify. I'm Dosu, a bot that's ready to assist you while you wait for a human maintainer.

To resolve the validation error in Pydantic where the "DocumentContext score" input should be a valid float but received a NoneType, ensure that the score field is allowed to be None by using the Optional type. The code should define score as Optional[float], which means it can be either a float or None. Here's an example of how it should be defined:

from typing import Optional
from pydantic import BaseModel

class DocumentContext(BaseModel):
    content: str
    score: Optional[float] = None

Make sure that when you create an instance of DocumentContext, you are either providing a valid float for score or leaving it as None. Check the data being passed to ensure it aligns with these expectations. In the context of the Dify platform, verify that the score is being correctly set in the DocumentContext instances. For example, in the DatasetRetrieval class, ensure that the score is retrieved from item.metadata.get("score") and is correctly populated with a float or None before creating the DocumentContext instance [1][2].

To continue talking to Dosu, mention @dosu.

crazywoola commented 5 hours ago

Duplicated