Skip to content

v6: Refactor REST endpoints and JSON de-/serialization #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 12, 2025
Merged

Conversation

bevzzz
Copy link
Collaborator

@bevzzz bevzzz commented Jun 10, 2025

Closes #373


tl;dr

  • io.weaviate.client6.v1.collection namespace is replaced by io.weaviate.client.v1.api.
  • io.weaviate.client6.internal namespace is replaced by io.weaviate.client.v1.internal.
  • Check JSON.java and JSONTest.java for custom de-/serialization adapters.
  • Integration test code adapted for some minor API changes, but largely unchanged.

  • Refactored HTTP-based endpoints to encapsulate request data in separate records and logic for building requests in Endpoint. This cleaned up WeaviateDataClient and WeaviateCollectionConfigClient a lot, letting these classes focus on the presenting the public API.
  • Created type adapters for classes that require custom serialization (CustomTypeAdapterFactory.INSTANCE):
    1. WeaviateObject: references (beacons) are merged with properties
    2. WeaviateCollection: references (cross-reference definitions) are merged with properties
    3. VectorIndex: encode vector index kind (hnsw/flat/dynamic) separately and let the concrete configuration be handled by default Gson adapter
    4. Vectorizer: similarly to vector index, encode vectorizer kind (module) and let the concrete configuration of each module be handled by default Gson adapter
  • Use a single static Gson instance under JSON.java -- it is thread-safe and keeps all configuration in one place.
  • Added Async counterparts for each client:
    • WeaviateClient -> WeaviateDataClient
    • WeaviateClientAsync -> WeaviateDataClientAsync

The .async() idiom for creating an async client from v5 is preserved:

// Initialize directly
try (var asyncClient = new WeaviateClientAsync(config)) { ... }

// Or create from an instance of a sync client
var syncClient = new WeaviateClient(config);
try (var asyncClient = syncClient.async()) { ... }

Async client returns CompletableFuture of whatever the sync client returns (T).
This will let users manage async calls in a familiar manner, re-using any existing "machinery" for working with completable futures they may already have.

  • Declare 3 generic parameters in WeaviateObject: P - properties, R - references, M - metadata. This allows us to re-use WeaviateObject for writing and reading objects. It might seem convoluted, but it provides a interop between different requests, e.g.:
// Fetch object
var person_1 = persons.query.byId("person-1");

// Create object
var person_2 = persons.data.insert(Map.of("name", "John Doe"));

// Use both as references
things.insert(Map.of("title", "Thing-1"), 
  thing -> thing.references(Reference.objects("hasOwner", person_1, person_2)));
  • Dropped ObjectReference(objects: List<WeaviateObject>) wrapper in favor of a simpler List<WeaviateObject> design. There is no additional information that ObjectReference can encode and it only adds layers.
  • Minor changes to gRPC response unmarshaler in QueryRequest.rpc() to reflect the new logic
  • Fixed missing default argument in Aggregation.Builder which prevented running aggregation queries without requesting any metrics.

bevzzz added 18 commits May 23, 2025 14:13
Also introduce sync/async split all the way to the root (WeaviateClient) level.
We don't want to expose it in VectorIndex.config(). It's more typing
but a cleaner logic.
- WeaviateCollectionsClient/-Async.java
- Async client available via sync_client.async()
- Use centralized JSON serializer instead of passing base Gson instance around
- Introduce REST Transport and Endpoint wrappers

Fixed 'transient' vectorizer field on BaseVectorIndex, which would previously
be ignored at deserialization. Now we manually exclude it during serialization
in VectorIndex.CustomTypeAdapterFactory.

Updated create-get-delete test in CollectionsITest.java
Update ReferencesITest.
Fix WeaviateObject serialization.
Minor improvements ( default values for list/map parameters );
Change vectorizer config param to vectorize**Class**Name
Move tests to the new location.
Otherwise serialization fails whenever no metrics are provided and List == null
@bevzzz bevzzz self-assigned this Jun 10, 2025
Copy link

@orca-security-eu orca-security-eu bot left a comment

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

@bevzzz bevzzz linked an issue Jun 11, 2025 that may be closed by this pull request
2 tasks
@bevzzz bevzzz merged commit 65c634e into v6 Jun 12, 2025
2 checks passed
@bevzzz bevzzz deleted the v6-async-rest branch June 12, 2025 11:07
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.

Async HTTP Client
1 participant