From 9232508c252770f67d128735c5daba5b3b777a93 Mon Sep 17 00:00:00 2001 From: Valentina Galata Date: Thu, 25 Jan 2024 15:47:28 +0100 Subject: [PATCH] feat: add list_namespaces method to document index Task: IL-174 --- .../connectors/document_index/document_index.py | 12 ++++++++++++ .../connectors/document_index/test_document_index.py | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/intelligence_layer/connectors/document_index/document_index.py b/src/intelligence_layer/connectors/document_index/document_index.py index a044eaddf..196679ef8 100644 --- a/src/intelligence_layer/connectors/document_index/document_index.py +++ b/src/intelligence_layer/connectors/document_index/document_index.py @@ -288,6 +288,18 @@ def _raise_for_status(self, response: requests.Response) -> None: ) raise exception_factory(response.text, HTTPStatus(response.status_code)) + def list_namespaces(self) -> Sequence[str]: + """Lists all available namespaces. + + Returns: + List of all available namespaces. + """ + + url = f"{self._base_document_index_url}/namespaces" + response = requests.get(url, headers=self.headers) + self._raise_for_status(response) + return [str(namespace) for namespace in response.json()] + def create_collection(self, collection_path: CollectionPath) -> None: """Creates a collection at the path. diff --git a/tests/connectors/document_index/test_document_index.py b/tests/connectors/document_index/test_document_index.py index 4d0a0d09b..7ac837421 100644 --- a/tests/connectors/document_index/test_document_index.py +++ b/tests/connectors/document_index/test_document_index.py @@ -48,6 +48,13 @@ def document_contents() -> DocumentContents: return DocumentContents(contents=[text], metadata={"Some": "Metadata"}) +@pytest.mark.internal +def test_document_index_lists_namespaces(document_index: DocumentIndexClient) -> None: + namespaces = document_index.list_namespaces() + + assert "aleph-alpha" in namespaces + + @pytest.mark.internal def test_document_index_creates_collection( document_index: DocumentIndexClient, collection_path: CollectionPath