From f2deeedbc44d8ea8003c588343af624f15f54fbc Mon Sep 17 00:00:00 2001 From: Quentin BEY Date: Mon, 6 Oct 2025 17:18:49 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(document)=20fix=20collection=20con?= =?UTF-8?q?text=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the URL build and the context manager (needs a test) --- .../albert_rag_backend.py | 2 +- .../document_rag_backends/base_rag_backend.py | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backend/chat/agent_rag/document_rag_backends/albert_rag_backend.py b/src/backend/chat/agent_rag/document_rag_backends/albert_rag_backend.py index dd382a8..d90c27d 100644 --- a/src/backend/chat/agent_rag/document_rag_backends/albert_rag_backend.py +++ b/src/backend/chat/agent_rag/document_rag_backends/albert_rag_backend.py @@ -70,7 +70,7 @@ class AlbertRagBackend(BaseRagBackend): # pylint: disable=too-many-instance-att Delete the current collection """ response = requests.delete( - urljoin(self._collections_endpoint, self.collection_id), + urljoin(f"{self._collections_endpoint}/", self.collection_id), headers=self._headers, timeout=settings.ALBERT_API_TIMEOUT, ) diff --git a/src/backend/chat/agent_rag/document_rag_backends/base_rag_backend.py b/src/backend/chat/agent_rag/document_rag_backends/base_rag_backend.py index 9bdf424..0a0a1da 100644 --- a/src/backend/chat/agent_rag/document_rag_backends/base_rag_backend.py +++ b/src/backend/chat/agent_rag/document_rag_backends/base_rag_backend.py @@ -81,14 +81,14 @@ class BaseRagBackend: """ raise NotImplementedError("Must be implemented in subclass.") + @classmethod + @contextmanager + def temporary_collection(cls, name: str, description: Optional[str] = None): + """Context manager for RAG backend with temporary collections.""" + backend = cls() -@contextmanager -def tmp_rag_backend(rag_backend_class, name): - """Context manager for RAG backend with temporary collections.""" - backend = rag_backend_class() - - backend.create_collection(name=name) - try: - yield backend - finally: - backend.delete_collection() + backend.create_collection(name=name, description=description) + try: + yield backend + finally: + backend.delete_collection()