Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/Changelog/sdk-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This page documents the release history of the [Agentuity JavaScript SDK](https:

### Changes

- **Added**: Support for bulk delete in vector storage ([PR #145](https://github.com/agentuity/sdk-js/pull/145))
- **Added**: Support for bulk delete in vector storage - The `vector.delete()` method now accepts multiple keys as variadic arguments, allowing efficient bulk deletion of vectors. Supports both single key deletion (`delete(name, key)`) and bulk deletion (`delete(name, key1, key2, key3)`) patterns. This is more efficient than making multiple individual delete calls. ([PR #145](https://github.com/agentuity/sdk-js/pull/145))
- **Changed**: Improved documentation of vector search parameters and tightened vector search metadata type definition ([PR #146](https://github.com/agentuity/sdk-js/pull/146))

## v0.0.130
Expand Down
24 changes: 18 additions & 6 deletions content/SDKs/javascript/api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -259,25 +259,37 @@ for (const result of results) {
}
```

#### `delete(name: string, key: string): Promise<number>`
#### `delete(name: string, ...keys: string[]): Promise<number>`

Deletes a vector from the vector storage.
Deletes one or more vectors from the vector storage.

##### Parameters

- `name`: The name of the vector storage
- `key`: The ID of the vector to delete
- `keys`: One or more keys of the vectors to delete

##### Return Value

Returns a Promise that resolves to the number of vectors that were deleted (0 or 1).
Returns a Promise that resolves to the number of vectors that were deleted.

##### Example
##### Examples

```typescript
// Delete a single vector
const deletedCount = await context.vector.delete('product-descriptions', 'id1');
console.log(`Deleted ${deletedCount} vector(s)`);
console.log(`Deleted ${deletedCount} vector(s)`); // Output: Deleted 1 vector(s)

// Delete multiple vectors in bulk (more efficient than individual calls)
const deletedCount = await context.vector.delete('product-descriptions', 'id1', 'id2', 'id3');
console.log(`Deleted ${deletedCount} vector(s)`); // Output: Deleted 3 vector(s)

// Delete with array spread
const keysToDelete = ['id1', 'id2', 'id3'];
const deletedCount = await context.vector.delete('product-descriptions', ...keysToDelete);

// Handle cases where some vectors might not exist
const deletedCount = await context.vector.delete('product-descriptions', 'existing-id', 'non-existent-id');
console.log(`Deleted ${deletedCount} vector(s)`); // Output: Deleted 1 vector(s)
```

### Object Storage
Expand Down
11 changes: 7 additions & 4 deletions content/SDKs/javascript/examples/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,18 @@ const handler: AgentHandler = async (request, response, context) => {
}

case 'delete': {
// Delete a product from vector storage
// Delete products from vector storage
if (!products || !Array.isArray(products) || products.length === 0) {
return response.json({ error: 'No product ID to delete' });
return response.json({ error: 'No product IDs to delete' });
}

const count = await context.vector.delete('products', products[0]);
// Support both single and bulk deletion
const productIds = products.map(p => p.id || p);
const count = await context.vector.delete('products', ...productIds);

return response.json({
message: `Deleted ${count} product successfully`
message: `Deleted ${count} product(s) successfully`,
deletedCount: count
});
}

Expand Down