|
9 | 9 | @dataclasses.dataclass |
10 | 10 | class Relationship: |
11 | 11 | """Describe a relationship between two nodes.""" |
12 | | - source: str |
13 | | - relationship_name: str |
14 | | - target: str |
| 12 | + subject: str |
| 13 | + predicate: str |
| 14 | + object: str |
15 | 15 |
|
16 | 16 | @dataclasses.dataclass |
17 | 17 | class Relationships: |
@@ -52,23 +52,29 @@ def docs_to_kg_flow(flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.D |
52 | 52 | instruction=( |
53 | 53 | "Please extract relationships from CocoIndex documents. " |
54 | 54 | "Focus on concepts and ingnore specific examples. " |
55 | | - "Each relationship should be a tuple of (source, relationship, target)."))) |
| 55 | + "Each relationship should be a tuple of (subject, predicate, object)."))) |
56 | 56 |
|
57 | 57 | with chunk["relationships"]["relationships"].row() as relationship: |
58 | 58 | relationships.collect( |
59 | 59 | id=cocoindex.GeneratedField.UUID, |
60 | | - source=relationship["source"], |
61 | | - relationship_name=relationship["relationship_name"], |
62 | | - target=relationship["target"], |
| 60 | + subject=relationship["subject"], |
| 61 | + predicate=relationship["predicate"], |
| 62 | + object=relationship["object"], |
63 | 63 | ) |
64 | 64 |
|
65 | 65 | relationships.export( |
66 | 66 | "relationships", |
67 | 67 | cocoindex.storages.Neo4jRelationship( |
68 | 68 | connection=conn_spec, |
69 | | - relationship="RELATIONSHIP", |
70 | | - source=cocoindex.storages.Neo4jRelationshipEndSpec(field_name="source", label="Entity"), |
71 | | - target=cocoindex.storages.Neo4jRelationshipEndSpec(field_name="target", label="Entity"), |
| 69 | + rel_type="RELATIONSHIP", |
| 70 | + source=cocoindex.storages.Neo4jRelationshipEndSpec( |
| 71 | + label="Entity", |
| 72 | + fields=[cocoindex.storages.Neo4jFieldMapping(field_name="subject", node_field_name="value")] |
| 73 | + ), |
| 74 | + target=cocoindex.storages.Neo4jRelationshipEndSpec( |
| 75 | + label="Entity", |
| 76 | + fields=[cocoindex.storages.Neo4jFieldMapping(field_name="object", node_field_name="value")] |
| 77 | + ), |
72 | 78 | nodes={ |
73 | 79 | "Entity": cocoindex.storages.Neo4jRelationshipNodeSpec(key_field_name="value"), |
74 | 80 | }, |
|
0 commit comments