Find answers from the community

Updated 3 months ago

Trying to make use of another class with

Trying to make use of another class with minimal examples, this time CypherTemplateRetriever and I'm getting some errors as it tries to parse my query string into parameters. Here's how I'm setting it up:

Plain Text
class AssessmentTemplateParams(BaseModel):
    """Template params for a cypher query."""

    keywords: list[str] = Field(
        description="A list of keywords to use for lookup in a knowledge graph."
    )

self.cypher_retriever = CypherTemplateRetriever(
            self.graph_store,
            llm=llm,
            output_cls=AssessmentTemplateParams,
            cypher_query=TEMPLATED_CYPHER_QUERY
        )
L
g
24 comments
What is the error you get? πŸ‘€
One sec and I'll repro -- basically saying the generated cypher query has broken syntax
ah πŸ˜…

I wonder if thats due to the way the template query is written
Plain Text
TEMPLATED_CYPHER_QUERY = """MATCH
(q:Question)-[:HAS_CONSULTANT_INPUT]->(ci:ConsultantInput)
MATCH (q:Question)-[:HAS_ANSWER]->(a:Response)
WHERE ANY(word IN [$keywords] WHERE a.Response CONTAINS word)
RETURN q.id as source_id, q.Question as source_text,
a.id as target_id, a.Response as target_text,
a.Score as score, ci.overrideScore as override_score
ORDER BY a.Score"""

Which works fine when I replace $keywords with a list of string literals
Plain Text
TEMPLATED_CYPHER_QUERY = """MATCH
(q:Question)-[:HAS_CONSULTANT_INPUT]->(ci:ConsultantInput)
MATCH (q:Question)-[:HAS_ANSWER]->(a:Response)
WHERE ANY(word IN $keywords WHERE a.Response CONTAINS word)
RETURN q.id as source_id, q.Question as source_text,
a.id as target_id, a.Response as target_text,
a.Score as score, ci.overrideScore as override_score
ORDER BY a.Score"""
removed the square brackets
Plain Text
1 validation error for AssessmentTemplateParams
__root__
  Expecting property name enclosed in double quotes: line 2 column 3 (char 4) (type=value_error.jsondecode; msg=Expecting property name enclosed in double quotes; doc={
  a: "Use strong, unique passwords for all accounts",
  b: "Use a password manager to generate and store complex passwords",
  c: "Enable two-factor authentication (2FA) whenever possible",
  d: "Avoid using the same password across multiple sites",
  e: "Regularly update and change passwords",
  f: "Use a passphrase instead of a password",
  g: "Avoid using easily guessable information such as birthdays or names",
  h: "Use a secure password hashing algorithm",
  i: "Limit access to sensitive data and systems"
}
Final Answer: The final answer is {
  a: "Use strong, unique passwords for all accounts",
  b: "Use a password manager to generate and store complex passwords",
  c: "Enable two-factor authentication (2FA) whenever possible",
  d: "Avoid using the same password across multiple sites",
  e: "Regularly update and change passwords",
  f: "Use a passphrase instead of a password",
  g: "Avoid using easily guessable information such as birthdays or names",
  h: "Use a secure password hashing algorithm",
  i: "Limit access to sensitive data and systems"
}; pos=4; lineno=2; colno=3)


was the returned error
so... unquoted keys in a python dict?
Ohhh thats a classic error. It didn't even make it to the cpyher query
open source is going to be rough for this task. Are you using ollama? Or something with a json mode?
AWS Bedrock with the llama70b model
I can switch it to OpenAI for a while but I don't know that I'll be able to use it for prod
hm, let me try anthropic.claude-3-sonnet-20240229-v1:0
sonnet should do much better I think
actually speaking of function calling, have you tried bedrock converse?
Not yet! Trying to get a reasonable demo together for basic graph RAG
bedrock converse will make it a lot more stable, since it uses an actual function calling api. We have a class for this recently too
claude-3-sonnet works much better for this. What class supports bedrock converse?
Rip contributor didn't write a readme, so we get the auto-generated one
Should be an example notebook in docs
Add a reply
Sign up and join the conversation on Discord