Skip to content

Commit f0b8fb2

Browse files
authored
Merge pull request #9 from endee-io/dev
Dev
2 parents 7421bee + f349c42 commit f0b8fb2

4 files changed

Lines changed: 88 additions & 4 deletions

File tree

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,30 @@ You can also query with:
312312
- **Sparse only**: Provide only `sparseIndices` and `sparseValues`
313313
- **Hybrid**: Provide all three for combined results
314314

315+
## Updating Filters
316+
317+
Use `index.updateFilters()` to update the filter fields of existing vectors without re-upserting them.
318+
319+
```java
320+
import io.endee.client.types.UpdateFilterParams;
321+
import java.util.List;
322+
import java.util.Map;
323+
324+
index.updateFilters(List.of(
325+
new UpdateFilterParams("vec1", Map.of("category", "ml", "score", 95)),
326+
new UpdateFilterParams("vec2", Map.of("category", "science", "score", 80))
327+
));
328+
```
329+
330+
**`UpdateFilterParams` Fields:**
331+
332+
| Field | Required | Description |
333+
| -------- | -------- | -------------------------------------------------- |
334+
| `id` | Yes | ID of the vector to update |
335+
| `filter` | Yes | New filter object to replace the existing filter |
336+
337+
> **Note:** The entire filter object is replaced, not merged.
338+
315339
## Deletion Methods
316340

317341
### Delete by ID
@@ -522,9 +546,10 @@ public class EndeeExample {
522546

523547
| Method | Parameters | Return Type | Description |
524548
| ----------------------------- | ---------- | ------------------- | -------------------------- |
525-
| `upsert(List<VectorItem>)` | `vectors` | `String` | Insert or update vectors |
526-
| `query(QueryOptions)` | `options` | `List<QueryResult>` | Search for similar vectors |
527-
| `deleteVector(String id)` | `id` | `String` | Delete a vector by ID |
549+
| `upsert(List<VectorItem>)` | `vectors` | `String` | Insert or update vectors |
550+
| `query(QueryOptions)` | `options` | `List<QueryResult>` | Search for similar vectors |
551+
| `updateFilters(List<UpdateFilterParams>)` | `updates` | `String` | Update filter fields on existing vectors |
552+
| `deleteVector(String id)` | `id` | `String` | Delete a vector by ID |
528553
| `deleteWithFilter(List<Map>)` | `filter` | `String` | Delete vectors by filter |
529554
| `getVector(String id)` | `id` | `VectorInfo` | Get a vector by ID |
530555
| `describe()` | - | `IndexDescription` | Get index metadata |

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.endee</groupId>
88
<artifactId>endee-java-client</artifactId>
9-
<version>0.1.6-SNAPSHOT</version>
9+
<version>1.0.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Endee Java Client</name>

src/main/java/io/endee/client/Index.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,43 @@ public List<QueryResult> query(QueryOptions options) {
341341
}
342342
}
343343

344+
/**
345+
* Updates the filter fields of existing vectors without re-upserting them.
346+
*
347+
* @param updates list of filter updates, each containing an id and the new filter object
348+
* @return success message
349+
*/
350+
public String updateFilters(List<UpdateFilterParams> updates) {
351+
List<String> ids = updates.stream().map(UpdateFilterParams::getId).collect(Collectors.toList());
352+
ValidationUtils.validateVectorIds(ids);
353+
354+
List<Map<String, Object>> payload = new ArrayList<>();
355+
for (UpdateFilterParams update : updates) {
356+
Map<String, Object> entry = new HashMap<>();
357+
entry.put("id", update.getId());
358+
entry.put("filter", update.getFilter() != null ? update.getFilter() : Map.of());
359+
payload.add(entry);
360+
}
361+
362+
try {
363+
String jsonBody = JsonUtils.toJson(Map.of("updates", payload));
364+
HttpRequest request = buildPostJsonRequest("/index/" + name + "/filters/update", jsonBody);
365+
HttpResponse<String> response =
366+
httpClient.send(request, HttpResponse.BodyHandlers.ofString());
367+
368+
if (response.statusCode() != 200) {
369+
EndeeApiException.raiseException(response.statusCode(), response.body());
370+
}
371+
372+
return response.body();
373+
} catch (IOException | InterruptedException e) {
374+
if (e instanceof InterruptedException) {
375+
Thread.currentThread().interrupt();
376+
}
377+
throw new EndeeException("Failed to update filters", e);
378+
}
379+
}
380+
344381
/**
345382
* Deletes a vector by ID.
346383
*
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.endee.client.types;
2+
3+
import java.util.Map;
4+
5+
/** Parameters for updating the filter fields of an existing vector. */
6+
public class UpdateFilterParams {
7+
private final String id;
8+
private final Map<String, Object> filter;
9+
10+
public UpdateFilterParams(String id, Map<String, Object> filter) {
11+
this.id = id;
12+
this.filter = filter;
13+
}
14+
15+
public String getId() {
16+
return id;
17+
}
18+
19+
public Map<String, Object> getFilter() {
20+
return filter;
21+
}
22+
}

0 commit comments

Comments
 (0)