Open hoangpnhat opened 5 days ago
To resolve the pydantic.v1.error_wrappers.ValidationError: 1 validation error for LLMPredictStartEvent
error when using TextToCypherRetriever
with an existing Neo4j graph, you need to ensure that the data being passed to the TextToCypherRetriever
is correctly validated according to the expected schema. This error typically occurs when the data does not conform to the expected structure defined by Pydantic models.
Here is an example of how to correctly set up and use the TextToCypherRetriever
:
from llama_index.core.indices.property_graph import TextToCypherRetriever
from llama_index.core.llms import LLM
from llama_index.core.prompts import PromptTemplate
from llama_index.core.settings import Settings
DEFAULT_RESPONSE_TEMPLATE = (
"Generated Cypher query:\n{query}\n\n" "Cypher Response:\n{response}"
)
DEFAULT_ALLOWED_FIELDS = ["text", "label", "type"]
cypher_retriever = TextToCypherRetriever(
graph_store=index.property_graph_store,
llm=llm, # customize the LLM, defaults to Settings.llm
text_to_cypher_template=PromptTemplate(index.property_graph_store.text_to_cypher_template),
response_template=DEFAULT_RESPONSE_TEMPLATE,
cypher_validator=None, # an optional callable that can clean/verify generated cypher
allowed_output_fields=DEFAULT_ALLOWED_FIELDS,
)
Ensure that the llm
and other parameters are correctly defined and that the data being passed matches the expected schema. If the error persists, you may need to inspect the specific validation error message to identify which field is causing the issue and adjust your data accordingly. Additionally, make sure that the graph_store
supports structured queries, as the TextToCypherRetriever
requires this capability [1][2].
To continue talking to Dosu, mention @dosu.
@hoangpnhat seems like DEFAULT_TEXT_TO_CYPHER_TEMPLATE
is not a PromptTemplate
object. How did you define it? Or if you print it, what is it?
Bug Description
I'm using an existing neo4j graph and trying to run TextToCypherRetriever When I run a query, the retriever returns error File "llama_index/core/indices/property_graph/sub_retrievers/text_to_cypher.py", line 131, in aretrieve_from_graph response = await self.llm.apredict( ^^^^^^^^^^^^^^^^^^^^^^^^ File "llama_index/core/instrumentation/dispatcher.py", line 255, in async_wrapper result = await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "llama_index/core/llms/llm.py", line 517, in apredict LLMPredictStartEvent(template=prompt, template_args=prompt_args) File "pydantic/v1/main.py", line 341, in init raise validation_error pydantic.v1.error_wrappers.ValidationError: 1 validation error for LLMPredictStartEvent template value is not a valid dict (type=type_error.dict)
Version
0.10.46
Steps to Reproduce
Relevant Logs/Tracbacks