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 AI21Embeddings class text embeddings #2253

Merged

Conversation

LaloLalo1999
Copy link
Contributor

This pull request adds the AI21Embeddings class to the langchain/langchain/embeddings module, providing support for generating text embeddings using the AI21 language model. The new class offers a similar interface as the existing OpenAIEmbeddings class, making it easy to integrate into the existing codebase.

The AI21Embeddings class has the following main methods:

generate_embeddings(texts, model): Generates embeddings for a list of texts using the specified AI21 model.
get_similarity(text1, text2, model): Calculates the similarity between two texts using the specified AI21 model.
The implementation uses the AI21 Python SDK for interacting with the AI21 API and requires an API key for initialization. The class is designed to be flexible and easy to use, allowing users to switch between different AI21 models by simply providing the model name as an argument.

This PR addresses issue #85 and provides an alternative to the existing OpenAI-based text embeddings.

Please let me know if you have any questions or need further changes.

This commit adds type annotations to the AI21Embeddings class in the langchain/langchain/embeddings/ai21.py file. The type annotations provide better readability and maintainability for the code, as well as help with type checking and documentation. This change addresses the linting errors identified in the previous pull request and ensures that the code adheres to the project’s coding standards.
This commit addresses the linting errors in the AI21Embeddings class by adding type annotations for the __enter__ and __exit__ methods. Additionally, it replaces the undefined 'client' attribute with the proper ai21.Completion.execute method call in the generate_embeddings method. These changes resolve the linting errors and ensure proper functionality of the AI21Embeddings class.
This commit fixes the remaining lint error by adding the missing type annotation for the `response` variable in the `generate_embeddings` method. This ensures that the code adheres to the type checking requirements, allowing for better maintainability and readability.
This commit adds the missing type annotations in ai21.py, specifically:

1. Importing additional typing hints: Any, Optional, and Dict.
2. Adding type annotations to the __exit__ method parameters.

These changes improve the code's readability and type checking capabilities.
Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

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

thanks for this! this should inherit from the existing embedding class, as that will make sure it exposes the right methods

- AI21Embeddings now inherits from the Embeddings base class.
- Implemented the embed_documents and embed_query methods in AI21Embeddings.
- Updated the import statement to include the Embeddings class from langchain.embeddings.base.
This commit reformats the ai21.py file using the black code formatter to ensure consistency with the project's coding style. Additionally, the AI21Embeddings class now inherits from the Embeddings base class, allowing for seamless integration with the existing embeddings infrastructure.
This commit addresses the linting issues found in the ai21.py file:

1. Removed an unused import (Dict) from the typing module.
2. Sorted and formatted the import block.

These changes resolve the linting errors and improve the code quality.
This commit addresses the linting issues reported by the CI pipeline for the langchain/embeddings/ai21.py file. It includes:

- Removing unused imports
- Sorting and formatting import statements using isort
- Ensuring proper indentation and formatting as per the project standards

With these changes, the ai21.py file should now pass the lint checks and be ready for integration into the project.
@LaloLalo1999
Copy link
Contributor Author

Thanks for the corrections, now it should be working, finally passed the lint checks

@hwchase17 hwchase17 changed the base branch from master to harrison/ai21-embeddings April 3, 2023 21:26
@hwchase17 hwchase17 merged commit 0c223c5 into langchain-ai:harrison/ai21-embeddings Apr 3, 2023
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.

None yet

2 participants