Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose get indexes #36

Merged
merged 4 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

An open-source tensor search engine that seamlessly integrates with your applications, websites, and workflow.

Marqo cloud ☁️ is currently in beta. If you're interested, apply here: https://q78175g1wwa.typeform.com/to/d0PEuRPC
Marqo cloud ☁️ is in beta. If you're interested, apply here: https://q78175g1wwa.typeform.com/to/d0PEuRPC

## What is tensor search?

Expand All @@ -41,8 +41,8 @@ Tensor search involves transforming documents, images and other data into collec
2. Use docker to run Marqo (Mac users with M-series chips will need to [go here](#m-series-mac-users)):
```bash
docker rm -f marqo;
docker pull marqoai/marqo:0.0.7;
docker run --name marqo -it --privileged -p 8882:8882 --add-host host.docker.internal:host-gateway marqoai/marqo:0.0.7
docker pull marqoai/marqo:0.0.6;
docker run --name marqo -it --privileged -p 8882:8882 --add-host host.docker.internal:host-gateway marqoai/marqo:0.0.6
```
3. Install the Marqo client:
```bash
Expand Down Expand Up @@ -74,11 +74,12 @@ results = mq.index("my-first-index").search(

```

- `mq` is the client that wraps the`marqo` API
- `mq` is the client that wraps the `marqo` API
- `add_documents()` takes a list of documents, represented as python dicts, for indexing
- `add_documents()` creates an index with default settings, if one does not already exist
- You can optionally set a document's ID with the special `_id` field. Otherwise, Marqo will generate one.
- If the index doesn't exist, Marqo will create it. If it exists then Marqo will add the documents to the index.
- Running this code multiple times could result in duplicate documents. To reset the index, you can delete it first using `mq.index("my-first-index").delete()`

Let's have a look at the results:

Expand Down Expand Up @@ -211,11 +212,7 @@ results = mq.index("my-multimodal-index").search('https://upload.wikimedia.org/w
```

## Documentation
The full documentation for Marqo can be found here [https://marqo.pages.dev/](https://marqo.pages.dev/).

## Warning

Note that you should not run other applications on Marqo's Opensearch cluster as Marqo automatically changes and adapts the settings on the cluster.
The full documentation for Marqo can be found here [https://docs.marqo.ai/](https://docs.marqo.ai/).

## M series Mac users
Marqo does not yet support the docker-in-docker backend configuration for the arm64 architecture. This means that if you have an M series Mac, you will also need to run marqo's backend, marqo-os, locally.
Expand All @@ -225,21 +222,21 @@ To run Marqo on an M series Mac, follow the next steps.
1. In one terminal run the following command to start opensearch:

```shell
docker rm -f marqo-os; docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" marqoai/marqo-os:0.0.2-arm
docker rm -f marqo-os; docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" marqoai/marqo-os:0.0.3-arm
```

2. In another terminal run the following command to launch Marqo:
```shell
docker rm -f marqo; docker run --name marqo --privileged \
-p 8882:8882 --add-host host.docker.internal:host-gateway \
-e "OPENSEARCH_URL=https://localhost:9200" \
marqoai/marqo:0.0.7
marqoai/marqo:0.0.6
```

## Contributors
Marqo is a community project with the goal of making tensor search accessible to the wider developer community. We are glad that you are interested in helping out! Please read [this](./CONTRIBUTING.md) to get started

## Dev set up
## Dev set up
1. Create a virtual env ```python -m venv ./venv```
2. Activate the virtual environment ```source ./venv/bin/activate```
3. Install requirements from the requirements file: ```pip install -r requirements.txt```
Expand All @@ -250,12 +247,25 @@ Marqo is a community project with the goal of making tensor search accessible to
1. Run the full test suite (by using the command `tox` in this dir).
2. Create a pull request with an attached github issue.

<!-- start support-pitch -->


## Support

- Join our [Slack community](https://join.slack.com/t/marqo-community/shared_invite/zt-1d737l76e-u~b3Rvey2IN2nGM4wyr44w) and chat with other community members about ideas.
- Marqo community meetings (coming soon!)

<!-- end support-pitch -->
### Stargazers
[![Stargazers repo roster for @marqo-ai/marqo](https://reporoster.com/stars/marqo-ai/marqo)](https://github.com/marqo-ai/marqo/stargazers)

### Forkers
[![Forkers repo roster for @marqo-ai/marqo](https://reporoster.com/forks/marqo-ai/marqo)](https://github.com/marqo-ai/marqo/network/members)


## Translations

This readme is available in the following translations:

- [English](README.md)🇬🇧
- [Français](README-translated/README-French.md)🇫🇷
- [中文 Chinese](README-translated/README-Chinese.md)🇨🇳
- [Polski](README-translated/README-Polish.md)🇵🇱
- [Українська](README-translated/README-Ukrainian.md)🇺🇦
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"tox"
],
name="marqo",
version="0.5.6",
version="0.5.7",
author="marqo org",
author_email="org@marqo.io",
description="Tensor search for humans",
Expand Down
16 changes: 16 additions & 0 deletions src/marqo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ def index(self, index_name: str) -> Index:
return Index(self.config, index_name=index_name)
raise Exception('The index UID should not be None')

def get_indexes(self) -> Dict[str, List[Index]]:
"""Get all indexes.

Returns:
Indexes, a dictionary with the name of indexes.
"""
response = self.http.get(path='indexes')
response['results'] = [
Index(
config=self.config,
index_name=index_info["index_name"],
)
for index_info in response["results"]
]
return response

@staticmethod
def _base64url_encode(
data: bytes
Expand Down
4 changes: 2 additions & 2 deletions src/marqo/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__marqo_version__ = "0.0.7"
__marqo_release_page__ = "https://github.com/marqo-ai/marqo/releases/tag/0.0.6"
__marqo_version__ = "0.0.8"
__marqo_release_page__ = "https://github.com/marqo-ai/marqo/releases/tag/0.0.8"


def supported_marqo_version() -> str:
Expand Down
1 change: 0 additions & 1 deletion tests/v0_tests/test_add_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import requests
from marqo.client import Client
from marqo.errors import MarqoApiError, MarqoError, MarqoWebError
import unittest
from tests.marqo_test import MarqoTestCase
from marqo import enums
from unittest import mock
Expand Down
75 changes: 75 additions & 0 deletions tests/v0_tests/test_get_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import pprint

import marqo.index
from marqo.client import Client
from marqo.errors import MarqoApiError, MarqoError, MarqoWebError
import unittest
from tests.marqo_test import MarqoTestCase


class TestAddDocuments(MarqoTestCase):

def setUp(self) -> None:
self.client = Client(**self.client_settings)
self.index_name_1 = "my-test-index-1"
self.index_name_2 = "my-test-index-2"
self.index_names = [self.index_name_1, self.index_name_2]
for ix_name in self.index_names:
try:
self.client.delete_index(ix_name)
except MarqoApiError:
pass

def tearDown(self) -> None:
for ix_name in self.index_names:
try:
self.client.delete_index(ix_name)
except MarqoApiError:
pass

def _is_index_name_in_get_indexes_response(self, index_name, get_indexes_response):
for found_index in get_indexes_response['results']:
if index_name == found_index.index_name:
return True
return False

def test_get_indexes(self):
"""Asserts that the results grow after each create_index request
If this test breaks, ensure another user isn't using the same Marqo
instance.
"""
ix_0 = self.client.get_indexes()
assert not self._is_index_name_in_get_indexes_response(self.index_name_1, ix_0)

self.client.create_index(self.index_name_1)
ix_1 = self.client.get_indexes()
assert self._is_index_name_in_get_indexes_response(self.index_name_1, ix_1)

self.client.create_index(self.index_name_2)
ix_2 = self.client.get_indexes()
assert self._is_index_name_in_get_indexes_response(self.index_name_2, ix_2)

assert len(ix_2['results']) > len(ix_1['results'])
assert len(ix_1['results']) > len(ix_0['results'])

for found_index in ix_2['results']:
assert isinstance(found_index, marqo.index.Index)

def test_get_indexes_usable(self):
"""Are the indices we get back usable? """
self.client.create_index(self.index_name_1)
get_ixes_res = self.client.get_indexes()
assert self._is_index_name_in_get_indexes_response(self.index_name_1, get_ixes_res)

my_ix = None
for found_index in get_ixes_res['results']:
if self.index_name_1 == found_index.index_name:
my_ix = found_index

if my_ix is None:
raise AssertionError

assert my_ix.get_stats()['numberOfDocuments'] == 0
my_ix.add_documents([{'some doc': 'gold fish'}])
assert my_ix.get_stats()['numberOfDocuments'] == 1
assert len(my_ix.search(q='aquatic animal')['hits']) == 1