Closed Johnbathappully closed 3 months ago
To resolve the ValidationError
when using TextToCypherRetriever
, ensure that the cypher_validator
callable function is correctly implemented and passed during the initialization of TextToCypherRetriever
. The cypher_validator
is used to validate the generated Cypher query. If it is not correctly implemented or if it raises an error, it could lead to a ValidationError
.
Here is an example of how to initialize TextToCypherRetriever
with a cypher_validator
:
def my_cypher_validator(cypher_query: str) -> str:
# Implement your validation logic here
if "UNSAFE_KEYWORD" in cypher_query:
raise ValueError("Unsafe keyword found in Cypher query")
return cypher_query
graph_store = PropertyGraphStore() # Initialize your graph store
llm = LLM() # Initialize your language model
retriever = TextToCypherRetriever(
graph_store=graph_store,
llm=llm,
cypher_validator=my_cypher_validator
)
Ensure that your cypher_validator
function is correctly validating the Cypher query and does not raise unnecessary errors [1].
Additionally, there is a potential issue in the TextToCypherRetriever
implementation that could cause a ValidationError
. Specifically, the _parse_generated_cyher
method is called to validate the generated Cypher query if a cypher_validator
is provided. If the cypher_validator
raises a ValidationError
, it could cause the entire process to fail [1].
Lastly, ensure that the text_to_cypher_template
parameter is correctly structured. It should be either a PromptTemplate
object or a string. If a string is provided, it will be converted into a PromptTemplate
object. The text_to_cypher_template
should include schema
and question
template arguments to generate the appropriate Cypher query based on the graph schema and the user's question [1][2].
If you are still encountering issues, there might be compatibility problems between the versions of llama-index
and other related packages. For example, gpt-index 0.4.6
requires tenacity<8.2.0
, but having tenacity 8.2.2
installed is incompatible. Using a fresh environment to avoid such issues is recommended [3][4].
To continue talking to Dosu, mention @dosu.
Pretty hard to debug if you don't give a full traceback
ValidationError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/llama_index/core/async_utils.py in asyncio_run(coro) 32 # If we're here, there's an existing loop but it's not running ---> 33 return loop.run_until_complete(coro) 34
37 frames ValidationError: 1 validation error for LLMPredictStartEvent template value is not a valid dict (type=type_error.dict)
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/llama_index/core/async_utils.py in asyncio_run(coro) 45 except Exception as e: 46 # Catch any other exceptions and re-raise with more context ---> 47 raise type(e)(f"Error running coroutine: {e!s}") from e 48 49
TypeError: ValidationError.init() missing 1 required positional argument: 'model'
this is code im using
import nest_asyncio nest_asyncio.apply()
from llama_index.core.indices.property_graph import TextToCypherRetriever
DEFAULT_RESPONSE_TEMPLATE = ( "Generated Cypher query:\n{query}\n\n" "Cypher Response:\n{response}" ) DEFAULT_ALLOWED_FIELDS = ["text", "label", "type"]
DEFAULT_TEXT_TO_CYPHER_TEMPLATE = ( index.property_graph_store.text_to_cypher_template, )
cypher_retriever = TextToCypherRetriever( graph_store,
llm=llm,
# customize the text-to-cypher template.
# Requires `schema` and `question` template args
text_to_cypher_template=DEFAULT_TEXT_TO_CYPHER_TEMPLATE,
# customize how the cypher result is inserted into
# a text node. Requires `query` and `response` template args
response_template=DEFAULT_RESPONSE_TEMPLATE,
# an optional callable that can clean/verify generated cypher
cypher_validator=None,
# allowed fields in the resulting
allowed_output_field=DEFAULT_ALLOWED_FIELDS,
)
from llama_index.core import PropertyGraphIndex
index = PropertyGraphIndex.from_existing( property_graph_store=graph_store )
retriever = index.as_retriever(sub_retrievers=[cypher_retriever])
query_engine = index.as_query_engine( sub_retrievers=[retriever] )
response = query_engine.query("Insurbridge Connects to")
print(response)
please note it works when i comment out text_to_cypher_template / response_template / cypher_validator / allowed_output_field
It seems like the template is not the proper type, you are declaring it as a tuple. It should be a string or prompt template object
DEFAULT_TEXT_TO_CYPHER_TEMPLATE = index.property_graph_store.text_to_cypher_template
Bug Description
r: ValidationError.init() missing 1 required positional argument: 'model'
Version
llama-cloud 0.0.9 llama-index 0.10.55 llama-index-agent-openai 0.2.8 llama-index-cli 0.1.12 llama-index-core 0.10.55 llama-index-embeddings-openai 0.1.10 llama-index-graph-stores-neo4j 0.2.7 llama-index-indices-managed-llama-cloud 0.2.5 llama-index-legacy 0.9.48 llama-index-llms-openai 0.1.25 llama-index-multi-modal-llms-openai 0.1.7 llama-index-program-openai 0.1.6 llama-index-question-gen-openai 0.1.3 llama-index-readers-file 0.1.30 llama-index-readers-llama-parse 0.1.6 llama-parse 0.4.7
Steps to Reproduce
not working TextToCypherRetriever
import nest_asyncio nest_asyncio.apply()
from llama_index.core.indices.property_graph import TextToCypherRetriever
DEFAULT_RESPONSE_TEMPLATE = ( "Generated Cypher query:\n{query}\n\n" "Cypher Response:\n{response}" ) DEFAULT_ALLOWED_FIELDS = ["text", "label", "type"]
DEFAULT_TEXT_TO_CYPHER_TEMPLATE = ( index.property_graph_store.text_to_cypher_template, )
cypher_retriever = TextToCypherRetriever( graph_store,
customize the LLM, defaults to Settings.llm
)
from llama_index.core import PropertyGraphIndex
Load the existing property graph index
index = PropertyGraphIndex.from_existing( property_graph_store=graph_store )
Create the retriever using the synonym retriever
retriever = index.as_retriever(sub_retrievers=[cypher_retriever])
Create the query engine using the retriever
query_engine = index.as_query_engine( sub_retrievers=[retriever] )
Perform a query using the query engine
response = query_engine.query("Insurbridge Connects to")
Print the response
print(response)
Relevant Logs/Tracbacks