Skip to content

Commit a9519d4

Browse files
authored
[ENH]: return error on /add if embeddings are not provided (#5033)
## Description of changes Our official clients prevent this but the server does not have a check. A better solution is making `AddCollectionRecordsPayload.embddings` non-optional, but this works as a minimal patch for now. ## Test plan _How are these changes tested?_ - [x] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Documentation Changes _Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs section](https://github.com/chroma-core/chroma/tree/main/docs/docs.trychroma.com)?_ n/a
1 parent b752329 commit a9519d4

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

rust/frontend/src/server.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,10 @@ async fn collection_add(
13101310
let mut quota_payload = QuotaPayload::new(Action::Add, tenant.clone(), api_token);
13111311
quota_payload = quota_payload.with_ids(&payload.ids);
13121312

1313+
if payload.embeddings.is_none() {
1314+
return Err(ValidationError::MissingEmbeddings.into());
1315+
}
1316+
13131317
let payload_embeddings: Option<Vec<Vec<f32>>> = maybe_decode_embeddings(payload.embeddings)?;
13141318
if let Some(embeddings) = payload_embeddings.as_ref() {
13151319
quota_payload = quota_payload.with_add_embeddings(embeddings);

rust/frontend/src/types/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub enum ValidationError {
3030
UpdateCollection(#[from] UpdateCollectionError),
3131
#[error("Error parsing collection configuration: {0}")]
3232
ParseCollectionConfiguration(#[from] CollectionConfigurationToInternalConfigurationError),
33+
#[error("Embeddings not provided")]
34+
MissingEmbeddings,
3335
}
3436

3537
impl ChromaError for ValidationError {
@@ -42,6 +44,7 @@ impl ChromaError for ValidationError {
4244
ValidationError::GetCollection(err) => err.code(),
4345
ValidationError::UpdateCollection(err) => err.code(),
4446
ValidationError::ParseCollectionConfiguration(_) => ErrorCodes::InvalidArgument,
47+
ValidationError::MissingEmbeddings => ErrorCodes::InvalidArgument,
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)