-
-
Notifications
You must be signed in to change notification settings - Fork 29
testing: Weaviate impl #88
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
Open
emekaokoli19
wants to merge
6
commits into
AI-Northstar-Tech:main
Choose a base branch
from
emekaokoli19:weaviate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e2a592
testing
emekaokoli19 fa5f40b
changes
emekaokoli19 4e18e48
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ad6920c
fixing some things
dhruv-anand-aintech 3f48bdd
Merge branch 'main' into pr/emekaokoli19/88
dhruv-anand-aintech 8c311b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,139 @@ | ||||||||||||
| import os | ||||||||||||
| import weaviate | ||||||||||||
| import json | ||||||||||||
| from tqdm import tqdm | ||||||||||||
| from vdf_io.import_vdf.vdf_import_cls import ImportVDB | ||||||||||||
| from vdf_io.names import DBNames | ||||||||||||
| from vdf_io.util import set_arg_from_input, set_arg_from_password | ||||||||||||
|
|
||||||||||||
| # Set these environment variables | ||||||||||||
| URL = os.getenv("YOUR_WCS_URL") | ||||||||||||
| APIKEY = os.getenv("YOUR_WCS_API_KEY") | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class ImportWeaviate(ImportVDB): | ||||||||||||
| DB_NAME_SLUG = DBNames.WEAVIATE | ||||||||||||
|
|
||||||||||||
| @classmethod | ||||||||||||
| def make_parser(cls, subparsers): | ||||||||||||
| parser_weaviate = subparsers.add_parser( | ||||||||||||
| cls.DB_NAME_SLUG, help="Import data into Weaviate" | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| parser_weaviate.add_argument("--url", type=str, help="URL of Weaviate instance") | ||||||||||||
| parser_weaviate.add_argument("--api_key", type=str, help="Weaviate API key") | ||||||||||||
| parser_weaviate.add_argument( | ||||||||||||
| "--index_name", type=str, help="Name of the index in Weaviate" | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| @classmethod | ||||||||||||
| def import_vdb(cls, args): | ||||||||||||
| set_arg_from_input( | ||||||||||||
| args, | ||||||||||||
| "url", | ||||||||||||
| "Enter the URL of Weaviate instance: ", | ||||||||||||
| str, | ||||||||||||
| ) | ||||||||||||
| set_arg_from_password( | ||||||||||||
| args, | ||||||||||||
| "api_key", | ||||||||||||
| "Enter the Weaviate API key: ", | ||||||||||||
| "WEAVIATE_API_KEY", | ||||||||||||
| ) | ||||||||||||
| set_arg_from_input( | ||||||||||||
| args, | ||||||||||||
| "index_name", | ||||||||||||
| "Enter the name of the index in Weaviate: ", | ||||||||||||
| str, | ||||||||||||
| ) | ||||||||||||
| weaviate_import = ImportWeaviate(args) | ||||||||||||
| weaviate_import.upsert_data() | ||||||||||||
| return weaviate_import | ||||||||||||
|
|
||||||||||||
| def __init__(self, args): | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To fix this, add the
Suggested change
|
||||||||||||
| super().__init__(args) | ||||||||||||
| if self.args["connection_type"] == "local": | ||||||||||||
| self.client = weaviate.connect_to_local() | ||||||||||||
| else: | ||||||||||||
| self.client = weaviate.connect_to_wcs( | ||||||||||||
| cluster_url=self.args["url"], | ||||||||||||
| auth_credentials=weaviate.auth.AuthApiKey(self.args["api_key"]), | ||||||||||||
| headers={'X-OpenAI-Api-key': self.args["openai_api_key"]} | ||||||||||||
| if self.args["openai_api_key"] | ||||||||||||
| else None, | ||||||||||||
| skip_init_checks=True, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| def upsert_data(self): | ||||||||||||
| max_hit = False | ||||||||||||
| total_imported_count = 0 | ||||||||||||
|
|
||||||||||||
| # Iterate over the indexes and import the data | ||||||||||||
| for index_name, index_meta in tqdm(self.vdf_meta["indexes"].items(), desc="Importing indexes"): | ||||||||||||
| tqdm.write(f"Importing data for index '{index_name}'") | ||||||||||||
| for namespace_meta in index_meta: | ||||||||||||
| self.set_dims(namespace_meta, index_name) | ||||||||||||
|
|
||||||||||||
| # Create or get the index | ||||||||||||
| index_name = self.create_new_name(index_name, self.client.collections.list_all().keys()) | ||||||||||||
| index = self.client.collections.get(index_name) | ||||||||||||
|
|
||||||||||||
| # Load data from the Parquet files | ||||||||||||
| data_path = namespace_meta["data_path"] | ||||||||||||
| final_data_path = self.get_final_data_path(data_path) | ||||||||||||
| parquet_files = self.get_parquet_files(final_data_path) | ||||||||||||
|
|
||||||||||||
| vectors = {} | ||||||||||||
| metadata = {} | ||||||||||||
|
|
||||||||||||
| # for file in tqdm(parquet_files, desc="Loading data from parquet files"): | ||||||||||||
| # file_path = os.path.join(final_data_path, file) | ||||||||||||
| # df = self.read_parquet_progress(file_path) | ||||||||||||
|
|
||||||||||||
| # if len(vectors) > (self.args.get("max_num_rows") or INT_MAX): | ||||||||||||
| # max_hit = True | ||||||||||||
| # break | ||||||||||||
|
|
||||||||||||
| # self.update_vectors(vectors, vector_column_name, df) | ||||||||||||
| # self.update_metadata(metadata, vector_column_names, df) | ||||||||||||
| # if max_hit: | ||||||||||||
| # break | ||||||||||||
|
|
||||||||||||
| # tqdm.write(f"Loaded {len(vectors)} vectors from {len(parquet_files)} parquet files") | ||||||||||||
|
|
||||||||||||
| # # Upsert the vectors and metadata to the Weaviate index in batches | ||||||||||||
| # BATCH_SIZE = self.args.get("batch_size", 1000) or 1000 | ||||||||||||
| # current_batch_size = BATCH_SIZE | ||||||||||||
| # start_idx = 0 | ||||||||||||
|
|
||||||||||||
| # while start_idx < len(vectors): | ||||||||||||
| # end_idx = min(start_idx + current_batch_size, len(vectors)) | ||||||||||||
|
|
||||||||||||
| # batch_vectors = [ | ||||||||||||
| # ( | ||||||||||||
| # str(id), | ||||||||||||
| # vector, | ||||||||||||
| # { | ||||||||||||
| # k: v | ||||||||||||
| # for k, v in metadata.get(id, {}).items() | ||||||||||||
| # if v is not None | ||||||||||||
| # } if len(metadata.get(id, {}).keys()) > 0 else None | ||||||||||||
| # ) | ||||||||||||
| # for id, vector in list(vectors.items())[start_idx:end_idx] | ||||||||||||
| # ] | ||||||||||||
|
|
||||||||||||
| # try: | ||||||||||||
| # resp = index.batch.create(batch_vectors) | ||||||||||||
| # total_imported_count += len(batch_vectors) | ||||||||||||
| # start_idx += len(batch_vectors) | ||||||||||||
| # except Exception as e: | ||||||||||||
| # tqdm.write(f"Error upserting vectors for index '{index_name}', {e}") | ||||||||||||
| # if current_batch_size < BATCH_SIZE / 100: | ||||||||||||
| # tqdm.write("Batch size is not the issue. Aborting import") | ||||||||||||
| # raise e | ||||||||||||
| # current_batch_size = int(2 * current_batch_size / 3) | ||||||||||||
| # tqdm.write(f"Reducing batch size to {current_batch_size}") | ||||||||||||
| # continue | ||||||||||||
|
|
||||||||||||
| # tqdm.write(f"Data import completed successfully. Imported {total_imported_count} vectors") | ||||||||||||
| # self.args["imported_count"] = total_imported_count | ||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
add_argumentsis incorrect and will cause a runtime error as it does not exist in argparse. It should beadd_argument.