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