@@ -125,6 +125,8 @@ async def read(self, read_config: Dict):
125125 async def chunk (self , chunk_config : Dict , input_stream : Iterator ):
126126 """
127127 chunk documents into smaller pieces from full_docs_storage if not already present
128+ input_stream: document IDs from full_docs_storage
129+ yield: chunk IDs inserted into chunks_storage
128130 """
129131 count = 0
130132 for doc_id in input_stream :
@@ -174,15 +176,22 @@ async def chunk(self, chunk_config: Dict, input_stream: Iterator):
174176 async def build_kg (self , inputs : List ):
175177 """
176178 build knowledge graph from text chunks
179+ inputs: chunk IDs from chunks_storage
180+ return: None
177181 """
182+ count = 0
178183 # Step 1: get chunks
184+ inserting_chunks : Dict [str , Dict ] = {}
185+ for _chunk_id in inputs :
186+ chunk = await self .chunks_storage .get_by_id (_chunk_id )
187+ if chunk :
188+ inserting_chunks [_chunk_id ] = chunk
189+
190+ count += len (inserting_chunks )
191+ logger .info (
192+ "[Build KG] Inserting %d chunks, total %d" , len (inserting_chunks ), count
193+ )
179194
180- inserting_chunks = await self .meta_storage .get_new_data (self .chunks_storage )
181- if len (inserting_chunks ) == 0 :
182- logger .warning ("All chunks are already in the storage" )
183- return
184-
185- logger .info ("[New Chunks] inserting %d chunks" , len (inserting_chunks ))
186195 # Step 2: build knowledge graph from new chunks
187196 _add_entities_and_relations = await build_kg (
188197 llm_client = self .synthesizer_llm_client ,
@@ -194,12 +203,8 @@ async def build_kg(self, inputs: List):
194203 logger .warning ("No entities or relations extracted from text chunks" )
195204 return
196205
197- # Step 3: mark meta
206+ # Step 3: store the new entities and relations
198207 await self .graph_storage .index_done_callback ()
199- await self .meta_storage .mark_done (self .chunks_storage )
200- await self .meta_storage .index_done_callback ()
201-
202- return _add_entities_and_relations
203208
204209 @op ("search" , deps = ["read" ], op_type = OpType .STREAMING )
205210 @async_to_sync_method
@@ -231,7 +236,7 @@ async def search(self, search_config: Dict, input_stream: Iterator):
231236
232237 @op ("quiz_and_judge" , deps = ["build_kg" ], op_type = OpType .BARRIER )
233238 @async_to_sync_method
234- async def quiz_and_judge (self , quiz_and_judge_config : Dict , inputs : None ):
239+ async def quiz_and_judge (self , quiz_and_judge_config : Dict ):
235240 logger .warning (
236241 "Quiz and Judge operation needs trainee LLM client."
237242 " Make sure to provide one."
@@ -270,7 +275,7 @@ async def quiz_and_judge(self, quiz_and_judge_config: Dict, inputs: None):
270275
271276 @op ("partition" , deps = ["build_kg" ], op_type = OpType .BARRIER )
272277 @async_to_sync_method
273- async def partition (self , partition_config : Dict , inputs : None ):
278+ async def partition (self , partition_config : Dict ):
274279 batches = await partition_kg (
275280 self .graph_storage ,
276281 self .chunks_storage ,
@@ -283,8 +288,11 @@ async def partition(self, partition_config: Dict, inputs: None):
283288 @op ("extract" , deps = ["chunk" ], op_type = OpType .STREAMING )
284289 @async_to_sync_method
285290 async def extract (self , extract_config : Dict , input_stream : Iterator ):
286- logger .info ("Extracting information from given chunks..." )
287-
291+ """
292+ Extract information from chunks in chunks_storage
293+ input_stream: chunk IDs from chunks_storage
294+ return: None
295+ """
288296 results = await extract_info (
289297 self .synthesizer_llm_client ,
290298 self .chunks_storage ,
0 commit comments