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

[ENH] AmazonBedrockEmbeddingFunction for JS #1659

Closed
wants to merge 10 commits into from

Conversation

chezou
Copy link
Contributor

@chezou chezou commented Jan 20, 2024

Description of changes

Summarize the changes made by this PR.

Test plan

  • Tests pass locally with pytest for python, yarn test for js

Also, manually tested with node:

$ npx node
Welcome to Node.js v18.17.1.
Type ".help" for more information.
> const { fromSSO } = require('@aws-sdk/credential-providers');
> const { AmazonBedrockEmbeddingFunction} = require('chromadb')
> var c = await fromSSO({profile: "my-profile"})
> var ef = new AmazonBedrockEmbeddingFunction({config: {credentials: c, region: "us-east-1"}})
> var emb = await ef.generate(["foo"])
> emb
[
  [
     -0.033203125,  -0.15722656,  -0.21386719,   -0.080078125,
      0.061035156,  -0.26171875,      0.78125, -0.00090408325,
      0.119140625, -0.060058594,   0.96484375,        0.65625,
        0.3203125,  -0.24707031,  -0.49414062,     0.66796875,
             -0.5,   -1.0546875,   -0.7578125,        0.53125,
      -0.25585938,    0.5234375,   0.16601562,      1.2421875,
       0.34765625,   0.69140625,   0.32226562,     0.14550781,
         0.890625,  -0.46679688,   0.12011719,      -0.859375,
     -0.087890625,    -0.546875,   -0.1953125,     -1.3671875,
       0.34570312,   -1.3046875,  -0.13476562,    -0.47070312,
       0.43359375,  -0.47851562,    1.2578125,     0.44140625,
      -0.36914062,  -0.69921875,   0.16308594,     0.65234375,
      -0.40820312,  0.111328125, -0.026855469,    0.039794922,
       -0.8515625,  -0.08251953,   0.13574219,      0.7578125,
       0.21679688,   0.25585938,   -0.4296875,    -0.45898438,
               -1,  -0.51171875,   0.31054688,    -0.74609375,
      0.030151367,  -0.46484375,  -0.62109375,     0.58203125,
       -1.1015625,     0.515625, -0.111328125,   -0.076171875,
         0.796875,  -0.64453125,     0.921875,     0.27148438,
          0.71875,    0.1953125,   0.17578125,     0.90234375,
      -0.37695312,   0.33203125,  0.018066406,   -0.009094238,
       0.12890625,   0.34179688,    0.6796875,    -0.19335938,
    0.00012207031,   0.75390625,       -0.125,     0.94921875,
        1.2734375,   0.26757812,  -0.25976562,     0.83203125,
      -0.57421875,  -0.87109375, -0.020629883,        0.46875,
    ... 1436 more items
  ]
]

Documentation Changes

Will update chroma-core/docs later.

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

Copy link
Contributor

@tazarov tazarov left a comment

Choose a reason for hiding this comment

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

@chezou, thank you for the great work. This looks good, but one important aspect of why Chroma is great is that we invest a lot of time crafting tests to ensure DX is smooth.

Will it be too much to ask you to add a test for the bedrock EF. You can find an example of a conditional test here for OpenAI here -

if (!process.env.OPENAI_API_KEY) {
. The test should only run if AWS credentials necessary for running the EF are present as env vars.

clients/js/package.json Show resolved Hide resolved
@chezou
Copy link
Contributor Author

chezou commented Jan 21, 2024

I added a change to ensure the default region, otherwise, the client returns error fa9746f

I'll add a test for this embedding function later.

@chezou
Copy link
Contributor Author

chezou commented Jan 22, 2024

Added a test for the function 6ef9154

@chezou
Copy link
Contributor Author

chezou commented Jan 28, 2024

@tazarov Can you allow to run tests?

@jeffchuber
Copy link
Contributor

@chezou im not sure why tests aren't running 🤔 can you tack on an extra commit here to trigger them? thank you! my apologies for the delay here

@chezou
Copy link
Contributor Author

chezou commented Feb 27, 2024

@jeffchuber Thanks! Created an empty commit b7425e8, but it looks approval for run is required
image

@chezou chezou changed the title feat: AmazonBedrockEmbeddingFunction for JS [ENH] AmazonBedrockEmbeddingFunction for JS Mar 13, 2024
@chezou
Copy link
Contributor Author

chezou commented Mar 13, 2024

Fixed the PR title since "Check PR Title" was failed.

@jeffchuber
Copy link
Contributor

tests will now re-run with the merge conflicts handled. sorry about the PR title issue

@chezou chezou requested a review from tazarov April 3, 2024 16:14
@chezou
Copy link
Contributor Author

chezou commented Apr 3, 2024

@tazarov @jeffchuber If there's no issue, could you approve and merge this PR?

@tazarov
Copy link
Contributor

tazarov commented Apr 16, 2024

@chezou, do you mind resolving the conflict?

@chezou
Copy link
Contributor Author

chezou commented Apr 16, 2024

@tazarov Resolved

Copy link
Contributor

@tazarov tazarov left a comment

Choose a reason for hiding this comment

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

One clarification and a nit about the test. Other than this it looks good.

await this.loadClient();
const td = new TextDecoder();
const embeddings: number[][] = [];
return Promise.all(texts.map(async text => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@chezou, just confirming my understanding here is that if the user provides several texts, the EF will embed each one individually, and if it hits a problem, then an error is raised. The existing embeddings are, in a way, lost, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the correct understanding. If we need to preserve partial embeddings, I have to modify to use Promise.allSettled instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tazarov Let me know if I need to do something additional.

@@ -83,6 +86,34 @@ if (!process.env.COHERE_API_KEY) {
});
}

if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind moving this to a separate file under test/embeddings/aws.bedrock.test.ts? This file is getting very crowded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Splitted 5a6b8ec

Copy link

vercel bot commented May 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chroma ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 5:05am

@jeffchuber
Copy link
Contributor

Our underlying impl has changed and so this PR is not landable as is.

That being said - we'd still like to add this functionality and that is now tracked in this issue.

@jeffchuber jeffchuber closed this Sep 15, 2024
@jeffchuber jeffchuber mentioned this pull request Sep 15, 2024
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.

3 participants