🐛(document) fix collection context manager
Fix the URL build and the context manager (needs a test)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user