[Python] Neo4j: how to pass parameters to relationships?

Discussão em 'Python' iniciado por Stack, Julho 3, 2025.

  1. Stack

    Stack Membro Participativo

    The official website of neo4j point out that we can not pass parameters to the type of relationships. However, I need to pass parameters to relationships when adding embeddings in batch.

    Neo4j adds batch vectors for nodes by

    driver.execute_query('''
    UNWIND $movies as movie
    MATCH (m:Movie {title: movie.title, plot: movie.plot})
    CALL db.create.setNodeVectorProperty(m, 'embedding', movie.embedding)
    ''', movies=nodes_with_embeddings, database_=DB_NAME)


    add embedding property for nodes

    This code use $movies to pass parameters and pass movie.title as property value. Each movie is a dict. However, I can not pass relationship types with $datas like MATCH (h:Entity {id: data.id})-[r: data.r]->(t:Entity {id: data.id})

    I've tried to use common concatenation for strings to pass parameters, and add embedding property one by one. For example, "MATCH (h:Entity {id: data.h_id})-[r:"+data['r']+"]->(t:Entity {id: data.t_id}) However, I want to use batch operation to speed up.

    Is there a way to pass parameters to the relationships for batch operation? Thanks for your time.

    Continue reading...

Compartilhe esta Página