[Python] How can i set a primary key that is inside a struct, cypher/neo4j

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    im trying to get a json file into kuzu but am facing some issues.

    This is what im trying:

    import kuzu

    def put_into_kuzu():
    db = kuzu.Database("rag.kuzu")
    conn = kuzu.Connection(db)
    cex = conn.execute
    cex("LOAD json;")
    cex("CREATE NODE TABLE Chunks(embedding_dim INT, data STRUCT(__id__ STRING, __created_at__ INT, content STRING, full_doc_id STRING, file_path STRING), PRIMARY KEY (__id__));")
    cex('COPY Chunks FROM "./rag_storage/vdb_chunks.json"')
    response = conn.execute(
    """
    RETURN Chunks;
    """
    )
    for row in response:
    print(row)

    if __name__ == "__main__":
    put_into_kuzu()


    json file structure:

    {
    "embedding_dim": 4096,
    "data": [
    {
    "__id__": "chunk-ed1b1b28b5cf4df59ca4bf1031e4cc27",
    "__created_at__": 1753946350,
    "content": "content of the text document",
    "full_doc_id": "doc-ed1b1b28b5cf4df59ca4bf1031e4cc27",
    "file_path": "test.txt"
    },
    {
    a lot more of this
    },
    ],
    "matrix" : "bunch of random characters, but they are unneeded"
    }


    As can be seen from the code i want __id__ as my primary key, but cant achieve it. I even tried data.__id__ but that didnt work either.

    Any help is appreciated!

    Continue reading...

Compartilhe esta Página