Neo4jQueryParametersMarshaller
DocumentQueryParametersMarshaller ¤
Bases: QueryParametersMarshaller
A marshaller which converts haystack.Document
to a dictionary when it is used as query parameter in Cypher query
Haystack's native to_dict
method is called to produce a flattened dictionary of Document data along with its meta
fields.
Source code in src/neo4j_haystack/serialization/query_parameters_marshaller.py
DataclassQueryParametersMarshaller ¤
Bases: QueryParametersMarshaller
A marshaller which converts a dataclass
to a dictionary when encountered as Cypher query parameter.
Source code in src/neo4j_haystack/serialization/query_parameters_marshaller.py
Neo4jQueryParametersMarshaller ¤
Bases: QueryParametersMarshaller
The marshaller converts Cypher query parameters to types which can be consumed in Neo4j query execution. In some
cases query parameters contain complex data types (e.g. dataclasses) which can be converted to dict
types and
thus become eligible for running a Cypher query:
Example: Running a query with a dataclass parameter
The above example would fail without marshaller. With marshaller from dataclasses import dataclass
from neo4j_haystack.client import Neo4jClient, Neo4jClientConfig
from neo4j_haystack.serialization import Neo4jQueryParametersMarshaller
@dataclass
class YearInfo:
year: int = 2024
neo4j_config = Neo4jClientConfig("bolt://localhost:7687", database="neo4j", username="neo4j", password="passw0rd")
neo4j_client = Neo4jClient(client_config=neo4j_config)
marshaller = Neo4jQueryParametersMarshaller()
query_params = marshaller.marshall({"year_info": YearInfo()})
neo4j_client.execute_read(
"MATCH (doc:`Document`) WHERE doc.year=$year_info.year RETURN doc",
parameters=query_params
)
query_params
will become
{"year_info": {"year": 2024}}
which is eligible input for Neo4j Driver.