run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
35.57k stars 5.02k forks source link

[Bug]: Should modify the datatype of a parameter to string in llama-index-packs-self-rag #16158

Open aerfafeng opened 2 hours ago

aerfafeng commented 2 hours ago

Bug Description

I was running self-RAG by llama-index-packs-self-rag. when I directly use the code it will report

pydantic_core._pydantic_core.ValidationError: 1 validation error for TextNode
id_
  Input should be a valid string [type=string_type, input_value=0, input_type=int]

This is because the code in line 229 in base.py of the package:

node=TextNode(text=paragraph, id_=p_idx),

id_ accepts string but p_idx is a number. It should be modified like this:

node=TextNode(text=paragraph, id_=str(p_idx)),

Version

0.11.11

Steps to Reproduce

The error will be raised when using code like this. It is the simplest way to call this module:

engine = SelfRAGQueryEngine(
    model_path=os.getenv('SELF_RAG_MODEL_DIR'),
    retriever=VectorIndexRetriever(index=index, similarity_top_k=6),
    verbose=True
 )

response = engine.query(question)

Relevant Logs/Tracbacks

No response

dosubot[bot] commented 2 hours ago

@aerfafeng Hello! I'm here to help you with any bugs, questions, or contributions. Let's work together to tackle this issue.

Yes, the datatype of the id_ parameter should be modified to a string in the llama-index-packs-self-rag package to fix the validation error in TextNode. Specifically, you should change the assignment in base.py from:

node=TextNode(text=paragraph, id_=p_idx),

to:

node=TextNode(text=paragraph, id_=str(p_idx)),

This change ensures that id_ is a string, which is required by the TextNode class [1][2].

To continue talking to Dosu, mention @dosu.

logan-markewich commented 47 minutes ago

Feel free to submit a PR!