dify icon indicating copy to clipboard operation
dify copied to clipboard

Add a file to Knowledge and display : "1 validation error for KnowledgeConfig......"

Open fyxkszz opened this issue 9 months ago • 7 comments

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.1.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I created a new Knowledge and uploaded some excle files. These files were processed successfully. There was an error when adding files later.

Knowledge Using Hybrid Search Method

Image Here is my operation process

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

✔️ Expected Behavior

❌ Actual Behavior

Image

fyxkszz avatar Mar 21 '25 02:03 fyxkszz

Hey @fyxkszz! 👋 I'm here to help you with bug fixes, answer questions, and assist you while waiting for a human maintainer. Let's squash those bugs together!

To resolve the Pydantic validation error indicating a missing required field weight_type in the KnowledgeConfig model, you need to ensure that the weights field in the RetrievalModel is properly initialized with a WeightModel that includes the weight_type attribute. Here's an example of how you can define the KnowledgeConfig with the required weight_type:

from pydantic import BaseModel
from typing import Literal, Optional

class WeightModel(BaseModel):
    weight_type: str
    vector_setting: Optional[WeightVectorSetting] = None
    keyword_setting: Optional[WeightKeywordSetting] = None

class RetrievalModel(BaseModel):
    search_method: Literal["hybrid_search", "semantic_search", "full_text_search"]
    reranking_enable: bool
    reranking_model: Optional[RerankingModel] = None
    reranking_mode: Optional[str] = None
    top_k: int
    score_threshold_enabled: bool
    score_threshold: Optional[float] = None
    weights: Optional[WeightModel] = None

class KnowledgeConfig(BaseModel):
    original_document_id: Optional[str] = None
    duplicate: bool = True
    indexing_technique: Literal["high_quality", "economy"]
    data_source: Optional[DataSource] = None
    process_rule: Optional[ProcessRule] = None
    retrieval_model: Optional[RetrievalModel] = None
    doc_form: str = "text_model"
    doc_language: str = "English"
    embedding_model: Optional[str] = None
    embedding_model_provider: Optional[str] = None
    name: Optional[str] = None

# Example initialization
knowledge_config = KnowledgeConfig(
    retrieval_model=RetrievalModel(
        search_method="semantic_search",
        reranking_enable=True,
        top_k=10,
        score_threshold_enabled=False,
        weights=WeightModel(
            weight_type="your_weight_type_here"
        )
    )
)

Make sure to replace "your_weight_type_here" with the appropriate value for weight_type [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Mar 21 '25 02:03 dosubot[bot]

I also encountered this problem,too

powertoredstar avatar Mar 21 '25 06:03 powertoredstar

Any way to resolve this before upgrade?

ensleep avatar Mar 21 '25 07:03 ensleep

Similar operations, similar problems

Image

icyflower avatar Mar 21 '25 08:03 icyflower

Image

jqsl2012 avatar Mar 21 '25 08:03 jqsl2012

any update on this, same with version 1.1.2

indradevelop avatar Mar 21 '25 15:03 indradevelop

Same problem on cloud hosted version.

Image

polischool avatar Mar 21 '25 16:03 polischool

Same problems with cloud hosted ver.

minamikik avatar Mar 22 '25 04:03 minamikik

We are actively working on resolving this issue. Thank you so much for your patience and understanding.

WTW0313 avatar Mar 22 '25 05:03 WTW0313

I also encountered this problem (V1.1.2) and would like to know how to solve it specifically??

Byzeal avatar Mar 23 '25 05:03 Byzeal

+1

woaiso avatar Mar 24 '25 02:03 woaiso

A new version will be released soon to address this issue, so you won't have to wait for too long. Thank you all for your patience and understanding.

WTW0313 avatar Mar 24 '25 02:03 WTW0313

@WTW0313 the version 1.1.3 did't solve this problem,when you "save and process" a document and the database use rerank model,the weight_type is null,the backend service report "1 validation error for KnowledgeConfig\nretrieval_model.weights.weight_type\n Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]"

SeesawLiu avatar Mar 24 '25 14:03 SeesawLiu

@WTW0313 the version 1.1.3 did't solve this problem,when you "save and process" a document and the database use rerank model,the weight_type is null,the backend service report "1 validation error for KnowledgeConfig\nretrieval_model.weights.weight_type\n Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]"

I can't reproduce this issue in version 1.1.3. Could you please provide the steps to reproduce the issue? If possible, screenshots or videos would be incredibly helpful.

WTW0313 avatar Mar 24 '25 14:03 WTW0313

Add a file to old Knowledge, sometimes

Image

icyflower avatar Mar 24 '25 16:03 icyflower

like @icyflower said,the old knowledage database config did't have the parameter,when i try save config again to overwrite it,some success and some fail.some kdb update to "customized",and some update to null.

Image

SeesawLiu avatar Mar 25 '25 00:03 SeesawLiu

When using dify version 1.1.3, newly created knowledge bases can upload files normally, but historically created knowledge bases still report an error:

1 validation error for KnowledgeConfig retrieval_model.weights.weight_type 
Input should be a valid string [type=string_type, input_value=None, input_type=NoneType] 
For further information visit https://errors.pydantic.dev/2.9/v/string_type

1609676823 avatar Mar 25 '25 00:03 1609676823

I'm currently using version 1.1.2 and encountering the same issue. It only works correctly when adding all the required files to the knowledge base the first time. If I try to add more files later, it throws an error—the same one you're experiencing. It seems version 1.1.3 hasn't fixed this issue either!

owenouy avatar Mar 25 '25 03:03 owenouy

I'm currently using version 1.1.2 and encountering the same issue. It only works correctly when adding all the required files to the knowledge base the first time. If I try to add more files later, it throws an error—the same one you're experiencing. It seems version 1.1.3 hasn't fixed this issue either!

Sorry about that. Currently, to avoid this error in old datasets, you can create a new dataset and upload the files again. We are working on a better solution for this issue, which will be compatible with old data.

WTW0313 avatar Mar 25 '25 04:03 WTW0313

I'm currently using version 1.1.2 and encountering the same issue. It only works correctly when adding all the required files to the knowledge base the first time. If I try to add more files later, it throws an error—the same one you're experiencing. It seems version 1.1.3 hasn't fixed this issue either!

Sorry about that. Currently, to avoid this error in old datasets, you can create a new dataset and upload the files again. We are working on a better solution for this issue, which will be compatible with old data.

So, is the current workaround to create a new knowledge base with the additional documents, and then select both knowledge bases for searching?

owenouy avatar Mar 25 '25 06:03 owenouy

You can give it a try. If the retrieval works well, it could certainly be a more efficient solution compared to simply duplicating all files into a new dataset.

WTW0313 avatar Mar 25 '25 06:03 WTW0313

Also having this issue after an upgrade to v1.1.3

abbottdev avatar Mar 25 '25 09:03 abbottdev