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

Add component to index aws opensearch #740

Merged
merged 14 commits into from
Jan 3, 2024

Conversation

shub-kris
Copy link
Contributor

This PR aims to add support for indexing to AWS OpenSearch.

@shub-kris shub-kris requested a review from mrchtr December 21, 2023 13:28
Copy link
Contributor

@mrchtr mrchtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shub-kris! Looks already quite promising. Could you try to add a component test as well? You could have a look into the write to Qdrant component. There was something similar implemented.

Args:
index_body (Dict[str, Any]): Parameters that specify index settings, mappings, and aliases for newly created index.
"""
response = self.client.indices.create(self.index_name, body=index_body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the index already exists? Will the index be overwritten? Maybe we add a check if an index exists.

Copy link
Contributor Author

@shub-kris shub-kris Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check what it does if an index already exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

I think you still need to modify the Docker image to be able to run the test with it similar to this so that you can run tests using

docker build . --target test

Could you please update and test?

Copy link
Contributor Author

@shub-kris shub-kris Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out. I almost missed it. But now, Updated and tested

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great :)

did you manage to fix the failing pipelines?

after installing pre-commit you should run

pre-commit run --all-files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yupp

Args:
dataframe (dd.DataFrame): The Dask DataFrame containing the data to be written.
"""
if not self.client.indices.exists(index=self.index_name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could call the create_index here if the index doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can do that

Copy link
Contributor Author

@shub-kris shub-kris Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed anymore as I am doing it inside the __init__ function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the Exception too

region: str,
index_name: str,
index_body: Dict[str, Any],
port: int = 443,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not include the default types here for the optional argument since you already define them in the spec and it can be misleading (they are not actually used here it will always default to the ones defined in the spec). You can instead define their types as optional just so that it's clear that they do have default values and they don't need to be explicitly defined. Similar to here

"""Creates an index in AWS OpenSearch.

Args:
index_body (Dict[str, Any]): Parameters that specify index settings,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
index_body (Dict[str, Any]): Parameters that specify index settings,
index_body: Parameters that specify index settings,

Our convention, we only define data types in the argument and not the docstring (single source of truth)

Writes the data from the given Dask DataFrame to AWS OpenSearch Index.

Args:
dataframe (dd.DataFrame): The Dask DataFrame containing the data to be written.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dataframe (dd.DataFrame): The Dask DataFrame containing the data to be written.
dataframe: The Dask DataFrame containing the data to be written.

msg = f"Index: {self.index_name} doesn't exist. Please Create"
raise ValueError(msg)

for part in dataframe.partitions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for part in dataframe.partitions:
for part in tqdm(
dataframe.partitions,
desc="Processing partitions",
total=dataframe.npartitions,
):

Useful to add logs in case the dataset is large. Similar to https://github.com/ml6team/fondant/blob/main/components/index_weaviate/src/main.py

Don't forget to add tqdm to the list of requirements

@RobbeSneyders
Copy link
Member

RobbeSneyders commented Dec 21, 2023

FYI, there's another test example in the index_weaviate component.

You can install pre-commit to take care of all the static checks for you (which are the reason the pipeline is currently failing). Just execute the following 3 commands:

pip install poetry
poetry install --all-extras
pre-commit install

@RobbeSneyders RobbeSneyders changed the title Feature/index aws opensearch Add component to index aws opensearch Dec 21, 2023
Copy link
Contributor

@PhilippeMoussalli PhilippeMoussalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shub-kris! Nice first contribution

"""
index_name = "pytest-index"
aws_os_comp = IndexAWSOpenSearchComponent(
host="search-genai-vectordb-domain-f7vxqkogveaie2qdrivnkr66om.eu-west-1.es.amazonaws.com",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to test this locally instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise it might be better to mock this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocking is the only solution to test it without having access to AWS OpenSearch Cluster.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed, so I would prefer that. Currently I cannot test this component myself. The goal of these tests is to be unit tests, we have other mechanism for integration testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that and update the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobbeSneyders updated

Copy link
Member

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shub-kris!

@RobbeSneyders RobbeSneyders merged commit ea8c6f4 into ml6team:main Jan 3, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants