@@ -33,6 +33,10 @@ class InsertTextRequest(BaseModel):
33
33
min_length = 1 ,
34
34
description = "The text to insert" ,
35
35
)
36
+ id : Optional [str ] = Field (
37
+ default = None ,
38
+ description = "The id of the text" ,
39
+ )
36
40
37
41
@field_validator ("text" , mode = "after" )
38
42
@classmethod
@@ -45,6 +49,10 @@ class InsertTextsRequest(BaseModel):
45
49
min_length = 1 ,
46
50
description = "The texts to insert" ,
47
51
)
52
+ ids : Optional [list [str ]] = Field (
53
+ default = None ,
54
+ description = "The ids of the texts" ,
55
+ )
48
56
49
57
@field_validator ("texts" , mode = "after" )
50
58
@classmethod
@@ -355,7 +363,7 @@ async def pipeline_index_files(rag: LightRAG, file_paths: List[Path]):
355
363
logger .error (traceback .format_exc ())
356
364
357
365
358
- async def pipeline_index_texts (rag : LightRAG , texts : List [str ]):
366
+ async def pipeline_index_texts (rag : LightRAG , texts : List [str ], ids : Optional [ List [ str ]] = None ):
359
367
"""Index a list of texts
360
368
361
369
Args:
@@ -364,7 +372,7 @@ async def pipeline_index_texts(rag: LightRAG, texts: List[str]):
364
372
"""
365
373
if not texts :
366
374
return
367
- await rag .apipeline_enqueue_documents (texts )
375
+ await rag .apipeline_enqueue_documents (texts , ids )
368
376
await rag .apipeline_process_enqueue_documents ()
369
377
370
378
@@ -496,7 +504,7 @@ async def insert_text(
496
504
HTTPException: If an error occurs during text processing (500).
497
505
"""
498
506
try :
499
- background_tasks .add_task (pipeline_index_texts , rag , [request .text ])
507
+ background_tasks .add_task (pipeline_index_texts , rag , [request .text ], [ request . id ] )
500
508
return InsertResponse (
501
509
status = "success" ,
502
510
message = "Text successfully received. Processing will continue in background." ,
@@ -531,7 +539,7 @@ async def insert_texts(
531
539
HTTPException: If an error occurs during text processing (500).
532
540
"""
533
541
try :
534
- background_tasks .add_task (pipeline_index_texts , rag , request .texts )
542
+ background_tasks .add_task (pipeline_index_texts , rag , request .texts , request . ids )
535
543
return InsertResponse (
536
544
status = "success" ,
537
545
message = "Text successfully received. Processing will continue in background." ,
0 commit comments