-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[WIP] feat: add Voyage embeddings #408
base: main
Are you sure you want to change the base?
Conversation
@fzliu thanks for your contribution. Please take a look at the CI reports and fix them. The rest looks okay to me. |
After analyzing the pull request, here are my findings: Overall Feedback: The addition of the Voyage AI embeddings is a significant enhancement to the project, providing new functionality for embedding models. The code is generally well-structured, but there are areas where improvements can be made, particularly regarding error handling and code clarity. Score: 85/100 Labels: Enhancement, Tests Code Suggestions:
The addition of Voyage AI embeddings is a great enhancement! Here are some suggestions:
|
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._client = _import_voyageai().Client(api_key=self.api_key) |
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.
Suggestion: Validate the API key before using it in the client.
Existing Code:
self._client = _import_voyageai().Client(api_key=self.api_key)
Improved Code:
if not self.api_key:
raise ValueError("API key must be provided for VoyageAIEmbeddings.")
self._client = _import_voyageai().Client(api_key=self.api_key)
Details:
Ensure that the api_key
is validated before using it to create the client.
self, text: str | list[str] | Document | list[Document], *args, **kwargs | ||
) -> list[DocumentWithEmbedding]: | ||
texts = [t.content for t in self.prepare_input(text)] | ||
embeddings = self._client.embed(texts, model=self.model_name).embeddings |
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.
Suggestion: Handle exceptions when calling the embed method to prevent crashes.
Existing Code:
embeddings = self._client.embed(texts, model=self.model_name).embeddings
Improved Code:
try:
embeddings = self._client.embed(texts, model=self.model_name).embeddings
except Exception as e:
raise RuntimeError(f"Failed to retrieve embeddings: {e}")
Details:
Handle potential exceptions when calling the embed method to prevent crashes due to API issues.
def test_voyageai_embeddings(): | ||
model = VoyageAIEmbeddings() | ||
output = model("Hello, world!") | ||
assert_embedding_result(output) |
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.
Suggestion: Ensure the test checks for the correct output structure.
Existing Code:
assert_embedding_result(output)
Improved Code:
assert isinstance(output, list) and all(isinstance(doc, DocumentWithEmbedding) for doc in output)
Details:
Ensure that the test for VoyageAIEmbeddings
checks for the correct output structure.
Description
Adds embeddings from Voyage AI.
Type of change
Checklist