🐛(document) fix collection context manager

Fix the URL build and the context manager (needs a test)
This commit is contained in:
Quentin BEY
2025-10-06 17:34:59 +02:00
parent 1cdccd3d24
commit f2deeedbc4
2 changed files with 11 additions and 11 deletions
@@ -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,
)
@@ -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()