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
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,30 @@ You can also query with:
- **Sparse only**: Provide only `sparseIndices` and `sparseValues`
- **Hybrid**: Provide all three for combined results

## Updating Filters

Use `index.updateFilters()` to update the filter fields of existing vectors without re-upserting them.

```java
import io.endee.client.types.UpdateFilterParams;
import java.util.List;
import java.util.Map;

index.updateFilters(List.of(
new UpdateFilterParams("vec1", Map.of("category", "ml", "score", 95)),
new UpdateFilterParams("vec2", Map.of("category", "science", "score", 80))
));
```

**`UpdateFilterParams` Fields:**

| Field | Required | Description |
| -------- | -------- | -------------------------------------------------- |
| `id` | Yes | ID of the vector to update |
| `filter` | Yes | New filter object to replace the existing filter |

> **Note:** The entire filter object is replaced, not merged.

## Deletion Methods

### Delete by ID
Expand Down Expand Up @@ -522,9 +546,10 @@ public class EndeeExample {

| Method | Parameters | Return Type | Description |
| ----------------------------- | ---------- | ------------------- | -------------------------- |
| `upsert(List<VectorItem>)` | `vectors` | `String` | Insert or update vectors |
| `query(QueryOptions)` | `options` | `List<QueryResult>` | Search for similar vectors |
| `deleteVector(String id)` | `id` | `String` | Delete a vector by ID |
| `upsert(List<VectorItem>)` | `vectors` | `String` | Insert or update vectors |
| `query(QueryOptions)` | `options` | `List<QueryResult>` | Search for similar vectors |
| `updateFilters(List<UpdateFilterParams>)` | `updates` | `String` | Update filter fields on existing vectors |
| `deleteVector(String id)` | `id` | `String` | Delete a vector by ID |
| `deleteWithFilter(List<Map>)` | `filter` | `String` | Delete vectors by filter |
| `getVector(String id)` | `id` | `VectorInfo` | Get a vector by ID |
| `describe()` | - | `IndexDescription` | Get index metadata |
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.endee</groupId>
<artifactId>endee-java-client</artifactId>
<version>0.1.6-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Endee Java Client</name>
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/io/endee/client/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,43 @@ public List<QueryResult> query(QueryOptions options) {
}
}

/**
* Updates the filter fields of existing vectors without re-upserting them.
*
* @param updates list of filter updates, each containing an id and the new filter object
* @return success message
*/
public String updateFilters(List<UpdateFilterParams> updates) {
List<String> ids = updates.stream().map(UpdateFilterParams::getId).collect(Collectors.toList());
ValidationUtils.validateVectorIds(ids);

List<Map<String, Object>> payload = new ArrayList<>();
for (UpdateFilterParams update : updates) {
Map<String, Object> entry = new HashMap<>();
entry.put("id", update.getId());
entry.put("filter", update.getFilter() != null ? update.getFilter() : Map.of());
payload.add(entry);
}

try {
String jsonBody = JsonUtils.toJson(Map.of("updates", payload));
HttpRequest request = buildPostJsonRequest("/index/" + name + "/filters/update", jsonBody);
HttpResponse<String> response =
httpClient.send(request, HttpResponse.BodyHandlers.ofString());

if (response.statusCode() != 200) {
EndeeApiException.raiseException(response.statusCode(), response.body());
}

return response.body();
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw new EndeeException("Failed to update filters", e);
}
}

/**
* Deletes a vector by ID.
*
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/endee/client/types/UpdateFilterParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.endee.client.types;

import java.util.Map;

/** Parameters for updating the filter fields of an existing vector. */
public class UpdateFilterParams {
private final String id;
private final Map<String, Object> filter;

public UpdateFilterParams(String id, Map<String, Object> filter) {
this.id = id;
this.filter = filter;
}

public String getId() {
return id;
}

public Map<String, Object> getFilter() {
return filter;
}
}