Hi,
i tryed text2cypher-demo-4bit-gguf-unsloth.Q4_K_M.gguf (aka. text2cypher_gguf locally) using ollama, as following:
llm = ChatOpenAI(model="text2cypher_gguf:latest",
base_url="http://localhost:11434/v1",
api_key="NA", temperature=0)
from langchain.chains.graph_qa.cypher import GraphCypherQAChain
graph = Neo4jGraph(url=os.environ["NEO4J_URI"], username=os.environ["NEO4J_USERNAME"], password=os.environ["NEO4J_PASSWORD"])
chain = GraphCypherQAChain.from_llm(
llm, graph=graph, verbose=True
)
chain.invoke({"query": "what materials are in the project? when creating the cypher write only the cypher command without any additions that might cause error during execution" })
i get the following errors:
Generated Cypher:
MATCH (p:IfcProject)<-[:HasContext]-(:IfcGeometricRepresentationContext)<-[:HasContext]-(:IfcMaterial)
RETURN DISTINCT p.name AS projectName, m.name AS materialName
ORDER BY projectName, materialName
LIMIT 10
<|im_end|>
and then, when GraphCypherQAChain trys to execute the cypher, it complains that the cypher is illegal (because of <|im_end|> suffix). i suggest to remove it from the generated cypher. see full error below:
CypherSyntaxError Traceback (most recent call last)
File /usr/local/anaconda3/lib/python3.11/site-packages/langchain_community/graphs/neo4j_graph.py:419, in Neo4jGraph.query(self, query, params)
418 try:
--> 419 data = session.run(Query(text=query, timeout=self.timeout), params)
420 json_data = [r.data() for r in data]
File /usr/local/anaconda3/lib/python3.11/site-packages/neo4j/_sync/work/session.py:314, in Session.run(self, query, parameters, **kwargs)
313 parameters = dict(parameters or {}, **kwargs)
--> 314 self._auto_result._run(
315 query, parameters, self._config.database,
316 self._config.impersonated_user, self._config.default_access_mode,
317 bookmarks, self._config.notifications_min_severity,
318 self._config.notifications_disabled_classifications,
319 )
321 return self._auto_result
File /usr/local/anaconda3/lib/python3.11/site-packages/neo4j/_sync/work/result.py:221, in Result._run(self, query, parameters, db, imp_user, access_mode, bookmarks, notifications_min_severity, notifications_disabled_classifications)
220 self._connection.send_all()
--> 221 self._attach()
File /usr/local/anaconda3/lib/python3.11/site-packages/neo4j/_sync/work/result.py:409, in Result._attach(self)
408 while self._attached is False:
--> 409 self._connection.fetch_message()
File /usr/local/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:178, in ConnectionErrorHandler.getattr..outer..inner(*args, **kwargs)
177 try:
--> 178 func(*args, **kwargs)
179 except (Neo4jError, ServiceUnavailable, SessionExpired) as exc:
File /usr/local/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_bolt.py:855, in Bolt.fetch_message(self)
852 tag, fields = self.inbox.pop(
853 hydration_hooks=self.responses[0].hydration_hooks
854 )
--> 855 res = self._process_message(tag, fields)
856 self.idle_since = monotonic()
File /usr/local/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_bolt5.py:370, in Bolt5x0._process_message(self, tag, fields)
369 try:
--> 370 response.on_failure(summary_metadata or {})
371 except (ServiceUnavailable, DatabaseUnavailable):
File /usr/local/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:245, in Response.on_failure(self, metadata)
244 Util.callback(handler)
--> 245 raise Neo4jError.hydrate(**metadata)
CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input '|': expected "+" or "-" (line 5, column 2 (offset: 210))
"<|im_end|>"
^}
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
Cell In[33], line 1
----> 1 chain.invoke({"query": "what materials are in the project? when creating the cypher write only the cypher command without any additions that might cause error during execution" })
File /usr/local/anaconda3/lib/python3.11/site-packages/langchain/chains/base.py:166, in Chain.invoke(self, input, config, **kwargs)
164 except BaseException as e:
165 run_manager.on_chain_error(e)
--> 166 raise e
167 run_manager.on_chain_end(outputs)
169 if include_run_info:
File /usr/local/anaconda3/lib/python3.11/site-packages/langchain/chains/base.py:156, in Chain.invoke(self, input, config, **kwargs)
153 try:
154 self._validate_inputs(inputs)
155 outputs = (
--> 156 self._call(inputs, run_manager=run_manager)
157 if new_arg_supported
158 else self._call(inputs)
159 )
161 final_outputs: Dict[str, Any] = self.prep_outputs(
162 inputs, outputs, return_only_outputs
163 )
164 except BaseException as e:
File /usr/local/anaconda3/lib/python3.11/site-packages/langchain_community/chains/graph_qa/cypher.py:338, in GraphCypherQAChain._call(self, inputs, run_manager)
335 # Retrieve and limit the number of results
336 # Generated Cypher be null if query corrector identifies invalid schema
337 if generated_cypher:
--> 338 context = self.graph.query(generated_cypher)[: self.top_k]
339 else:
340 context = []
File /usr/local/anaconda3/lib/python3.11/site-packages/langchain_community/graphs/neo4j_graph.py:425, in Neo4jGraph.query(self, query, params)
423 return json_data
424 except CypherSyntaxError as e:
--> 425 raise ValueError(f"Generated Cypher Statement is not valid\n{e}")
ValueError: Generated Cypher Statement is not valid
{code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input '|': expected "+" or "-" (line 5, column 2 (offset: 210))
"<|im_end|>"
^}