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 : mongodb integration #110

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

vipul-maheshwari
Copy link

@vipul-maheshwari vipul-maheshwari commented Oct 3, 2024

Add MongoDB Export Support

  • Purpose:
    Add support for exporting data from MongoDB databases to the VDF format.
  • Key Changes:
    • Implemented the ExportMongoDB class that inherits from the ExportVDB base class.
    • Added functionality to connect to a MongoDB Atlas instance, retrieve data from a specified collection, and export it to Parquet files.
    • Implemented logic to handle various BSON data types and flatten nested documents.
    • Added support for detecting the vector dimension automatically if not provided.
    • Integrated the new MongoDB export functionality into the command-line interface.
  • Impact:
    This change will allow users to export data from MongoDB databases to the VDF format, enabling them to leverage the VDF ecosystem for vector search, embeddings, and other machine learning tasks.

✨ Generated with love by Kaizen ❤️

Original Description # Add MongoDB Export Functionality
  • **Purpose:
    **
    Add support for exporting data from MongoDB databases to the VDF format.
  • Key Changes:
    • Introduced a new ExportMongoDB class that inherits from the base ExportVDB class.
    • Implemented methods to connect to a MongoDB database, fetch data from a specified collection, and export the data to Parquet files.
    • Added support for handling various BSON data types (ObjectId, Binary, Regex, Timestamp, Decimal128, Code) during the flattening process.
    • Integrated the new MongoDB export functionality into the command-line interface.
  • **Impact:
    **
    Users can now export data from MongoDB databases to the VDF format, enabling seamless integration with the VDF ecosystem and downstream applications.

✨ Generated with love by Kaizen ❤️

Original Description # Add MongoDB Export Functionality
  • ****Purpose:
    **
    **
    Introduces a new feature to export data from MongoDB into a specified format.
  • Key Changes:
    • Added .cfg and environment-related entries to .gitignore.
    • Updated requirements.txt to include pymongo.
    • Created mongodb_export.py for handling MongoDB data exports.
    • Implemented argument parsing for MongoDB connection and export parameters.
    • Enhanced utility functions to support MongoDB-specific data handling.
  • ****Impact:
    **
    **
    This addition allows users to seamlessly export data from MongoDB, enhancing the tool's versatility.

✨ Generated with love by Kaizen ❤️

Original Description # Add MongoDB Export Functionality
  • ******Purpose:
    **
    **
    **
    Introduce functionality to export data from MongoDB to a specified format.
  • Key Changes:
    • Added .cfg and environment-related entries to .gitignore.
    • Updated requirements.txt to include pymongo for MongoDB support.
    • Implemented ExportMongoDB class for handling MongoDB data exports.
    • Added command-line argument parsing for MongoDB connection and export parameters.
    • Integrated data flattening and exporting to Parquet format.
  • ******Impact:
    **
    **
    **
    This enhancement allows users to seamlessly export data from MongoDB, improving data integration capabilities.

✨ Generated with love by Kaizen ❤️

Original Description # Add MongoDB Export Functionality
  • ********Purpose:
    **
    **
    **
    **
    Adds the ability to export data from a MongoDB database to the VDF format.
  • Key Changes:
    • Added a new ExportMongoDB class that inherits from the ExportVDB base class.
    • Implemented methods to connect to a MongoDB database, fetch data from a specified collection, and export the data to Parquet files.
    • Included support for handling various BSON data types (ObjectId, Binary, Regex, Timestamp, Decimal128, Code) during the flattening process.
    • Added a new mongodb subparser to the command-line interface to allow users to specify MongoDB connection details and export options.
  • ********Impact:
    **
    **
    **
    **
    This change will enable users to export data from MongoDB databases to the VDF format, allowing for easier integration with the VDF ecosystem and downstream applications.

✨ Generated with love by Kaizen ❤️

Original Description - [ ] export script - [ ] import script

[!IMPORTANT]
Adds MongoDB export functionality with BSON handling and Parquet export in mongodb_export.py.

  • MongoDB Export Integration:
    • Adds ExportMongoDB class in mongodb_export.py for exporting data from MongoDB.
    • Implements make_parser() and export_vdb() methods for argument parsing and export logic.
    • Handles BSON type conversions and data flattening in flatten_dict().
    • Exports data to Parquet format with vector dimension detection in get_data().
  • Configuration:
    • Adds MONGODB to DBNames in names.py.
    • Updates db_metric_to_standard_metric in util.py to include MongoDB distance metrics.
  • Dependencies:
    • Adds pymongo to requirements.txt.

This description was created by Ellipsis for 6788f90. It will automatically update as commits are pushed.

Copy link

@kaizen-bot kaizen-bot bot left a comment

Choose a reason for hiding this comment

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

Consider implementing the following changes to improve the code.

src/vdf_io/export_vdf/mongodb_export.py Show resolved Hide resolved
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 6788f90 in 13 seconds

More details
  • Looked at 245 lines of code in 4 files
  • Skipped 1 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. src/vdf_io/export_vdf/mongodb_export.py:3
  • Draft comment:
    The import statement import bson is redundant since specific imports from bson are already made. Consider removing it to clean up the code.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The import statement for bson is redundant since specific imports from bson are already made. This redundancy can be removed to clean up the code.
2. src/vdf_io/export_vdf/mongodb_export.py:10
  • Draft comment:
    The set_arg_from_password function is imported but not used. Consider removing this import to clean up the code.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The set_arg_from_password function is imported but not used in the mongodb_export.py file. This is unnecessary and should be removed to clean up the code.
3. src/vdf_io/export_vdf/mongodb_export.py:14
  • Draft comment:
    The ConnectionFailure and OperationFailure imports from pymongo.errors are not used. Consider removing these imports to clean up the code.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The ConnectionFailure and OperationFailure imports from pymongo.errors are not used in the code. These should be removed to clean up the code.
4. src/vdf_io/export_vdf/mongodb_export.py:117
  • Draft comment:
    The object_columns_list is populated but never used. Consider removing it to clean up the code.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The object_columns_list is being populated but never used. This is unnecessary and should be removed to clean up the code.

Workflow ID: wflow_cuCIRBnrVVwADNP6


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

@kaizen-bot kaizen-bot bot left a comment

Choose a reason for hiding this comment

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

Consider implementing the following changes to improve the code.

src/vdf_io/export_vdf/mongodb_export.py Show resolved Hide resolved
Copy link

@kaizen-bot kaizen-bot bot left a comment

Choose a reason for hiding this comment

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

Consider implementing the following changes to improve the code.

total=total,
num_vectors_exported=total,
dim=expected_dim,
vector_columns=vector_columns,
Copy link

Choose a reason for hiding this comment

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

Comment: Inefficient data retrieval in get_data method

Solution: Consider using MongoDB's aggregation framework for more efficient data processing.
Potential Fix:
cursor = self.collection.aggregate([...]) # Use aggregation pipeline here

Copy link

kaizen-bot bot commented Oct 3, 2024

🔍 Code Review Summary

All Clear: This commit looks good! 👍

Overview

  • Total Feedbacks: 0 (Critical: 0, Refinements: 0)
  • Files Affected: 0
  • Code Quality: [██████████████████░░] 90% (Excellent)

✨ Generated with love by Kaizen ❤️

Useful Commands
  • Feedback: Share feedback on kaizens performance with !feedback [your message]
  • Ask PR: Reply with !ask-pr [your question]
  • Review: Reply with !review
  • Update Tests: Reply with !unittest to create a PR with test changes

except pymongo.errors.ServerSelectionTimeoutError as err:
logger.error(f"Failed to connect to MongoDB: {err}")
raise
self.db = self.client[args["database"]]
Copy link
Member

Choose a reason for hiding this comment

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

let's add an error check here

logger.error(f"Failed to connect to MongoDB: {err}")
raise
self.db = self.client[args["database"]]
self.collection = self.db[args["collection"]]
Copy link
Member

Choose a reason for hiding this comment

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

same here

self.collection = self.db[args["collection"]]

def get_index_names(self):
if self.args.get("collection", None) is not None:
Copy link
Member

Choose a reason for hiding this comment

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

need to check if it exists

Comment on lines +167 to +180
flattened_data = []
for document in batch_data:
flat_doc = self.flatten_dict(document)

for key in flat_doc:
if isinstance(flat_doc[key], dict):
flat_doc[key] = json.dumps(flat_doc[key])
elif flat_doc[key] == "":
flat_doc[key] = None

flattened_data.append(flat_doc)

df = pd.DataFrame(flattened_data)
df = df.dropna(axis=1, how="all")
Copy link
Member

Choose a reason for hiding this comment

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

need to push data to disk as it is streamed, so that the RAM doesn't fill up

@dhruv-anand-aintech
Copy link
Member

Thanks for contributing to Vector-io!

please also give a short readme or how-to for exporting data from mongo, as it is a bit harder than a normal VectorDB (connection string v/s looking up fields like admin password from the portal). Thanks.

@vipul-maheshwari
Copy link
Author

Got you comments! Will do the needful!

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.

2 participants