-
Notifications
You must be signed in to change notification settings - Fork 295
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
Embeddings support in the SDK #1475
Conversation
.map(|v| { | ||
v.as_str() | ||
.with_context(|| "only text embeddings are supported") | ||
.unwrap() |
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.
You can collect into a Result<Vec<_>>
so you can ?
the Result
instead of panicking if the value is not a str
.
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.
Something like
let texts = texts
.0
.as_array()
.with_context(|| "embed_batch takes an array of texts")?
.iter()
.map(|v| {
v.as_str()
.with_context(|| "only text embeddings are supported")
.map(|s| s.to_string())
})
.collect::<anyhow::Result<Vec<String>>>()?;
I think will work.
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.
I don't think we want that. The API accepts an array of strings, so if someone passes in an array of objects that can be cast to a string, they will get embeddings of integers, or whatever else they passed in, which will make them think that everything is fine.
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.
We are still calling as_str
here so if it was an object, it wouldn't be treated as a string. I was merely suggesting using Result::Err
instead of unwrap
. But all is good.
A test for both in Rust, Python, and JavaScript would be nice |
Do these tests run in CI or only locally? They require a PostgresML installation to be running somewhere right? |
I can't seem to find instructions for setting up the JS environment for testing this. I did the Python one from memory, but it would be nice to have a short README for developers. I'm going to skip the JS tests for now and come back to them when I have a moment. |
SDK
pgml.embed()
support intoBuiltins
, with single and batch mode.