Skip to content

Commit

Permalink
feat: add list_namespaces method to document index
Browse files Browse the repository at this point in the history
Task: IL-174
  • Loading branch information
Valentina Galata committed Jan 25, 2024
1 parent 754b911 commit f82cca7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/intelligence_layer/connectors/document_index/document_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 response.json()

def create_collection(self, collection_path: CollectionPath) -> None:
"""Creates a collection at the path.
Expand Down
7 changes: 7 additions & 0 deletions tests/connectors/document_index/test_document_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f82cca7

Please sign in to comment.