Skip to content

[ENH] Delete with limit in server#6573

Merged
Sicheng-Pan merged 3 commits intomainfrom
03-06-_enh_delete_with_limit
Mar 7, 2026
Merged

[ENH] Delete with limit in server#6573
Sicheng-Pan merged 3 commits intomainfrom
03-06-_enh_delete_with_limit

Conversation

@Sicheng-Pan
Copy link
Copy Markdown
Contributor

@Sicheng-Pan Sicheng-Pan commented Mar 6, 2026

Description of changes

Summarize the changes made by this PR.

  • Improvements & Bug fixes
    • N/A
  • New functionality
    • Introduce limit: Option<u32> in the collection delete route. The response now returns how many records have been deleted.

Test plan

How are these changes tested?

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

Migration plan

Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?

Observability plan

What is the plan to instrument and monitor this change?

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2026

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
Copy Markdown
Contributor Author

Sicheng-Pan commented Mar 6, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

propel-code-bot[bot]

This comment was marked as outdated.

@blacksmith-sh

This comment has been minimized.

@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch 2 times, most recently from 19c9b46 to b5e2b71 Compare March 6, 2026 23:30
propel-code-bot[bot]

This comment was marked as outdated.

@blacksmith-sh

This comment has been minimized.

@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch from b5e2b71 to 2755df3 Compare March 6, 2026 23:54
Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

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

Changes suggested to add validation, correct API docs, and expose new delete limit in bindings.

Status: Changes Suggested | Risk: Medium

Issues Identified & Suggestions
  • Validate delete limit bounds to avoid no-op/exhaustion: rust/types/src/api_types.rs
  • Fix OpenAPI response type for delete endpoint: rust/frontend/src/server.rs
  • Expose limit and deleted count in Python bindings: rust/python_bindings/src/bindings.rs
Review Details

📁 9 files reviewed | 💬 3 comments

👍 / 👎 individual comments to help improve reviews for you

collection_id: CollectionUuid,
ids: Option<Vec<String>>,
r#where: Option<Where>,
limit: Option<u32>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

[Security] Missing validation: The limit parameter is accepted as Option<u32> but lacks validation for sensible bounds. A client could send limit: 0 or limit: u32::MAX, both of which are problematic.

Issues:

  • limit: 0 makes the operation a no-op (why allow it?)
  • limit: u32::MAX (4.2 billion) could cause memory exhaustion
  • No documented maximum safe value

Fix: Add validation in try_new():

if let Some(limit_val) = limit {
    if limit_val == 0 {
        return Err(ChromaValidationError::from((
            "limit",
            "must be greater than 0",
        )));
    }
    if limit_val > MAX_DELETE_LIMIT {  // e.g., 10000
        return Err(ChromaValidationError::from((
            "limit",
            format!("must not exceed {}", MAX_DELETE_LIMIT),
        )));
    }
}
Context for Agents
**Missing validation**: The `limit` parameter is accepted as `Option<u32>` but lacks validation for sensible bounds. A client could send `limit: 0` or `limit: u32::MAX`, both of which are problematic.

**Issues**:
- `limit: 0` makes the operation a no-op (why allow it?)
- `limit: u32::MAX` (4.2 billion) could cause memory exhaustion
- No documented maximum safe value

**Fix**: Add validation in `try_new()`:

```rust
if let Some(limit_val) = limit {
    if limit_val == 0 {
        return Err(ChromaValidationError::from((
            "limit",
            "must be greater than 0",
        )));
    }
    if limit_val > MAX_DELETE_LIMIT {  // e.g., 10000
        return Err(ChromaValidationError::from((
            "limit",
            format!("must not exceed {}", MAX_DELETE_LIMIT),
        )));
    }
}
```

File: rust/types/src/api_types.rs
Line: 1580

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For backward compact we need to support None, which is equivalent to u32::MAX. Limit by itself is not going to introduce additional cost than what we already have

collection_id,
ids,
r#where,
None,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

[Requirements] The limit parameter is hardcoded to None here, meaning the new functionality is not exposed to Python users. Additionally, the return value (deleted count) is discarded by returning Ok(()).

Please update the delete method signature to accept an optional limit argument and return the deleted count, ensuring feature parity for the Python bindings.

Context for Agents
The `limit` parameter is hardcoded to `None` here, meaning the new functionality is not exposed to Python users. Additionally, the return value (deleted count) is discarded by returning `Ok(())`.

Please update the `delete` method signature to accept an optional `limit` argument and return the deleted count, ensuring feature parity for the Python bindings.

File: rust/python_bindings/src/bindings.rs
Line: 577

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will be resolved in next PR on stack

@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch from 2755df3 to c0b3443 Compare March 7, 2026 00:03
propel-code-bot[bot]

This comment was marked as outdated.

@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch from c0b3443 to dab3721 Compare March 7, 2026 00:44
@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch from dab3721 to 861f644 Compare March 7, 2026 01:36
@Sicheng-Pan Sicheng-Pan marked this pull request as ready for review March 7, 2026 01:38
@Sicheng-Pan Sicheng-Pan requested a review from rescrv as a code owner March 7, 2026 01:38
@propel-code-bot
Copy link
Copy Markdown
Contributor

propel-code-bot bot commented Mar 7, 2026

Add delete limits with deleted-count responses across API and frontends

This PR introduces a limit parameter for collection record deletion and returns a deleted-count in responses. Core request/response types were updated to include limit and deleted, and deletion logic now applies limits when a where clause is present while rejecting limit without a filter.

Server handlers, service-based and in-memory frontends, and generated JS client types were updated to surface the new payload/response shape, and extensive Rust tests were added to validate limit behavior across where/ids scenarios and looped deletions.

This summary was automatically generated by @propel-code-bot

propel-code-bot[bot]

This comment was marked as outdated.

encoding: None,
metadata: None,
}));
if let Some(limit) = limit {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we just error if user ids len > limit??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

limit is relevant only when a where is specified. added validation for this

assert_eq!(count(&mut frontend, &collection).await, 2);

// Limit is 100, but only 2 records match.
let response = frontend
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we add a test that loops over batches to use this correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct DeleteCollectionRecordsPayload {
pub ids: Option<Vec<String>>,
pub limit: Option<u32>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you need a default here to be b/w compatible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added serde default

@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch from 045a146 to 0ce6340 Compare March 7, 2026 02:37
propel-code-bot[bot]

This comment was marked as outdated.

@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch from 0ce6340 to 1d4a302 Compare March 7, 2026 02:50
Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

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

Review found no issues; changes appear solid and well-covered by tests.

Status: No Issues Found | Risk: Low

Review Details

📁 10 files reviewed | 💬 0 comments

@Sicheng-Pan Sicheng-Pan force-pushed the 03-06-_enh_delete_with_limit branch from 1d4a302 to 0e11fca Compare March 7, 2026 02:58
@Sicheng-Pan Sicheng-Pan changed the title [ENH] Delete with limit [ENH] Delete with limit in server Mar 7, 2026
@Sicheng-Pan Sicheng-Pan merged commit 9100022 into main Mar 7, 2026
108 of 131 checks passed
chroma-droid pushed a commit that referenced this pull request Mar 7, 2026
## Description of changes

_Summarize the changes made by this PR._

- Improvements & Bug fixes
  - N/A
- New functionality
- Introduce `limit: Option<u32>` in the collection delete route. The
response now returns how many records have been deleted.

## Test plan

_How are these changes tested?_

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Migration plan

_Are there any migrations, or any forwards/backwards compatibility
changes needed in order to make sure this change deploys reliably?_

## Observability plan

_What is the plan to instrument and monitor this change?_

## 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)?_
chroma-droid pushed a commit that referenced this pull request Mar 7, 2026
## Description of changes

_Summarize the changes made by this PR._

- Improvements & Bug fixes
  - N/A
- New functionality
- Introduce `limit: Option<u32>` in the collection delete route. The
response now returns how many records have been deleted.

## Test plan

_How are these changes tested?_

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Migration plan

_Are there any migrations, or any forwards/backwards compatibility
changes needed in order to make sure this change deploys reliably?_

## Observability plan

_What is the plan to instrument and monitor this change?_

## 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)?_
Sicheng-Pan added a commit that referenced this pull request Mar 7, 2026
This PR cherry-picks the commit 9100022
onto release/2026-02-20. If there are unresolved conflicts, please
resolve them manually.

Co-authored-by: Macronova <[email protected]>
Sicheng-Pan added a commit that referenced this pull request Mar 7, 2026
This PR cherry-picks the commit 9100022
onto rc/2026-03-06. If there are unresolved conflicts, please resolve
them manually.

Co-authored-by: Macronova <[email protected]>
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.

2 participants