@@ -77,10 +77,38 @@ def extract_product_info(product: cocoindex.Json, filename: str) -> ProductInfo:
7777 )
7878
7979
80+ neo4j_conn_spec = cocoindex .add_auth_entry (
81+ "Neo4jConnection" ,
82+ cocoindex .storages .Neo4jConnection (
83+ uri = "bolt://localhost:7687" ,
84+ user = "neo4j" ,
85+ password = "cocoindex" ,
86+ ),
87+ )
88+ kuzu_conn_spec = cocoindex .add_auth_entry (
89+ "KuzuConnection" ,
90+ cocoindex .storages .KuzuConnection (
91+ api_server_url = "http://localhost:8123" ,
92+ ),
93+ )
94+
95+ # Use Neo4j as the graph database
96+ GraphDbSpec = cocoindex .storages .Neo4j
97+ GraphDbConnection = cocoindex .storages .Neo4jConnection
98+ GraphDbDeclaration = cocoindex .storages .Neo4jDeclaration
99+ conn_spec = neo4j_conn_spec
100+
101+ # Use Kuzu as the graph database
102+ # GraphDbSpec = cocoindex.storages.Kuzu
103+ # GraphDbConnection = cocoindex.storages.KuzuConnection
104+ # GraphDbDeclaration = cocoindex.storages.KuzuDeclaration
105+ # conn_spec = kuzu_conn_spec
106+
107+
80108@cocoindex .flow_def (name = "StoreProduct" )
81109def store_product_flow (
82110 flow_builder : cocoindex .FlowBuilder , data_scope : cocoindex .DataScope
83- ):
111+ ) -> None :
84112 """
85113 Define an example flow that extracts triples from files and build knowledge graph.
86114 """
@@ -122,25 +150,16 @@ def store_product_flow(
122150 taxonomy = t ["name" ],
123151 )
124152
125- conn_spec = cocoindex .add_auth_entry (
126- "Neo4jConnection" ,
127- cocoindex .storages .Neo4jConnection (
128- uri = "bolt://localhost:7687" ,
129- user = "neo4j" ,
130- password = "cocoindex" ,
131- ),
132- )
133-
134153 product_node .export (
135154 "product_node" ,
136- cocoindex . storages . Neo4j (
155+ GraphDbSpec (
137156 connection = conn_spec , mapping = cocoindex .storages .Nodes (label = "Product" )
138157 ),
139158 primary_key_fields = ["id" ],
140159 )
141160
142161 flow_builder .declare (
143- cocoindex . storages . Neo4jDeclaration (
162+ GraphDbDeclaration (
144163 connection = conn_spec ,
145164 nodes_label = "Taxonomy" ,
146165 primary_key_fields = ["value" ],
@@ -149,7 +168,7 @@ def store_product_flow(
149168
150169 product_taxonomy .export (
151170 "product_taxonomy" ,
152- cocoindex . storages . Neo4j (
171+ GraphDbSpec (
153172 connection = conn_spec ,
154173 mapping = cocoindex .storages .Relationships (
155174 rel_type = "PRODUCT_TAXONOMY" ,
@@ -175,7 +194,7 @@ def store_product_flow(
175194 )
176195 product_complementary_taxonomy .export (
177196 "product_complementary_taxonomy" ,
178- cocoindex . storages . Neo4j (
197+ GraphDbSpec (
179198 connection = conn_spec ,
180199 mapping = cocoindex .storages .Relationships (
181200 rel_type = "PRODUCT_COMPLEMENTARY_TAXONOMY" ,
0 commit comments