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 embeddings space component #16

Merged
merged 3 commits into from
Aug 31, 2023
Merged

Conversation

juanjoman
Copy link
Member

No description provided.

Copy link
Member

@javiertoledo javiertoledo left a comment

Choose a reason for hiding this comment

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

Great work! I left a couple of comments:

  • Let's make generation methods private and remove them from the documentation
  • Let's discuss a bit about error handling and logging. It could make sense to create a small error handler class that help us homogenize how we handle them project-wide. We should avoid masking unknown errors and log messages in the correct log level.


// Or just
Embedding embedding = embeddingSpace.save(sampleText);
Embedding embedding = embeddingsSpace.save(sampleText);
Copy link
Member

Choose a reason for hiding this comment

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

💣 🚀

Comment on lines 21 to 35
public Embedding generate(String text) {
Embedding embedding = null;
try {
embedding = model.generateEmbedding(text);
} catch (RuntimeException e) {
// TODO: Create and catch EmbeddingGenerationException?
System.out.printf("Error while generating embedding tor text %s", text);
}
return embedding;
}

public Embedding generate(String text, Map<String, String> additionalMetadata) {
// TODO: What about metadata?
return model.generateEmbedding(text);
}
Copy link
Member

Choose a reason for hiding this comment

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

I think that we no longer need to make generation methods public. Without the vector arithmetic, there's no reason to expose embedding objects to the user through this interface anymore, because even search calculates the embedding for the reference text internally...

Comment on lines 23 to 28
try {
embedding = model.generateEmbedding(text);
} catch (RuntimeException e) {
// TODO: Create and catch EmbeddingGenerationException?
System.out.printf("Error while generating embedding tor text %s", text);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if capturing exceptions here makes sense because capturing any runtime exception can mask errors and make troubleshooting more challenging. If we want to log the error, that's a good idea, but then we should re-raise the original exception or generate a new one, wrapping the original one. Also, if Java supports log levels, these logs must probably be debug level to avoid stuffing production logs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove the try catchs then, we can detect if this is needed in the future :P

Comment on lines 44 to 46
// TODO: Create and catch EmbeddingStoreException?
System.out.printf("Error while storing embedding %s into the embedding space%n", embedding.toString());
return null;
Copy link
Member

Choose a reason for hiding this comment

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

I've created a MissingRequiredCredentialException in https://github.com/theam/eLLMental/pull/15/files#diff-76b05f415c5a32450bc4c8092ca7a23ac0c019751b652a40173c696823a6bda4R4-R8

Not sure if it makes sense to capture Pinecone exceptions or is better to let them go through though

Copy link
Member

@mnlx mnlx left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@javiertoledo javiertoledo left a comment

Choose a reason for hiding this comment

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

LGTM. Will we wait for the test to be implemented here or you rather work on it in a future PR?

Comment on lines +19 to +21
private Embedding generate(String text) {
return embeddingsGenerationModel.generateEmbedding(text);
}
Copy link
Member

Choose a reason for hiding this comment

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

I like private methods at the bottom of the class because when we read a class we tend to look for public methods first, but no need to change this now.


return mostSimilarEmbeddings(embedding, limit);
}

Copy link
Member

Choose a reason for hiding this comment

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

The extra whitespace triggers OCD feelings 😅. Maybe we can activate a default linter to take all these little details into account 🤔

@juanjoman
Copy link
Member Author

Test will be done here -> #20. So I'm merging this 🎉

@juanjoman juanjoman merged commit 4968a61 into main Aug 31, 2023
1 check passed
@juanjoman juanjoman deleted the embeddings_space_component branch August 31, 2023 13:26
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