Skip to content

Commit 4aaf156

Browse files
committed
feat: adding optional id into text insert
1 parent 3286a0d commit 4aaf156

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lightrag/api/routers/document_routes.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class InsertTextRequest(BaseModel):
3333
min_length=1,
3434
description="The text to insert",
3535
)
36+
id: Optional[str] = Field(
37+
default=None,
38+
description="The id of the text",
39+
)
3640

3741
@field_validator("text", mode="after")
3842
@classmethod
@@ -45,6 +49,10 @@ class InsertTextsRequest(BaseModel):
4549
min_length=1,
4650
description="The texts to insert",
4751
)
52+
ids: Optional[list[str]] = Field(
53+
default=None,
54+
description="The ids of the texts",
55+
)
4856

4957
@field_validator("texts", mode="after")
5058
@classmethod
@@ -355,7 +363,7 @@ async def pipeline_index_files(rag: LightRAG, file_paths: List[Path]):
355363
logger.error(traceback.format_exc())
356364

357365

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):
359367
"""Index a list of texts
360368
361369
Args:
@@ -364,7 +372,7 @@ async def pipeline_index_texts(rag: LightRAG, texts: List[str]):
364372
"""
365373
if not texts:
366374
return
367-
await rag.apipeline_enqueue_documents(texts)
375+
await rag.apipeline_enqueue_documents(texts, ids)
368376
await rag.apipeline_process_enqueue_documents()
369377

370378

@@ -496,7 +504,7 @@ async def insert_text(
496504
HTTPException: If an error occurs during text processing (500).
497505
"""
498506
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])
500508
return InsertResponse(
501509
status="success",
502510
message="Text successfully received. Processing will continue in background.",
@@ -531,7 +539,7 @@ async def insert_texts(
531539
HTTPException: If an error occurs during text processing (500).
532540
"""
533541
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)
535543
return InsertResponse(
536544
status="success",
537545
message="Text successfully received. Processing will continue in background.",

lightrag_webui/src/lib/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ButtonVariantType } from '@/components/ui/Button'
22

3-
export const backendBaseUrl = ''
3+
export const backendBaseUrl = 'http://localhost:9621'
44

55
export const controlButtonVariant: ButtonVariantType = 'ghost'
66

0 commit comments

Comments
 (0)