Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions smart-kiosk-assistant/rag-service/api/custom_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async def ingest_context_file(request: Request) -> BatchIngestResponse:
(e.g. ``file`` or ``files``) so the endpoint is resilient to client changes.
"""
form = await request.form()
uploads = [value for value in form.values() if isinstance(value, StarletteUploadFile)]
uploads = [value for key, value in form.multi_items() if isinstance(value, StarletteUploadFile)]
if not uploads:
raise HTTPException(
status_code=422,
Expand All @@ -199,8 +199,14 @@ def context_stats():

@router.delete("/api/v1/context")
def clear_context():
get_shared_pipeline().clear_context()
return JSONResponse(content={"status": "cleared"}, status_code=200)
try:
get_shared_pipeline().clear_context()
return JSONResponse(content={"status": "cleared"}, status_code=200)
except Exception as exc:
return JSONResponse(
content={"status": "failed", "detail": str(exc)},
status_code=500
)


@router.post("/api/v1/query")
Expand Down
19 changes: 10 additions & 9 deletions smart-kiosk-assistant/rag-service/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,17 @@ def ingest_text(self, text: str, source: str = "api", metadata: dict | None = No
return self._ingestion.ingest_text(text, source=source, metadata=metadata)

def clear_context(self) -> None:
client = getattr(self.vectorstore, "_client", None)
if client is None:
raise RuntimeError("Vector store client is not available")
collection = getattr(self.vectorstore, "_collection", None)
if collection is None:
logger.info("No collection to clear")
return
try:
client.delete_collection(self.collection_name)
except Exception: # noqa: BLE001
logger.info(
"Collection %s did not exist yet during clear_context", self.collection_name,
)
self.vectorstore = self._build_vectorstore()
all_ids = collection.get(include=[])
if all_ids["ids"]:
collection.delete(ids=all_ids["ids"])
logger.info("Deleted %d documents from collection", len(all_ids["ids"]))
except Exception as exc: # noqa: BLE001
raise RuntimeError(f"Failed to clear context: {exc}") from exc

def get_stats(self) -> dict:
collection = getattr(self.vectorstore, "_collection", None)
Expand Down