diff --git a/README.md b/README.md index de294fc28..c613ba6bf 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ -# Weaviate Java client Weaviate logo +# Weaviate Java client Weaviate logo [![Build Status](https://github.com/weaviate/java-client/actions/workflows/.github/workflows/test.yaml/badge.svg?branch=main)](https://github.com/weaviate/java-client/actions/workflows/.github/workflows/test.yaml) Official Weaviate Java Client. +> [!IMPORTANT] +> `client6` does not support many of the legacy features supported in other clients. Ensure your instance is running at least `v1.32` to avoid compatibility issues. + ## Usage To start using Weaviate Java Client add the dependency to `pom.xml`: @@ -67,6 +70,646 @@ applicationDefaultJvmArgs += listOf( ) ``` +## Supported APIs + +### Tucked Builder + +Tucked Builder is an iteration of the Builder pattern that reduces boilerplate and leverages static typing and autocompletion to help API discovery. +It is well-worth getting familiar with Tucked Builders before diving into the next sections, as the library makes intensive use of this pattern across its API surface. + +If you've worked with Elasticserch Java API Client before, you'll recognize this pattern as [Builder lamba expressions](https://www.elastic.co/docs/reference/elasticsearch/clients/java/api-conventions/building-objects#_builder_lambda_expressions). + +Most operations in Weaviate have multiple optional parameters and Builder patter is a common way to implement that. For example, here's what a nearVector query _could_ look like: + +```java +import io.weaviate.client6.v1.api.collections.query.Hybrid; +import io.weaviate.client6.v1.api.collections.query.NearText; +import io.weaviate.client6.v1.api.collections.query.NearText.Move; + +Move moveTo = Move.builder() + .force(.5f) + .concepts("lullaby") + .build(); +NearText nearText = NearText.builder() + .concepts("sunshine", "butterflies") + .distance(.4f) + .moveTo(moveTo) + .build(); +Hybrid hybridQuery = Hybrid.builder() + .concepts("rainbow") + .nearText(nearText) + .queryProperties("title", "lyrics") + .returnProperties("album", "author") + .build(); + +songs.query.hybrid(hybridQuery); +``` + +The Tucked Builder pattern replaces repetitive `.builder() [...] .build()` with a **lambda expression** which accepts the pre-instantiated builder object as its only argument. +If that's a mouthful, take a look at what the query above looks like in `client6`. After all, seeing is believing: + +```java +import io.weaviate.client6.v1.api.collections.query.NearText; + +songs.query.hybrid( + "rainbow", + /* Hybrid.Builder */ h -> h + .nearText(NearText.of( + List.of("sunshine", "butterflies"), + /* NearText.Builder */ nt -> nt + .distance(.4f) + .moveTo(.5f, /* NearText.Move.Builder */ to -> to.concepts("lullaby")) + ) + .queryProperties("title", "lyrics") + .returnProperties("album", "author") +); +``` + +Notice how the type of each lambda argument can be automatically deduced from the methods' signatures. This allows the autocomplete to correctly suggest possible arguments, guiding you through the query API. The builder itself is "tucked" in the method's internals, so you needn't remember how to access or import it. What's more, the code reads a lot more like a query thanks to improved [locality](https://htmx.org/essays/locality-of-behaviour/). As you'll see in the examples below, you can also get creative with naming the lambda argument to act as hint for future readers. + +In real-world programs there will be cases where you need to inject some control-flow statements in the query builder code. Consider an example of limiting the number of query results based on some external value, such as a URL query paramter. Lambda expressions are fully-fledged functions, so you could add a if-statement right in the middle of it: + +```java +songs.query.hybrid("rainbow", h -> { + if (limitURL != null) { + h.limit(limitURL); + } + return h; +}); +``` + +This may get out of hand quickly if complex logic is involved. Or you may simply prefer the standard Builder pattern. Whichever's the case, `client6` has got you covered. Tucked builders are public members of the classes they build, so they can be used directly. + +```java +Hybrid.Builder builder = new Hybrid.Builder("rainbow"); +if (limitURL != null) { + builder.limit(limitURL) +} + +// more complex steps... + +songs.query.hybrid(/* Hybrid */ builder.build()); +``` + +Finally, if you need to separate "query definition" from "performing the query", most objects provide two static factories: one with only the required arguments and one with the required aruments and a tucked builder. + +```java +Hybrid requiredOnly = Hybrid.of("rainbow"); +Hybrid withOptional = Hybrid.of("rainbow", opt -> opt.limit(10)); +``` + +### Connecting to a Weaviate instance + +```java +WeaviateClient client = WeaviateClient.connectToCustom( + conn -> conn + .scheme("http") + .httpPort(8080).httpHost("localhost") + .grpcPort(50051).grpcHost("localhost") + .setHeader("X-Custom-Header", "Readme") +); +``` + +Shorthand methods for connecting to a local instance and a Weaviate Cloud cluster are available too: + +```java +// Defaults to scheme=http, host=localhost, port=8080, grpcHost=locahost, grpcPort=50051 +WeaviateClient local = WeaviateClient.connectToLocal(local -> local.port(9090)); + +// Always uses httpPort=443, grpcPort=443, httpHost == gprcHost == , and API Key authentication +WeaviateClient wcd = WeaviateClient.connectToWeaviateCloud("my-cluster-url.io", "my-api-key"); +``` + +> [!TIP] +> The client holds a number of resources (HTTP connection pools, gRPC channel) which must be disposed of correclty then they are no longer needed. +> If the client's lifecycle is tied to that of your app, closing the client via `client.close()` is a good way to do that. +> +> Otherwise, use the client inside a [try-with-resources](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) statement: +> +>```java +> try (final var client = new WeaviateClient(config)) { +> // Do something with the client +> } +> ``` +> WeaviateClient will be automatically closed when execution exits the block. + +#### Authentication + +Weaviate supports several authentication methods: + +| Method | Client API reference | +| ----------------------- | --------------------------------------------------------------- | +| API Key | `Authentication.apiKey("my-api-key")` | +| Resource owner password | `Authentication.resourceOwnerPassword("username", "password")` | +| Client credentials | `Authentication.clientCredentials("clientKey", "clientSecret")` | +| Existing bearer token | `Authentication.apiKey("access-token", "refresh-token", 900)` | + +Pass the preferred authentication method as an argument to the connection builder to use it in the client: + +```java +WeaviateClient.connectToCustom( + conn -> conn.authentication(Authentication.apiKey("my-api-key") +); +``` + +Follow the [documentation](https://docs.weaviate.io/deploy/configuration/authentication) for a detailed discussion. + +### Collection management + +```java +client.collections.create( + "Songs", + collection -> collection + .properties( + Property.text("title"), + Property.text("lyrics", p -> p.tokenization(Tokenization.WORD)), + Property.integer("yearReleased"), + Property.blob("albumCover"), + Property.bool("isSingle") + ) + .references( + ReferenceProperty.to("hasAwards", "GrammyAwards", "BillboardMusicAwards") + ) + .vectorConfig( + VectorConfig.text2vecWeaviate("title_vec", t2v -> t2v.sourceProperties("title")), + VectorConfig.text2vecWeaviate("lyrics_vec", t2v -> t2v.sourceProperties("lyrics")), + VectorConfig.img2vecNeural("cover_vec", i2v -> i2v.imageFields("albumCover")) + ) +); + +assert client.collections.exists("Songs"); + +client.collections.delete("Songs"); +assert !client.collections.exists("Songs"); +``` + +Other methods in `collections` namespace include: + +- `getConfig(String collection)` to fetch collection configuration; +- `list()` to fetch collection configurations for all existing collections +- `deleteAll()` to drop all collections and their data + +#### Using a Collection Handle + +Once a collection is created, you can obtain another client object that's scoped to that collection, called a _"handle"_. + +```java +CollectionHandle> songs = client.collections.use("Songs"); +``` + +Using the handle, we can ingest new data into the collection and query it, as well as modify the configuration. +The handle object is thread safe. Although lightweight, it is best created once and shared across threads / callers. + +```java +// Bad: creates a new CollectionHandle object for each iteration, strains the GC unnecessarily. +for (var song : mySongs) { + client.collections.use("Songs").data.insert(song); +} + +// Good: the same CollectionHandle is reused across multiple iterations / processes. +var songs = client.collections.use("Songs"); +Thread.run(() -> rapSongs.forEach(song -> songs.data.insert(song))); +Thread.run(() -> popSongs.forEach(song -> songs.data.insert(song))); +``` + +For the rest of the document, assume `songs` is handle for the "Songs" collection defined elsewhere. + +#### Generic `PropertiesT` + +Weaviate client lets you insert object properties in different "shapes". The compile-time type in which the properties must be passed is determined by a generic paramter in CollectionHandle object. +By defalt, the value for this parameter is `Map`. That allows you to think of your data as JSON objects with some additional metadata (vector embedding, UUID, certainty score, etc.). + +In practice this means you'll be passing an instance of `Map` to insert a new object and receive its properties as `Map` when the collection is queried. + +If you prefer stricter typing, you can leverage our built-in ORM to work with properties as custom Java types. We will return to this in the **ORM** section later. Assume for now that properties are always being passed around as an "untyped" map. + +### Ingesting data + +Data operations are concentrated behind the `.data` namespace. + +#### Insert single object + +```java +var yellowSubmarine = songs.data.insert(Map.of( + "title", "Yellow Submarine", + "lyrics", "In the town where I was born...", + "year", 1969 +)); +System.out.println("Inserted new song at "+ yellowSubmarine.metadata().createdAt()); +System.out.println("Yellow Submarine uuid="+ yellowSubmarine.uuid()); +``` + +You can supply your own UUID and vector embedding: + +```java +songs.data.insert( + Map.of(...), + obj -> obj + .uuid("valid-custom-uuid") + .vectors(Vectors.of("title_vec", new float[]{...})) +); +``` + +#### `Vectors`? + +Weaviate supports 1-dimensional and multi-dimensional vector embeddings, thanks to ColBERT-family modules. The associated vector can be `float[] | float[][]`. +As Java does not have unions of primitive types, we define an abstraction called `Vectors` which is a container type for object's vector embeddings. + +Creating a new vector is simple: + +- `Vectors.of(new float[]{...})`: default 1-d vector +- `Vectors.of("custom_1d", new float[]{...})`: 1-d vector with a custom name +- `Vectors.of(new float[][]{...})`: default 2-d vector +- `Vectors.of("custom_2d", new float[][]{...})`: 2-d vector with a custom name +- `Vectors.of(Vectors.of(...), Vectors.of(...))`: Multiple vectors, all must define a custom name + +Here's how you can retrieve the actual vector associated with the object: + +```java +Vectors vectors = yellowSubmarine.vectors(); +float[] v = vectors.getDefaultSingle(); // default 1-dimensional vector +float[] v = vectors.getSingle("custom_1d"); // 1-d vector with a custom name +float[][] v = vectors.getDefaultMulti(); // default 2-dimensional vector +float[][] v = vectors.getMulti("custom_2d"); // 2-d vector with a custom name +``` + +#### Batch insert + +> [!NOTE] +> Support for Dynamic Batching in `client6` will be added once Server-Side Batching becomes GA in Weaviate (est. `v1.34`) + +```java +InsertManyResponse response = songs.data.insertMany( + Map.of("title", "High-Speed Dirt", "artist", "Megadeth"), + Map.of("title", "Rattlehead", "artist", "Megadeth") +); + +if (!response.errors().isEmpty()) { + throw new RuntimeException(String.join(", ", response.errors())); +} +System.out.println( + "Inserted %d objects, took: %.2fs" + .formatted(response.reponses().size(), response.took()) +); +``` + +To supply your own UUID and vector embedding when inserting multiple objects wrap each obejct in `WeaviateObject.of(...)`: + +```java +songs.data.insertMany( + WeaviateObject.of(map1, obj -> obj.uuid(uuid1)), + WeaviateObject.of(map2, obj -> obj.uuid(uuid2)) +) +``` + +### Querying data + +Query methods are concentrated behind the `.query` namespace. + +By default, _all object properties_ and its UUID are included in the response. To select a subset of properties, pass their names to `.returnProperties(...)` method on the tucked builder. Retrieve additional metadata (where relevant) like so: + +```java +// Distance and Certainty are only relevant to semantic search +q -> q.returnMetadata(Metadata.VECTOR, Metadata.DISTANCE, Metadata.CERTAINTY) + +// Score and Explain Score are only relevant to BM25 and hybrid queries +q -> q.returnMetadata(Metadata.SCORE, Metadata.EXPLAIN_SCORE) +``` + +#### Semantic search + +```java +songs.query.nearVector( + new float[]{...}, + nv -> nv.distance(.3f) +); + +songs.query.nearText( + "a song about weather", + nt -> nt.moveAway(.6f, from -> from.concepts("summertime")) +); + +songs.query.nearObject( + yellowSubmarine.uuid(), + nobj -> nobj.excludeSelf() +); + +songs.query.nearImage("base64-encoded-image"); +// Other "near-media" methods available: nearVideo, nearAudio, nearDepth, nearImu, nearThermal +``` + +> [!TIP] +> The first object returned in a NearObject query will _always_ be the search object itself. To filter it out, use the `.excludeSelf()` helper as in the example above. + +#### Keyword and Hybrid search + +```java +songs.query.bm25( + "rain", + bm25 -> bm25.queryProeperties("lyrics") +); + +songs.query.hybrid( + "rain", + h -> h + .queryProperties("lyrics") + .nearVector(NearVector.of(new float[]{...})) +); +``` + +#### Filtering + +Objects can be filtered by property or reference values. In the latter case you need to pass the "path" to the property in the referenced collection. + +```java +.where(Where.property("year").gte(1969)) +.where(Where.reference("hasAwards", "GrammyAwards", "category").eq("New Artist")) +``` + +Supported **comparison operators**: + +- Equal: `.eq` +- NotEqual: `.ne` +- LessThan: `.lt` +- LessThanEqual: `.lte` +- GreaterThan: `.gt` +- GreaterThanEqual: `.gte` +- Like: `.like` +- ContainsAll: `.containsAll` +- ContainsAny: `.containsAny` +- ContainsNone: `.containsNone` +- WithinGeoRange: `.withinGeoRange` + +Comparison operators can be grouped using **logical operators** with arbitrarily deep nesting. + +```java +.where( + Where.or( + Where.and( + Where.property("year").gt(2000), + Where.property("year").lt(2017) + ), + Where.or( + Where.property("artist").like("Boys"), + Where.property("genres").containsAny("#rock", "#rocknroll", "#grunge") + ) + ) +) +``` + +Supported **logical operators**: + +- And: `.and` +- Or: `.or` +- Not: `.not` + +Operators passed in subsequent calls to `.where` are concatenated with the `.and` operartor. +These 3 calls are equivalent: + +```java +.where(Where.and(cond1, cond2)) +.where(cond1, cond2) +.where(cond1).where(cond2) +``` + +To negate an operator, wrap it in `Where.not(...)` or use the negation shorthand. + +```java +Where.not(Where.property("title").like("summer")); +Where.property("title").like("summer").not(); +``` + +Passing `null` and and empty `Where[]` to any of the logical operators as well as to the `.where()` method is safe -- the empty operators will simply be ignored. + +#### Grouping results + +Every query above has an overloaded variant that accepts a group-by clause. + +```java +// Required arguments + GroupBy +songs.query.nearVector( + new float[]{...}, + GroupBy.property("artist", 10, 100) +); + +// Required argument, optional parameters, GroupBy +songs.query.bm25( + "rain", + bm25 -> bm25.queryProperties("lyrics"), + GroupBy.property("artist", 10, 100) +); +``` + +The shape of the response object is different too, see [`QueryResponseGrouped`](./src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGrouped.java). + +### Pagination + +Paginating a Weaviate collection is straighforward and its API should is instantly familiar. `CursorSpliterator` powers 2 patterns for iterating over objects: + +- the default Paginator object returned by `collection.paginate()` implements Iterable that can be used in a traditional for-loop +- `.stream()` presents the internal Spliterator via an idiomatic Stream API + +```java +var allSongs = songs.paginate(); + +for (WeaviateObject song : allSongs) { + // Traditional for-loop +} + +// Stream API +var allSongUUIDs = allSongs.stream().map(WeaviateObject::uuid).toList(); +``` + +Paginator can be configured to return a subset of properties / metadata fields, use a different page size (defaults to 100) or resume iteration from an arbitrary object. + +```java +// Create a paginator +var allSongs = things.paginate( + p -> p + .pageSize(500) + .resumeFrom("uuid-3") + .returnProperties("artist", "album") + .returnMetadata(Metadata.VECTOR)); + +// Process data +allSongs.stream().toList(); +``` + +### Aggregating data + +```java +songs.aggregate.overAll( + with -> with + .metrics( + Aggregate.integer("year", calc -> calc.min().max().median()), + Aggregate.text("album", calc -> calc.topOccurrences().topOccurencesCutoff(5)), + Aggregate.bool("isSingle", calc -> calc.percentageTrue().totalFalse()), + Aggregate.number("monthlyListeners", calc -> calc.mode().count()) + ) + .includeTotalCount(true) +) +``` + +#### Filtered aggregations + +To perform aggregations over query results, use one of the other method under the `aggregate` namespace: it has the same set of methods as the `query` namespace, with the exception of `.bm25(...)`, which cannot be used as an aggregation filter. + +```java +songs.aggregate.hybrid( + "summer of love", + hybrid -> hybrid + .queryProperties("title", "lyrics") + .nearVector(NearVector.of( + new float[]{...}, + nv -> nv.certainty(.7f) + ) + .alpha(.3f), + aggregate -> aggregate + .metrics( + Aggregate.text("artist", calc -> calc.topOccurrences()) + ) +); +``` + +Similartly, an overload with another parameter for a group-by clause is available: + +```java +songs.aggregate.nearObject( + yellowSubmarine.uuid(), + nearObject -> nearObject.excludeSelf(), + aggregate -> aggregate.metrics( + Aggregate.text("album", calc -> calc.topOccurrences()) + ), + GroupBy.property("year") +); +``` + +#### Counting collection objects + +To query the total object count in a collection use `songs.size()` shorthand. + + +### Error handling + +The client throws exceptions extending `WeaviateException`, which can be used as a catch-all case for any package-related exceptions. Other exception types, such as `IOException` which may be thrown by the underlying HTTP / gRPC libraries are allowed to propagate, as they usually signal different kinds of errors: malformed URL, network problems, etc. + +> [!WARNING] +> `WeaviateException` is an **unchecked exception**. + +```java +try (final var client = WeaviateClient.connectToLocal()) { + // Make some requests +} catch (WeaviateException | IOException e) { + e.printStackTrace(); +} +``` + +Concrete exception types: + +- `WeaviateApiException` - Bad request. +- `PaginationException` - Wrapper exception with pagination details (page size, last cursor UUID) +- `WeaviateConnectException` - Weaviate instance not available, failed to connect. +- `WeaviateOAuthException` - Error during OAuth credentials exchange. +- `WeaviateTransportException` - Internal transport layer exception. + + +### ORM + +Weaviate client comes with a minimal ORM, which lets you serialize and deserialize object properties into Java **records**. Moreover, the client can create a collection based on the record's declared fields. +The "Songs" collection that we've been working with so far may look somethins like this: + + +```java +import io.weaviate.client6.v1.api.collections.annotations.Collection; +import io.weaviate.client6.v1.api.collections.annotations.Property; + +@Collection("Songs", description = "Global media library") +record Song( + String title, + String lyrics, + @Property("artist") String singer, + int year, + String[] genres +) {} +``` + +By default, the class and field names map to the collection and property names respectively. The `@Collection` and `@Property` annotations can be used to override those defaults. + +To create the collection, pass the class definition to `.create`. + +```java +client.collections.create( + Song.class, + collection -> collection + .references(...) + .vectorConfig(...); +``` + +Ingestion and search work the same way, but will accept / return `Song.class` instances instead of `Map`. + +```java +Song bad = new Song("Bad", "...", "Michael Jackson", 1987, ...); +Song badGuy = new Song("Bad Guy", "...", "Billie Eilish", 2019, ...); +Song crown = new Song("You Should See Me in a Crown", "...", "Billie Eilish", 2019, ...); + +songs.data.insert(bad); +songs.data.insertMany(badGuy, crown); + +var result = songs.query.bm25( + "bad", + opt -> opt + .queryProperties("lyrics") + .returnProperties("artist") +); + +for (var object : result.objects()) { + Song song = object.properties(); + System.out.println(song.artist()); +} +``` + +We want to stress that this ORM's focus is on improving type-safety around object properties and simplifying serialization/deserialization. It is intentionally kept minimal and as such has the following limitations: + +- **Does not support BLOB properties.** On the wire, blob properties are represented as base64-encoded strings, and both logically map to the Java's `String`. Presently there isn't a good way for the client to deduce which property type should be created, so it always maps `Sting -> TEXT`. +- **Limited configuration options.** Vector indices, replication, multi-tenancy, and such need to be configured via a tucked builder in `.create(..., here -> here)`. +- **Does not support cross-references.** Properties and Cross-References are conceptually and "physically" separated in Weaviate' client libraries, so doing something like in the snippet below is not supported. + +```java +record Artist(String firstName, String lastName, int age) {}; + +record Song(String title, Artist artist) {}; + +var song1 = songs.query.byId( + uuid1, + song -> song.returnReferences(QueryReference.single("artist")) +); +System.out.println( + "Artist's last name is: " + + song1.properties().artist().lastName() +); +``` + +Instead you'd work with cross-references same way as without the ORM: + +```java +System.out.println( + "Artist's last name is: " + + song1.references().get("artist").properties().get("lastName") +); +``` + +Some of these features may be added in future releases. + +### Collection alias + +```java +client.collections.alias("RapSongs", "Songs_Alias"); +client.collections.list(only -> only.collection("RapSongs")); +client.collections.get("Songs_Alias"); +client.collections.update("Songs_Alias", "PopSongs"); +client.collections.delete("Songs_Alias"); +``` + ## Useful resources - [Documentation](https://weaviate.io/developers/weaviate/current/client-libraries/java.html). diff --git a/assets/duke-client6.png b/assets/duke-client6.png new file mode 100644 index 000000000..f6974dfd3 Binary files /dev/null and b/assets/duke-client6.png differ diff --git a/src/main/java/io/weaviate/client6/v1/api/WeaviateApiException.java b/src/main/java/io/weaviate/client6/v1/api/WeaviateApiException.java index e91bc1265..ee029da54 100644 --- a/src/main/java/io/weaviate/client6/v1/api/WeaviateApiException.java +++ b/src/main/java/io/weaviate/client6/v1/api/WeaviateApiException.java @@ -43,27 +43,37 @@ private WeaviateApiException(String method, String endpoint, int statusCode, Str this.grpcStatusCode = null; } + /** Get raw error message. */ + public String getError() { + return errorMessage; + } + + /** Check if the exception originates from the gRPC transport. */ public boolean isGPRC() { return source == Source.GRPC; } + /** Get the gRPC status code. */ public String grpcStatusCode() { + if (!isGPRC()) { + return null; + } return grpcStatusCode.toString(); } + /** Check if the exception originates from the HTTP transport. */ public boolean isHTTP() { return source == Source.HTTP; } + /** Get the endpoint that the failed request was sent to. */ public String endpoint() { return endpoint; } + /** Get the HTTP status code. */ public Integer httpStatusCode() { return httpStatusCode; } - public String getError() { - return errorMessage; - } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java index 581c357ee..634bd9713 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java @@ -23,16 +23,27 @@ import io.weaviate.client6.v1.internal.ObjectBuilder; public record CollectionConfig( + /** Collection name. */ @SerializedName("class") String collectionName, + /** Collection description. */ @SerializedName("description") String description, + /** Collection properties. */ @SerializedName("properties") List properties, + /** Cross-reference properties. */ List references, + /** Vector indexes configured for this collection. */ @SerializedName("vectorConfig") Map vectors, + /** Multi-tenantcy options. */ @SerializedName("multiTenancyConfig") MultiTenancy multiTenancy, + /** Sharding configuration. */ @SerializedName("shardingConfig") Sharding sharding, + /** Replication configuration. */ @SerializedName("replicationConfig") Replication replication, + /** Inverted index configuration. */ @SerializedName("invertedIndexConfig") InvertedIndex invertedIndex, + /** Reranker modules. */ List rerankerModules, + /** Generative modules. */ Generative generativeModule) { public static CollectionConfig of(String collectionName) { @@ -100,15 +111,26 @@ public Builder(String collectionName) { this.collectionName = collectionName; } + /** Add collection description. */ public Builder description(String description) { this.description = description; return this; } + /** + * Add collection properties. + * + * @see Property + */ public Builder properties(Property... properties) { return properties(Arrays.asList(properties)); } + /** + * Add collection properties. + * + * @see Property + */ public Builder properties(List properties) { properties.forEach(property -> this.properties.put(property.propertyName(), property)); return this; @@ -118,10 +140,20 @@ private List propertyList() { return this.properties.values().stream().toList(); } + /** + * Add cross-reference properties. + * + * @see ReferenceProperty#to + */ public Builder references(ReferenceProperty... references) { return references(Arrays.asList(references)); } + /** + * Add cross-reference properties. + * + * @see ReferenceProperty#to + */ public Builder references(List references) { references.forEach(reference -> this.references.put(reference.propertyName(), reference)); return this; @@ -131,66 +163,83 @@ private List referenceList() { return this.references.values().stream().toList(); } + /** Add vector index configurations. */ public final Builder vectorConfig(Map vectors) { this.vectors.putAll(vectors); return this; } + /** + * Add vector index configurations. + * + * @see VectorConfig + */ @SafeVarargs public final Builder vectorConfig(Map.Entry... vectors) { this.vectors.putAll(Map.ofEntries(vectors)); return this; } + /** Configure collection's sharding. */ public Builder sharding(Sharding sharding) { this.sharding = sharding; return this; } + /** Configure collection's sharding. */ public Builder sharding(Function> fn) { this.sharding = Sharding.of(fn); return this; } + /** Configure multi-tenancy. */ public Builder multiTenancy(MultiTenancy multiTenancy) { this.multiTenancy = multiTenancy; return this; } + /** Configure multi-tenancy. */ public Builder multiTenancy(Function> fn) { this.multiTenancy = MultiTenancy.of(fn); return this; } + /** Configure replication. */ public Builder replication(Replication replication) { this.replication = replication; return this; } + /** Configure replication. */ public Builder replication(Function> fn) { this.replication = Replication.of(fn); return this; } + /** Change inverted index configurations. */ public Builder invertedIndex(InvertedIndex invertedIndex) { this.invertedIndex = invertedIndex; return this; } + /** Change inverted index configurations. */ public Builder invertedIndex(Function> fn) { this.invertedIndex = InvertedIndex.of(fn); return this; } + /** Add reranker modules. */ public Builder rerankerModules(Reranker... rerankerModules) { return rerankerModules(Arrays.asList(rerankerModules)); } + /** Add reranker modules. */ public Builder rerankerModules(List rerankerModules) { this.rerankerModules.addAll(rerankerModules); return this; } + /** Add a generative module. */ public Builder generativeModule(Generative generativeModule) { this.generativeModule = generativeModule; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandle.java b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandle.java index 3a1b35038..08f41eca3 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandle.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandle.java @@ -49,10 +49,39 @@ private CollectionHandle(CollectionHandle c, CollectionHandleDefaul this.tenants = c.tenants; } + /** + * Create a Paginator over the objects in this collection. + * + *

+ * Usage: + * + *

+   * {@code
+   * var things = client.collections.use("Things");
+   *
+   * // In a for-loop:
+   * for (final var thing : things.paginate()) {
+   *   // ... do something for each Thing object
+   * }
+   *
+   * // As a stream
+   * things.paginate().stream()
+   *  .map(...)
+   *  .collect(...);
+   * }
+ * + * @return An {@link Iterable} over this collection's objects. + */ public Paginator paginate() { return Paginator.of(this.query); } + /** + * Create a Paginator over the objects in this collection. + * + * @param fn Lambda expression for optional parameters. + * @return An {@link Iterable} over this collection's objects. + */ public Paginator paginate( Function, ObjectBuilder>> fn) { return Paginator.of(this.query, fn); @@ -68,7 +97,7 @@ public Paginator paginate( * collection exceeds {@link Long#MAX_VALUE} as this is unlikely to happen. * *

- * This is a shortcut for: + * This is a shorthand for: * *

{@code
    * handle.aggregate.overAll(all -> all.includeTotalCount(true)).totalCount()
@@ -78,22 +107,30 @@ public long size() {
     return this.aggregate.overAll(all -> all.includeTotalCount(true)).totalCount();
   }
 
+  /** Default consistency level for requests. */
   public ConsistencyLevel consistencyLevel() {
     return defaults.consistencyLevel();
   }
 
+  /** Obtain a collection handle with a different consistency level. */
   public CollectionHandle withConsistencyLevel(ConsistencyLevel consistencyLevel) {
     return new CollectionHandle<>(this, CollectionHandleDefaults.of(with -> with.consistencyLevel(consistencyLevel)));
   }
 
+  /** Default tenant for requests. */
   public String tenant() {
     return defaults.tenant();
   }
 
+  /** Obtain a collection handle with a different target tenant. */
   public CollectionHandle withTenant(String tenant) {
     return new CollectionHandle<>(this, CollectionHandleDefaults.of(with -> with.tenant(tenant)));
   }
 
+  /**
+   * Obtain a collection handle with different defaults
+   * (consistency level / tenant).
+   */
   public CollectionHandle withDefaults(
       Function> fn) {
     return new CollectionHandle<>(this, CollectionHandleDefaults.of(fn));
diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java
index 1fdb73a35..5e8196dd2 100644
--- a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java
+++ b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java
@@ -85,23 +85,31 @@ public CompletableFuture size() {
         .thenApply(AggregateResponse::totalCount);
   }
 
+  /** Default consistency level for requests. */
   public ConsistencyLevel consistencyLevel() {
     return defaults.consistencyLevel();
   }
 
+  /** Obtain a collection handle with a different consistency level. */
   public CollectionHandleAsync withConsistencyLevel(ConsistencyLevel consistencyLevel) {
     return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(
         def -> def.consistencyLevel(consistencyLevel)));
   }
 
+  /** Default tenant for requests. */
   public String tenant() {
     return defaults.tenant();
   }
 
+  /** Obtain a collection handle with a different target tenant. */
   public CollectionHandleAsync withTenant(String tenant) {
     return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(with -> with.tenant(tenant)));
   }
 
+  /**
+   * Obtain a collection handle with different defaults
+   * (consistency level / tenant).
+   */
   public CollectionHandleAsync withDefaults(
       Function> fn) {
     return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(fn));
diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleDefaults.java b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleDefaults.java
index 7ce9711ba..c7952222a 100644
--- a/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleDefaults.java
+++ b/src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleDefaults.java
@@ -54,6 +54,7 @@ public CollectionHandleDefaults build() {
     }
   }
 
+  /** Serialize default values to a URL query. */
   public Map queryParameters() {
     if (consistencyLevel == null && tenant == null) {
       return Collections.emptyMap();
diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/DataType.java b/src/main/java/io/weaviate/client6/v1/api/collections/DataType.java
index 32858bca6..91584a797 100644
--- a/src/main/java/io/weaviate/client6/v1/api/collections/DataType.java
+++ b/src/main/java/io/weaviate/client6/v1/api/collections/DataType.java
@@ -19,6 +19,17 @@ public interface DataType {
   public static final String UUID = "uuid";
   public static final String UUID_ARRAY = "uuid[]";
 
+  /**
+   * Scalar/array types which Weaviate and WeaviateClient recognize.
+   *
+   * 

+ * Other data types are considered reference types, i.e. if a user creates a + * property with type {@code "timestamp"}, the client will count it a + * cross-reference to the {@code "timestamp"} collection. + * + * This is obviously wrong, so it is recommended to always create properties + * using {@link Property}'s factory classes. + */ public static final Set KNOWN_TYPES = ImmutableSet.of( TEXT, INT, BLOB, BOOL, DATE, UUID, NUMBER, TEXT_ARRAY, INT_ARRAY, NUMBER_ARRAY, BOOL_ARRAY, DATE_ARRAY, UUID_ARRAY); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/Generative.java b/src/main/java/io/weaviate/client6/v1/api/collections/Generative.java index 2354d5b7a..632713cdd 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/Generative.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/Generative.java @@ -42,10 +42,16 @@ public static Kind valueOfJson(String jsonValue) { Object _self(); + /** Configure a default Cohere generative module. */ public static Generative cohere() { return CohereGenerative.of(); } + /** + * Configure a Cohere generative module. + * + * @param fn Lambda expression for optional parameters. + */ public static Generative cohere(Function> fn) { return CohereGenerative.of(fn); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/InvertedIndex.java b/src/main/java/io/weaviate/client6/v1/api/collections/InvertedIndex.java index 2edb99043..ad2fc17f6 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/InvertedIndex.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/InvertedIndex.java @@ -9,12 +9,28 @@ import io.weaviate.client6.v1.internal.ObjectBuilder; public record InvertedIndex( + /** The frequency of cleanup operations in the HNSW vector index. */ @SerializedName("cleanupIntervalSeconds") Integer cleanupIntervalSeconds, + /** Parameters for BM25 ranking algorithm. */ @SerializedName("bm25") Bm25 bm25, + /** Common words which should be ignored in queries. */ @SerializedName("stopwords") Stopwords stopwords, + /** + * If true, indexes object creation and update timestamps, + * enabling filtering by creationTimeUnix and lastUpdateTimeUnix. + */ @SerializedName("indexTimestamps") Boolean indexTimestamps, + /** + * If true, indexes the null/non-null state of each property, + * enabling filtering for null values. + */ @SerializedName("indexNullState") Boolean indexNulls, + /** + * If true, indexes the length of each property, + * enabling filtering by property length. + */ @SerializedName("indexPropertyLength") Boolean indexPropertyLength, + /** If true, BlockMaxWAND optimization is used. */ @SerializedName("usingBlockMaxWAND") Boolean useBlockMaxWAND) { public static InvertedIndex of(Function> fn) { @@ -22,7 +38,9 @@ public static InvertedIndex of(Function> f } public record Bm25( + /** Free parameter for the BM25 ranking function. */ @SerializedName("b") Float b, + /** Free parameter for the BM25 ranking function. */ @SerializedName("k1") Float k1) { public static Bm25 of(Function> fn) { @@ -37,11 +55,13 @@ public static class Builder implements ObjectBuilder { private Float b; private Float k1; + /** Set free parameter {@code b} for the BM25 ranking function. */ public Builder b(float b) { this.b = b; return this; } + /** Set free parameter {@code k1} for the BM25 ranking function. */ public Builder k1(float k1) { this.k1 = k1; return this; @@ -55,8 +75,11 @@ public Bm25 build() { } public record Stopwords( + /** Selected preset. */ @SerializedName("preset") String preset, + /** Custom words added to the selected preset. */ @SerializedName("additions") List additions, + /** Words removed from the selected preset. */ @SerializedName("removals") List removals) { public static Stopwords of(Function> fn) { @@ -72,24 +95,29 @@ public static class Builder implements ObjectBuilder { private List additions; private List removals; + /** Select a preset to use for a particular language. */ public Builder preset(String preset) { this.preset = preset; return this; } + /** Add words to the selected preset. */ public Builder add(String... additions) { return add(Arrays.asList(additions)); } + /** Add words to the selected preset. */ public Builder add(List additions) { this.additions.addAll(additions); return this; } + /** Remove words from the selected preset. */ public Builder remove(String... removals) { return remove(Arrays.asList(removals)); } + /** Remove words from the selected preset. */ public Builder remove(List removals) { this.removals.addAll(removals); return this; @@ -122,37 +150,59 @@ public static class Builder implements ObjectBuilder { private Boolean indexPropertyLength; private Boolean useBlockMaxWAND; + /** Set the frequency of cleanup operations in the HNSW vector index. */ public Builder cleanupIntervalSeconds(int cleanupIntervalSeconds) { this.cleanupIntervalSeconds = cleanupIntervalSeconds; return this; } + /** Set {@code b} and {@code k1} parameters for BM25 ranking algorithm. */ public Builder bm25(Function> fn) { this.bm25 = Bm25.of(fn); return this; } + /** Select and configure a stopwords preset. */ public Builder stopwords(Function> fn) { this.stopwords = Stopwords.of(fn); return this; } - public Builder indexTimestamps(Boolean indexTimestamps) { + /** + * Enable / disable creating an index for creation / update timestamps. + * + * @see InvertedIndex#indexTimestamps + */ + public Builder indexTimestamps(boolean indexTimestamps) { this.indexTimestamps = indexTimestamps; return this; } - public Builder indexNulls(Boolean indexNulls) { + /** + * Enable / disable creating an index for null property values. + * + * @see InvertedIndex#indexNulls + */ + public Builder indexNulls(boolean indexNulls) { this.indexNulls = indexNulls; return this; } - public Builder indexPropertyLength(Boolean indexPropertyLength) { + /** + * Enable / disable creating an index for property lengths. + * + * @see InvertedIndex#indexPropertyLength + */ + public Builder indexPropertyLength(boolean indexPropertyLength) { this.indexPropertyLength = indexPropertyLength; return this; } - public Builder useBlockMaxWAND(Boolean useBlockMaxWAND) { + /** + * If true, indexes object creation and update timestamps, + * enabling filtering by creationTimeUnix and lastUpdateTimeUnix. + */ + public Builder useBlockMaxWAND(boolean useBlockMaxWAND) { this.useBlockMaxWAND = useBlockMaxWAND; return this; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/MultiTenancy.java b/src/main/java/io/weaviate/client6/v1/api/collections/MultiTenancy.java index 9524a1f05..11227eeea 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/MultiTenancy.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/MultiTenancy.java @@ -7,8 +7,11 @@ import io.weaviate.client6.v1.internal.ObjectBuilder; public record MultiTenancy( + /** Is multi-tenancy enabled for this collection. */ @SerializedName("enabled") boolean enabled, + /** Is auto tenant creation enabled for this collection. */ @SerializedName("autoTenantCreation") Boolean createAutomatically, + /** Is auto tenant activation enabled for this collection. */ @SerializedName("autoTenantActivation") Boolean activateAutomatically) { public static MultiTenancy of(Function> fn) { @@ -27,16 +30,19 @@ public static class Builder implements ObjectBuilder { private Boolean createAutomatically; private Boolean activateAutomatically; + /** Enable / disable multi-tenancy for this collection. */ public Builder enabled(boolean enabled) { this.enabled = enabled; return this; } + /** Enable / disable auto tenant creation. */ public Builder autoTenantCreation(boolean enabled) { this.createAutomatically = enabled; return this; } + /** Enable / disable auto tenant activation. */ public Builder autoTenantActivation(boolean enabled) { this.activateAutomatically = enabled; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/Quantization.java b/src/main/java/io/weaviate/client6/v1/api/collections/Quantization.java index 64c4ec022..b17b11441 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/Quantization.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/Quantization.java @@ -51,38 +51,63 @@ public static Kind valueOfJson(String jsonValue) { Object _self(); + /** Disable any quantization for this collection. */ public static Quantization uncompressed() { return Uncompressed.of(); } + /** Enable binary quantization for this collection. */ public static Quantization bq() { return BQ.of(); } + /** + * Enable binary quantization for this collection. + * + * @param fn Lambda expression for optional parameters. + */ public static Quantization bq(Function> fn) { return BQ.of(fn); } + /** Enable product quantization for this collection. */ public static Quantization pq() { return PQ.of(); } + /** + * Enable product quantization for this collection. + * + * @param fn Lambda expression for optional parameters. + */ public static Quantization pq(Function> fn) { return PQ.of(fn); } + /** Enable scalar quantization for this collection. */ public static Quantization sq() { return SQ.of(); } + /** + * Enable scalar quantization for this collection. + * + * @param fn Lambda expression for optional parameters. + */ public static Quantization sq(Function> fn) { return SQ.of(fn); } + /** Enable rotational quantization for this collection. */ public static Quantization rq() { return RQ.of(); } + /** + * Enable rotational quantization for this collection. + * + * @param fn Lambda expression for optional parameters. + */ public static Quantization rq(Function> fn) { return RQ.of(fn); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/ReferenceProperty.java b/src/main/java/io/weaviate/client6/v1/api/collections/ReferenceProperty.java index 38716f782..7b3d37703 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/ReferenceProperty.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/ReferenceProperty.java @@ -44,6 +44,7 @@ public static ReferenceProperty to(String name, List collections) { return new ReferenceProperty(name, collections); } + /** This method is intended for client's internal use only. */ public Property toProperty() { return new Property.Builder(propertyName, dataTypes).build(); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/Replication.java b/src/main/java/io/weaviate/client6/v1/api/collections/Replication.java index 2b175bae5..a01af272c 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/Replication.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/Replication.java @@ -36,16 +36,22 @@ public static class Builder implements ObjectBuilder { private Boolean asyncEnabled; private DeletionStrategy deletionStrategy; + /** Set desired replication factor for this collection. */ public Builder replicationFactor(int replicationFactor) { this.replicationFactor = replicationFactor; return this; } + /** Enable / disable async replication. */ public Builder asyncEnabled(boolean asyncEnabled) { this.asyncEnabled = asyncEnabled; return this; } + /** + * Select the deletion strategy for resolving conflicts + * during async replication. + */ public Builder deletionStrategy(DeletionStrategy deletionStrategy) { this.deletionStrategy = deletionStrategy; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/Reranker.java b/src/main/java/io/weaviate/client6/v1/api/collections/Reranker.java index fb473b40c..08b6aeb82 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/Reranker.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/Reranker.java @@ -42,10 +42,16 @@ public static Kind valueOfJson(String jsonValue) { Object _self(); + /** Configure a default Cohere reranker module. */ public static Reranker cohere() { return CohereReranker.of(); } + /** + * Configure a Cohere reranker module. + * + * @param fn Lambda expression for optional parameters. + */ public static Reranker cohere(Function> fn) { return CohereReranker.of(fn); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/VectorConfig.java b/src/main/java/io/weaviate/client6/v1/api/collections/VectorConfig.java index 1e8cd96d5..ae13f70ce 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/VectorConfig.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/VectorConfig.java @@ -52,8 +52,10 @@ public static Kind valueOfJson(String jsonValue) { Object _self(); + /** Get vector index configuration for this vector. */ VectorIndex vectorIndex(); + /** Get quantization configuration for this vector. */ Quantization quantization(); /** Create a bring-your-own-vector vector index. */ diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java b/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java index 4da02656c..51096f639 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java @@ -45,10 +45,12 @@ public static Kind valueOfJson(String jsonValue) { VectorIndex.Kind _kind(); + /** Returns the on-the-wire name of the vector index type. */ default String type() { return _kind().jsonValue(); } + /** Get the concrete vector index configuration object. */ Object config(); public static enum CustomTypeAdapterFactory implements TypeAdapterFactory { diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClient.java index 2bcb3071d..b662dbd61 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClient.java @@ -224,6 +224,20 @@ public void delete(String collectionName) throws IOException { this.restTransport.performRequest(new DeleteCollectionRequest(collectionName), DeleteCollectionRequest._ENDPOINT); } + /** + * Delete a Weaviate collection. + * + * @param cls Class that represents an object in the collection. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ + public void delete(Class cls) throws IOException { + delete(CollectionDescriptor.ofClass(cls).collectionName()); + } + /** * Delete all collections in Weaviate. * @@ -252,4 +266,18 @@ public void deleteAll() throws IOException { public boolean exists(String collectionName) throws IOException { return getConfig(collectionName).isPresent(); } + + /** + * Check if a collection with this name exists. + * + * @param cls Class that represents an object in the collection. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ + public boolean exists(Class cls) throws IOException { + return exists(CollectionDescriptor.ofClass(cls).collectionName()); + } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java index e7e4755b3..8f5c3516c 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateCollectionsClientAsync.java @@ -173,6 +173,15 @@ public CompletableFuture delete(String collectionName) { DeleteCollectionRequest._ENDPOINT); } + /** + * Delete a Weaviate collection. + * + * @param cls Class that represents an object in the collection. + */ + public CompletableFuture delete(Class cls) { + return delete(CollectionDescriptor.ofClass(cls).collectionName()); + } + /** * Delete all collections in Weaviate. */ @@ -193,4 +202,13 @@ public CompletableFuture deleteAll() throws IOException { public CompletableFuture exists(String collectionName) { return getConfig(collectionName).thenApply(Optional::isPresent); } + + /** + * Check if a collection with this name exists. + * + * @param cls Class that represents an object in the collection. + */ + public CompletableFuture exists(Class cls) { + return exists(CollectionDescriptor.ofClass(cls).collectionName()); + } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java index 9121e33c3..a4b8cc05a 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java @@ -1,7 +1,9 @@ package io.weaviate.client6.v1.api.collections; public interface WeaviateMetadata { + /** Object's UUID. */ String uuid(); + /** Object's associated vector embeddings. */ Vectors vectors(); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java index c96b22916..3180cf2e7 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java @@ -43,20 +43,22 @@ public static WeaviateObject of( } public WeaviateObject(Builder builder) { - this(builder.collection, builder.properties, builder.references, builder.metadata); + this(builder.collectionName, builder.properties, builder.references, builder.metadata); } public static class Builder implements ObjectBuilder> { - private String collection; + private String collectionName; private P properties; private Map> references = new HashMap<>(); private M metadata; - public final Builder collection(String collection) { - this.collection = collection; + /** Set the name of the collection his object belongs to. */ + public final Builder collection(String collectionName) { + this.collectionName = collectionName; return this; } + /** Add object properties. */ public final Builder properties(P properties) { this.properties = properties; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/aggregate/AbstractAggregateClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/aggregate/AbstractAggregateClient.java index 6c6db167b..c082ff70a 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/aggregate/AbstractAggregateClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/aggregate/AbstractAggregateClient.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.function.Function; +import io.weaviate.client6.v1.api.WeaviateApiException; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.query.Hybrid; import io.weaviate.client6.v1.api.collections.query.NearAudio; @@ -44,39 +45,139 @@ abstract class AbstractAggregateClient { // OverAll ------------------------------------------------------------------ + /** + * Aggregate metrics over all objects in this collection. + * + * @param fn Lambda expression for optional parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT overAll(Function> fn) { return performRequest(Aggregation.of(fn)); } + /** + * Aggregate metrics over all objects in this collection. + * + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT overAll(Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(fn), groupBy); } // Hybrid ------------------------------------------------------------------- + /** + * Aggregate results of a hybrid search query. + * + * @param query Query string. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT hybrid(String query, Function> fn) { return hybrid(Hybrid.of(query), fn); } - public ResponseT hybrid(String query, Function> nv, + /** + * Aggregate results of a hybrid search query. + * + * @param query Query string. + * @param hybrid Lambda expression for optional hybrid search parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ + public ResponseT hybrid(String query, Function> hybrid, Function> fn) { - return hybrid(Hybrid.of(query, nv), fn); - } - + return hybrid(Hybrid.of(query, hybrid), fn); + } + + /** + * Aggregate results of a hybrid search query. + * + * @param filter Hybrid query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT hybrid(Hybrid filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a hybrid search query. + * + * @param query Query string. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT hybrid(String query, Function> fn, GroupBy groupBy) { return hybrid(Hybrid.of(query), fn, groupBy); } - public GroupedResponseT hybrid(String query, Function> nv, + /** + * Aggregate results of a hybrid search query. + * + * @param query Query string. + * @param hybrid Lambda expression for optional hybrid search parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ + public GroupedResponseT hybrid(String query, Function> hybrid, Function> fn, GroupBy groupBy) { - return hybrid(Hybrid.of(query, nv), fn, groupBy); - } - + return hybrid(Hybrid.of(query, hybrid), fn, groupBy); + } + + /** + * Aggregate results of a hybrid search query. + * + * @param filter Hybrid query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT hybrid(Hybrid filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -84,29 +185,106 @@ public GroupedResponseT hybrid(Hybrid filter, Function> fn) { return nearVector(NearVector.of(vector), fn); } + /** + * Aggregate results of a near vector query. + * + * @param vector Query vector. + * @param nv Lambda expression for optional near vector parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearVector(float[] vector, Function> nv, Function> fn) { return nearVector(NearVector.of(vector, nv), fn); } + /** + * Aggregate results of a near vector query. + * + * @param filter Near vector query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearVector(NearVector filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near vector query. + * + * @param vector Query vector. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearVector(float[] vector, Function> fn, GroupBy groupBy) { return nearVector(NearVector.of(vector), fn, groupBy); } + /** + * Aggregate results of a near vector query. + * + * @param vector Query vector. + * @param nv Lambda expression for optional near vector parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearVector(float[] vector, Function> nv, Function> fn, GroupBy groupBy) { return nearVector(NearVector.of(vector, nv), fn, groupBy); } + /** + * Aggregate results of a near vector query. + * + * @param filter Near vector query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearVector(NearVector filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -114,29 +292,106 @@ public GroupedResponseT nearVector(NearVector filter, Function> fn) { return nearObject(NearObject.of(uuid), fn); } - public ResponseT nearObject(String uuid, Function> nv, + /** + * Aggregate results of a near object query. + * + * @param uuid Query object UUID. + * @param nobj Lambda expression for optional near object parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ + public ResponseT nearObject(String uuid, Function> nobj, Function> fn) { - return nearObject(NearObject.of(uuid, nv), fn); - } - + return nearObject(NearObject.of(uuid, nobj), fn); + } + + /** + * Aggregate results of a near object query. + * + * @param filter Near object query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearObject(NearObject filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near object query. + * + * @param uuid Query object UUID. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearObject(String uuid, Function> fn, GroupBy groupBy) { return nearObject(NearObject.of(uuid), fn, groupBy); } - public GroupedResponseT nearObject(String uuid, Function> nv, + /** + * Aggregate results of a near object query. + * + * @param uuid Query object UUID. + * @param nobj Lambda expression for optional near object parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ + public GroupedResponseT nearObject(String uuid, Function> nobj, Function> fn, GroupBy groupBy) { - return nearObject(NearObject.of(uuid, nv), fn, groupBy); - } - + return nearObject(NearObject.of(uuid, nobj), fn, groupBy); + } + + /** + * Aggregate results of a near object query. + * + * @param filter Near object query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearObject(NearObject filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -144,48 +399,176 @@ public GroupedResponseT nearObject(NearObject filter, Function> fn) { return nearText(NearText.of(text), fn); } + /** + * Aggregate results of a near text query. + * + * @param concepts Query concepts. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearText(List concepts, Function> fn) { return nearText(NearText.of(concepts), fn); } + /** + * Aggregate results of a near text query. + * + * @param text Query string. + * @param nt Lambda expression for optional near text parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearText(String text, Function> nt, Function> fn) { return nearText(NearText.of(text, nt), fn); } + /** + * Aggregate results of a near text query. + * + * @param concepts Query concepts. + * @param nt Lambda expression for optional near text parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearText(List concepts, Function> nt, Function> fn) { return nearText(NearText.of(concepts, nt), fn); } + /** + * Aggregate results of a near text query. + * + * @param filter Near text query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearText(NearText filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near text query. + * + * @param text Query string. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearText(String text, Function> fn, GroupBy groupBy) { return nearText(NearText.of(text), fn, groupBy); } + /** + * Aggregate results of a near text query. + * + * @param concepts Query concepts. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearText(List concepts, Function> fn, GroupBy groupBy) { return nearText(NearText.of(concepts), fn, groupBy); } + /** + * Aggregate results of a near text query. + * + * @param text Query string. + * @param nt Lambda expression for optional near text parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearText(String text, Function> nt, Function> fn, GroupBy groupBy) { return nearText(NearText.of(text, nt), fn, groupBy); } + /** + * Aggregate results of a near text query. + * + * @param concepts Query concepts. + * @param nt Lambda expression for optional near text parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearText(List concepts, Function> nt, Function> fn, GroupBy groupBy) { return nearText(NearText.of(concepts, nt), fn, groupBy); } + /** + * Aggregate results of a near text query. + * + * @param filter Near text query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearText(NearText filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -193,29 +576,106 @@ public GroupedResponseT nearText(NearText filter, Function> fn) { return nearImage(NearImage.of(image), fn); } - public ResponseT nearImage(String image, Function> nv, + /** + * Aggregate results of a near image query. + * + * @param image Query image. + * @param ni Lambda expression for optional near image parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ + public ResponseT nearImage(String image, Function> ni, Function> fn) { - return nearImage(NearImage.of(image, nv), fn); - } - + return nearImage(NearImage.of(image, ni), fn); + } + + /** + * Aggregate results of a near image query. + * + * @param filter Near image query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearImage(NearImage filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near image query. + * + * @param image Query image. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearImage(String image, Function> fn, GroupBy groupBy) { return nearImage(NearImage.of(image), fn, groupBy); } - public GroupedResponseT nearImage(String image, Function> nv, + /** + * Aggregate results of a near image query. + * + * @param image Query image. + * @param ni Lambda expression for optional near image parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ + public GroupedResponseT nearImage(String image, Function> ni, Function> fn, GroupBy groupBy) { - return nearImage(NearImage.of(image, nv), fn, groupBy); - } - + return nearImage(NearImage.of(image, ni), fn, groupBy); + } + + /** + * Aggregate results of a near image query. + * + * @param filter Near image query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearImage(NearImage filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -223,29 +683,106 @@ public GroupedResponseT nearImage(NearImage filter, Function> fn) { return nearAudio(NearAudio.of(audio), fn); } - public ResponseT nearAudio(String audio, Function> nv, + /** + * Aggregate results of a near audio query. + * + * @param audio Query audio. + * @param na Lambda expression for optional near audio parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ + public ResponseT nearAudio(String audio, Function> na, Function> fn) { - return nearAudio(NearAudio.of(audio, nv), fn); - } - + return nearAudio(NearAudio.of(audio, na), fn); + } + + /** + * Aggregate results of a near audio query. + * + * @param filter Near audio query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearAudio(NearAudio filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near audio query. + * + * @param audio Query audio. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearAudio(String audio, Function> fn, GroupBy groupBy) { return nearAudio(NearAudio.of(audio), fn, groupBy); } - public GroupedResponseT nearAudio(String audio, Function> nv, + /** + * Aggregate results of a near audio query. + * + * @param audio Query audio. + * @param na Lambda expression for optional near audio parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ + public GroupedResponseT nearAudio(String audio, Function> na, Function> fn, GroupBy groupBy) { - return nearAudio(NearAudio.of(audio, nv), fn, groupBy); - } - + return nearAudio(NearAudio.of(audio, na), fn, groupBy); + } + + /** + * Aggregate results of a near audio query. + * + * @param filter Near audio query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearAudio(NearAudio filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -253,29 +790,106 @@ public GroupedResponseT nearAudio(NearAudio filter, Function> fn) { return nearVideo(NearVideo.of(video), fn); } + /** + * Aggregate results of a near video query. + * + * @param video Query video. + * @param nv Lambda expression for optional near video parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearVideo(String video, Function> nv, Function> fn) { return nearVideo(NearVideo.of(video, nv), fn); } + /** + * Aggregate results of a near video query. + * + * @param filter Near video query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearVideo(NearVideo filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near video query. + * + * @param video Query video. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearVideo(String video, Function> fn, GroupBy groupBy) { return nearVideo(NearVideo.of(video), fn, groupBy); } + /** + * Aggregate results of a near video query. + * + * @param video Query video. + * @param nv Lambda expression for optional near video parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearVideo(String video, Function> nv, Function> fn, GroupBy groupBy) { return nearVideo(NearVideo.of(video, nv), fn, groupBy); } + /** + * Aggregate results of a near video query. + * + * @param filter Near video query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearVideo(NearVideo filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -283,29 +897,106 @@ public GroupedResponseT nearVideo(NearVideo filter, Function> fn) { return nearThermal(NearThermal.of(thermal), fn); } - public ResponseT nearThermal(String thermal, Function> nv, + /** + * Aggregate results of a near thermal query. + * + * @param thermal Query thermal. + * @param nt Lambda expression for optional near thermal parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ + public ResponseT nearThermal(String thermal, Function> nt, Function> fn) { - return nearThermal(NearThermal.of(thermal, nv), fn); - } - + return nearThermal(NearThermal.of(thermal, nt), fn); + } + + /** + * Aggregate results of a near thermal query. + * + * @param filter Near thermal query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearThermal(NearThermal filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near thermal query. + * + * @param thermal Query thermal. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearThermal(String thermal, Function> fn, GroupBy groupBy) { return nearThermal(NearThermal.of(thermal), fn, groupBy); } - public GroupedResponseT nearThermal(String thermal, Function> nv, + /** + * Aggregate results of a near thermal query. + * + * @param thermal Query thermal. + * @param nt Lambda expression for optional near thermal parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ + public GroupedResponseT nearThermal(String thermal, Function> nt, Function> fn, GroupBy groupBy) { - return nearThermal(NearThermal.of(thermal, nv), fn, groupBy); - } - + return nearThermal(NearThermal.of(thermal, nt), fn, groupBy); + } + + /** + * Aggregate results of a near thermal query. + * + * @param filter Near thermal query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearThermal(NearThermal filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -313,29 +1004,106 @@ public GroupedResponseT nearThermal(NearThermal filter, Function> fn) { return nearDepth(NearDepth.of(depth), fn); } - public ResponseT nearDepth(String depth, Function> nv, + /** + * Aggregate results of a near depth query. + * + * @param depth Query depth. + * @param nd Lambda expression for optional near depth parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ + public ResponseT nearDepth(String depth, Function> nd, Function> fn) { - return nearDepth(NearDepth.of(depth, nv), fn); - } - + return nearDepth(NearDepth.of(depth, nd), fn); + } + + /** + * Aggregate results of a near depth query. + * + * @param filter Near depth query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearDepth(NearDepth filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near depth query. + * + * @param depth Query depth. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearDepth(String depth, Function> fn, GroupBy groupBy) { return nearDepth(NearDepth.of(depth), fn, groupBy); } - public GroupedResponseT nearDepth(String depth, Function> nv, + /** + * Aggregate results of a near depth query. + * + * @param depth Query depth. + * @param nd Lambda expression for optional near depth parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ + public GroupedResponseT nearDepth(String depth, Function> nd, Function> fn, GroupBy groupBy) { - return nearDepth(NearDepth.of(depth, nv), fn, groupBy); - } - + return nearDepth(NearDepth.of(depth, nd), fn, groupBy); + } + + /** + * Aggregate results of a near depth query. + * + * @param filter Near depth query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearDepth(NearDepth filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); @@ -343,29 +1111,106 @@ public GroupedResponseT nearDepth(NearDepth filter, Function> fn) { return nearImu(NearImu.of(imu), fn); } - public ResponseT nearImu(String imu, Function> nv, + /** + * Aggregate results of a near IMU query. + * + * @param imu Query IMU. + * @param ni Lambda expression for optional near IMU parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ + public ResponseT nearImu(String imu, Function> ni, Function> fn) { - return nearImu(NearImu.of(imu, nv), fn); - } - + return nearImu(NearImu.of(imu, ni), fn); + } + + /** + * Aggregate results of a near IMU query. + * + * @param filter Near IMU query request. + * @param fn Lambda expression for optional aggregation parameters. + * @return Aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @see AggregateResponse + */ public ResponseT nearImu(NearImu filter, Function> fn) { return performRequest(Aggregation.of(filter, fn)); } + /** + * Aggregate results of a near IMU query. + * + * @param imu Query IMU. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearImu(String imu, Function> fn, GroupBy groupBy) { return nearImu(NearImu.of(imu), fn, groupBy); } - public GroupedResponseT nearImu(String imu, Function> nv, + /** + * Aggregate results of a near IMU query. + * + * @param imu Query IMU. + * @param ni Lambda expression for optional near IMU parameters. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ + public GroupedResponseT nearImu(String imu, Function> ni, Function> fn, GroupBy groupBy) { - return nearImu(NearImu.of(imu, nv), fn, groupBy); - } - + return nearImu(NearImu.of(imu, ni), fn, groupBy); + } + + /** + * Aggregate results of a near IMU query. + * + * @param filter Near IMU query request. + * @param fn Lambda expression for optional aggregation parameters. + * @param groupBy GroupBy clause. + * @return Grouped aggregation result. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see AggregateResponseGrouped + */ public GroupedResponseT nearImu(NearImu filter, Function> fn, GroupBy groupBy) { return performRequest(Aggregation.of(filter, fn), groupBy); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java index c8a12fa0c..717b01c45 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java @@ -147,7 +147,7 @@ public static void buildObject(WeaviateProtoBatch.BatchObject.Builder object protoValue.setBoolValue(v.booleanValue()); } else if (value instanceof Number v) { protoValue.setNumberValue(v.doubleValue()); - } else if (value instanceof List v) { + } else if (value instanceof List v) { protoValue.setListValue( com.google.protobuf.ListValue.newBuilder() .addAllValues(v.stream() diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectResponse.java deleted file mode 100644 index c3eb95f2f..000000000 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectResponse.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.weaviate.client6.v1.api.collections.data; - -import com.google.gson.annotations.SerializedName; - -import io.weaviate.client6.v1.api.collections.Vectors; - -public record InsertObjectResponse( - @SerializedName("class") String collectionName, - @SerializedName("properties") T properties, - @SerializedName("id") String uuid, - @SerializedName("vectors") Vectors vectors, - @SerializedName("creationTimeUnix") Long createdAt, - @SerializedName("lastUpdateTimeUnix") Long lastUpdatedAt) { -} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java index dfc7c90ca..7d7dcb6f9 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java @@ -74,6 +74,7 @@ public Builder(WeaviateQueryClient query) { // Pagination options ----------------------------------------------------- + /** Set a different page size. Defaults to 100. */ public Builder pageSize(int pageSize) { this.pageSize = pageSize; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java index 356df14d5..cc6492b38 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java @@ -4,6 +4,7 @@ import java.util.Optional; import java.util.function.Function; +import io.weaviate.client6.v1.api.WeaviateApiException; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; @@ -37,10 +38,28 @@ abstract class AbstractQueryClient> fn) { // Collection handle defaults (consistencyLevel / tenant) are irrelevant for // by-ID lookup. Do not `applyDefaults` to `fn`. @@ -62,327 +81,1049 @@ protected final Optional> optionalF // Object queries ----------------------------------------------------------- + /** + * Retrieve objects without applying a Vector Search or Keyword Search filter. + * + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT fetchObjects(Function> fn) { return fetchObjects(FetchObjects.of(fn)); } + /** + * Retrieve objects without applying a Vector Search or Keyword Search filter. + * + * @param query FetchObjects query. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT fetchObjects(FetchObjects query) { return performRequest(query); } + /** + * Retrieve objects without applying a Vector Search or Keyword Search filter. + * + * + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT fetchObjects(Function> fn, GroupBy groupBy) { return fetchObjects(FetchObjects.of(fn), groupBy); } + /** + * Retrieve objects without applying a Vector Search or Keyword Search filter. + * + * @param query FetchObjects query. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT fetchObjects(FetchObjects query, GroupBy groupBy) { return performRequest(query, groupBy); } // BM25 queries ------------------------------------------------------------- + /** + * Query collection objects using keyword (BM25) search. + * + * @param query Query string. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT bm25(String query) { return bm25(Bm25.of(query)); } + /** + * Query collection objects using keyword (BM25) search. + * + * @param query Query string. + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT bm25(String query, Function> fn) { return bm25(Bm25.of(query, fn)); } + /** + * Query collection objects using keyword (BM25) search. + * + * @param query BM25 query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT bm25(Bm25 query) { return performRequest(query); } + /** + * Query collection objects using keyword (BM25) search. + * + * @param query Query string. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT bm25(String query, GroupBy groupBy) { return bm25(Bm25.of(query), groupBy); } + /** + * Query collection objects using keyword (BM25) search. + * + * @param query Query string. + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT bm25(String query, Function> fn, GroupBy groupBy) { return bm25(Bm25.of(query, fn), groupBy); } + /** + * Query collection objects using keyword (BM25) search. + * + * @param query BM25 query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT bm25(Bm25 query, GroupBy groupBy) { return performRequest(query, groupBy); } // Hybrid queries ----------------------------------------------------------- + /** + * Query collection objects using hybrid search. + * + * @param query Query string. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT hybrid(String query) { return hybrid(Hybrid.of(query)); } + /** + * Query collection objects using hybrid search. + * + * @param query Query string. + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT hybrid(String query, Function> fn) { return hybrid(Hybrid.of(query, fn)); } + /** + * Query collection objects using hybrid search. + * + * @param query Hybrid query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT hybrid(Hybrid query) { return performRequest(query); } + /** + * Query collection objects using hybrid search. + * + * @param query Query string. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT hybrid(String query, GroupBy groupBy) { return hybrid(Hybrid.of(query), groupBy); } + /** + * Query collection objects using hybrid search. + * + * @param query Query string. + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT hybrid(String query, Function> fn, GroupBy groupBy) { return hybrid(Hybrid.of(query, fn), groupBy); } + /** + * Query collection objects using hybrid search. + * + * @param query Query string. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT hybrid(Hybrid query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearVector queries ------------------------------------------------------- + /** + * Query collection objects using near vector search. + * + * @param vector Query vector. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearVector(float[] vector) { return nearVector(NearVector.of(vector)); } + /** + * Query collection objects using near vector search. + * + * @param vector Query vector. + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearVector(float[] vector, Function> fn) { return nearVector(NearVector.of(vector, fn)); } + /** + * Query collection objects using near vector search. + * + * @param query Near vector query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearVector(NearVector query) { return performRequest(query); } + /** + * Query collection objects using near vector search. + * + * @param vector Query vector. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearVector(float[] vector, GroupBy groupBy) { return nearVector(NearVector.of(vector), groupBy); } + /** + * Query collection objects using near vector search. + * + * @param vector Query vector. + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearVector(float[] vector, Function> fn, GroupBy groupBy) { return nearVector(NearVector.of(vector, fn), groupBy); } + /** + * Query collection objects using near vector search. + * + * @param query Near vector query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearVector(NearVector query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearObject queries ------------------------------------------------------- + /** + * Query collection objects using near object search. + * + * @param uuid Query object UUID. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearObject(String uuid) { return nearObject(NearObject.of(uuid)); } + /** + * Query collection objects using near object search. + * + * @param uuid Query object UUID. + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearObject(String uuid, Function> fn) { return nearObject(NearObject.of(uuid, fn)); } + /** + * Query collection objects using near object search. + * + * @param query Near object query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearObject(NearObject query) { return performRequest(query); } + /** + * Query collection objects using near object search. + * + * @param uuid Query object UUID. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearObject(String uuid, GroupBy groupBy) { return nearObject(NearObject.of(uuid), groupBy); } + /** + * Query collection objects using near object search. + * + * @param uuid Query object UUID. + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearObject(String uuid, Function> fn, GroupBy groupBy) { return nearObject(NearObject.of(uuid, fn), groupBy); } + /** + * Query collection objects using near object search. + * + * @param query Near object query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearObject(NearObject query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearText queries --------------------------------------------------------- + /** + * Query collection objects using near text search. + * + * @param text Query concepts. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearText(String... text) { return nearText(NearText.of(text)); } + /** + * Query collection objects using near text search. + * + * @param text Query concepts. + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearText(String text, Function> fn) { return nearText(NearText.of(text, fn)); } + /** + * Query collection objects using near text search. + * + * @param text Query concepts. + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearText(List text, Function> fn) { return nearText(NearText.of(text, fn)); } + /** + * Query collection objects using near text search. + * + * @param query Near text query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearText(NearText query) { return performRequest(query); } + /** + * Query collection objects using near text search. + * + * @param text Query concepts. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearText(String text, GroupBy groupBy) { return nearText(NearText.of(text), groupBy); } + /** + * Query collection objects using near text search. + * + * @param text Query concepts. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearText(List text, GroupBy groupBy) { return nearText(NearText.of(text), groupBy); } + /** + * Query collection objects using near text search. + * + * @param text Query concepts. + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearText(String text, Function> fn, GroupBy groupBy) { return nearText(NearText.of(text), groupBy); } + /** + * Query collection objects using near text search. + * + * @param text Query concepts. + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearText(List text, Function> fn, GroupBy groupBy) { return nearText(NearText.of(text), groupBy); } + /** + * Query collection objects using near text search. + * + * @param query Near text query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearText(NearText query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearImage queries -------------------------------------------------------- + /** + * Query collection objects using near image search. + * + * @param image Query image (base64-encoded). + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearImage(String image) { return nearImage(NearImage.of(image)); } + /** + * Query collection objects using near image search. + * + * @param image Query image (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearImage(String image, Function> fn) { return nearImage(NearImage.of(image, fn)); } + /** + * Query collection objects using near image search. + * + * @param query Near image query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearImage(NearImage query) { return performRequest(query); } + /** + * Query collection objects using near image search. + * + * @param image Query image (base64-encoded). + * @param groupBy Group-by clause. + * @return Grouped query result. + * + * @see GroupBy + * @see QueryResponseGrouped + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public GroupedResponseT nearImage(String image, GroupBy groupBy) { return nearImage(NearImage.of(image), groupBy); } + /** + * Query collection objects using near image search. + * + * @param image Query image (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearImage(String image, Function> fn, GroupBy groupBy) { return nearImage(NearImage.of(image, fn), groupBy); } + /** + * Query collection objects using near image search. + * + * @param query Near image query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearImage(NearImage query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearAudio queries -------------------------------------------------------- + /** + * Query collection objects using near audio search. + * + * @param audio Query audio (base64-encoded). + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearAudio(String audio) { return nearAudio(NearAudio.of(audio)); } + /** + * Query collection objects using near audio search. + * + * @param audio Query audio (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearAudio(String audio, Function> fn) { return nearAudio(NearAudio.of(audio, fn)); } + /** + * Query collection objects using near audio search. + * + * @param query Near audio query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearAudio(NearAudio query) { return performRequest(query); } + /** + * Query collection objects using near audio search. + * + * @param audio Query audio (base64-encoded). + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearAudio(String audio, GroupBy groupBy) { return nearAudio(NearAudio.of(audio), groupBy); } + /** + * Query collection objects using near audio search. + * + * @param audio Query audio (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ + public GroupedResponseT nearAudio(String audio, Function> fn, GroupBy groupBy) { return nearAudio(NearAudio.of(audio, fn), groupBy); } + /** + * Query collection objects using near audio search. + * + * @param query Near audio query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearAudio(NearAudio query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearVideo queries -------------------------------------------------------- + /** + * Query collection objects using near video search. + * + * @param video Query video (base64-encoded). + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearVideo(String video) { return nearVideo(NearVideo.of(video)); } + /** + * Query collection objects using near video search. + * + * @param video Query video (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearVideo(String video, Function> fn) { return nearVideo(NearVideo.of(video, fn)); } + /** + * Query collection objects using near video search. + * + * @param query Near video query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearVideo(NearVideo query) { return performRequest(query); } + /** + * Query collection objects using near video search. + * + * @param video Query video (base64-encoded). + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearVideo(String video, GroupBy groupBy) { return nearVideo(NearVideo.of(video), groupBy); } + /** + * Query collection objects using near video search. + * + * @param video Query video (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearVideo(String video, Function> fn, GroupBy groupBy) { return nearVideo(NearVideo.of(video, fn), groupBy); } + /** + * Query collection objects using near video search. + * + * @param query Near video query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearVideo(NearVideo query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearThermal queries ------------------------------------------------------ + /** + * Query collection objects using near thermal search. + * + * @param thermal Query thermal (base64-encoded). + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearThermal(String thermal) { return nearThermal(NearThermal.of(thermal)); } + /** + * Query collection objects using near thermal search. + * + * @param thermal Query thermal (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearThermal(String thermal, Function> fn) { return nearThermal(NearThermal.of(thermal, fn)); } + /** + * Query collection objects using near thermal search. + * + * @param query Near thermal query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearThermal(NearThermal query) { return performRequest(query); } + /** + * Query collection objects using near thermal search. + * + * @param thermal Query thermal (base64-encoded). + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearThermal(String thermal, GroupBy groupBy) { return nearThermal(NearThermal.of(thermal), groupBy); } + /** + * Query collection objects using near thermal search. + * + * @param thermal Query thermal (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearThermal(String thermal, Function> fn, GroupBy groupBy) { return nearThermal(NearThermal.of(thermal, fn), groupBy); } + /** + * Query collection objects using near thermal search. + * + * @param query Near thermal query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearThermal(NearThermal query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearDepth queries -------------------------------------------------------- + /** + * Query collection objects using near depth search. + * + * @param depth Query depth (base64-encoded). + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearDepth(String depth) { return nearDepth(NearDepth.of(depth)); } + /** + * Query collection objects using near depth search. + * + * @param depth Query depth (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearDepth(String depth, Function> fn) { return nearDepth(NearDepth.of(depth, fn)); } + /** + * Query collection objects using near depth search. + * + * @param query Near depth query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearDepth(NearDepth query) { return performRequest(query); } + /** + * Query collection objects using near depth search. + * + * @param depth Query depth (base64-encoded). + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearDepth(String depth, GroupBy groupBy) { return nearDepth(NearDepth.of(depth), groupBy); } + /** + * Query collection objects using near depth search. + * + * @param depth Query depth (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearDepth(String depth, Function> fn, GroupBy groupBy) { return nearDepth(NearDepth.of(depth, fn), groupBy); } + /** + * Query collection objects using near depth search. + * + * @param query Near depth query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearDepth(NearDepth query, GroupBy groupBy) { return performRequest(query, groupBy); } // NearImu queries ---------------------------------------------------------- + /** + * Query collection objects using near IMU search. + * + * @param imu Query IMU (base64-encoded). + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearImu(String imu) { return nearImu(NearImu.of(imu)); } + /** + * Query collection objects using near IMU search. + * + * @param imu Query IMU (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearImu(String imu, Function> fn) { return nearImu(NearImu.of(imu, fn)); } + /** + * Query collection objects using near IMU search. + * + * @param query Near IMU query request. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public ResponseT nearImu(NearImu query) { return performRequest(query); } + /** + * Query collection objects using near IMU search. + * + * @param imu Query IMU (base64-encoded). + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearImu(String imu, GroupBy groupBy) { return nearImu(NearImu.of(imu), groupBy); } + /** + * Query collection objects using near IMU search. + * + * @param imu Query IMU (base64-encoded). + * @param fn Lambda expression for optional parameters. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearImu(String imu, Function> fn, GroupBy groupBy) { return nearImu(NearImu.of(imu, fn), groupBy); } + /** + * Query collection objects using near IMU search. + * + * @param query Near IMU query request. + * @param groupBy Group-by clause. + * @return Grouped query result. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * + * @see GroupBy + * @see QueryResponseGrouped + */ public GroupedResponseT nearImu(NearImu query, GroupBy groupBy) { return performRequest(query, groupBy); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseQueryOptions.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseQueryOptions.java index ad8d71b24..036ce1165 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseQueryOptions.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseQueryOptions.java @@ -52,26 +52,51 @@ protected Builder() { returnMetadata(MetadataField.UUID); } + /** + * Limit the number of returned objects. + * + *

+ * Combine with {@link #offset(int)} to use offset-based pagination. + */ public final SELF limit(int limit) { this.limit = limit; return (SELF) this; } + /** + * Skip the first N objects in the result set. + * + *

+ * Combine with {@link #limit(int)} to use offset-based pagination. + */ public final SELF offset(int offset) { this.offset = offset; return (SELF) this; } + /** + * Discard results after an automatically calculated cutoff point. + * + * @param autocut The number of "groups" to keep. + * @see Documentation + */ public final SELF autocut(int autocut) { this.autocut = autocut; return (SELF) this; } + /** + * Discard results before this object. + * + * @param after UUID of an object in this collection. + */ public final SELF after(String after) { this.after = after; return (SELF) this; } + /** Set consitency level for query resolution. */ public final SELF consistencyLevel(ConsistencyLevel consistencyLevel) { this.consistencyLevel = consistencyLevel; return (SELF) this; @@ -81,42 +106,52 @@ public final SELF consistencyLevel(ConsistencyLevel consistencyLevel) { * Filter result set using traditional filtering operators: {@code eq}, * {@code gte}, {@code like}, etc. * Subsequent calls to {@link #where} aggregate with an AND operator. - * - *

- * See: {@link Where} */ public final SELF where(Where where) { this.where = this.where == null ? where : Where.and(this.where, where); return (SELF) this; } + /** Combine several conditions using with an AND operator. */ + public final SELF where(Where... wheres) { + Arrays.stream(wheres).map(this::where); + return (SELF) this; + } + + /** Select properties to include in the query result. */ public final SELF returnProperties(String... properties) { return returnProperties(Arrays.asList(properties)); } + /** Select properties to include in the query result. */ public final SELF returnProperties(List properties) { this.returnProperties.addAll(properties); return (SELF) this; } + /** Select cross-referenced objects to include in the query result. */ public final SELF returnReferences(QueryReference... references) { return returnReferences(Arrays.asList(references)); } + /** Select cross-referenced objects to include in the query result. */ public final SELF returnReferences(List references) { this.returnReferences.addAll(references); return (SELF) this; } + /** Select metadata to include in the query result. */ public final SELF returnMetadata(Metadata... metadata) { return returnMetadata(Arrays.asList(metadata)); } + /** Select metadata to include in the query result. */ public final SELF returnMetadata(List metadata) { this.returnMetadata.addAll(metadata); return (SELF) this; } + /** Include default vector. */ public final SELF includeVector() { return returnMetadata(Metadata.VECTOR); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseVectorSearchBuilder.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseVectorSearchBuilder.java index 08b385a1a..afc96d338 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseVectorSearchBuilder.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/BaseVectorSearchBuilder.java @@ -7,12 +7,29 @@ abstract class BaseVectorSearchBuilder + * Use {@link Hybrid.Builder#maxVectorDistance(float)} if {@link NearVector} or + * {@link NearText} are used as a vector search component in hybrid search. + */ @SuppressWarnings("unchecked") public SelfT distance(float distance) { this.distance = distance; return (SelfT) this; } + /** + * Discard objects whose vectors are further away + * from the target vector than the threshold according + * to a normalized ({@code 0 <= c <= 0}) distance. + * + *

+ * Certainty is only meaningful for {@code cosine} distance. + * Prefer using {@link #distance(float)} to limit search results. + */ @SuppressWarnings("unchecked") public SelfT certainty(float certainty) { this.certainty = certainty; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/Bm25.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/Bm25.java index 9c48e6101..899487a62 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/Bm25.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/Bm25.java @@ -39,15 +39,22 @@ public Builder(String query) { this.query = query; } + /** Select properties to be included in the results scoring. */ public Builder queryProperties(String... properties) { return queryProperties(Arrays.asList(properties)); } + /** Select properties to be included in the results scoring. */ public Builder queryProperties(List properties) { this.queryProperties.addAll(properties); return this; } + /** + * Select BM25 + * Search Operator to use. + */ public Builder searchOperator(SearchOperator searchOperator) { this.searchOperator = searchOperator; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/ById.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/ById.java index 5a2bee979..7beb43f90 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/ById.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/ById.java @@ -48,33 +48,40 @@ public Builder(String uuid) { returnMetadata(MetadataField.UUID); } + /** Select properties to include in the query result. */ public final Builder returnProperties(String... properties) { return returnProperties(Arrays.asList(properties)); } + /** Select properties to include in the query result. */ public final Builder returnProperties(List properties) { this.returnProperties.addAll(properties); return this; } + /** Select cross-referenced objects to include in the query result. */ public final Builder returnReferences(QueryReference... references) { return returnReferences(Arrays.asList(references)); } + /** Select cross-referenced objects to include in the query result. */ public final Builder returnReferences(List references) { this.returnReferences.addAll(references); return this; } + /** Select metadata to include in the query result. */ public final Builder returnMetadata(Metadata... metadata) { return returnMetadata(Arrays.asList(metadata)); } + /** Select metadata to include in the query result. */ public final Builder returnMetadata(List metadata) { this.returnMetadata.addAll(metadata); return this; } + /** Include default vector. */ public final Builder includeVector() { return returnMetadata(Metadata.VECTOR); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/ConsistencyLevel.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/ConsistencyLevel.java index 5ed88258f..326609d2e 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/ConsistencyLevel.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/ConsistencyLevel.java @@ -6,8 +6,21 @@ import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoSearchGet; public enum ConsistencyLevel { + /** + * The operation succeeds as soon as one replica acknowledges the request. This + * is the fastest and most available, but least consistent option. + */ ONE(WeaviateProtoBase.ConsistencyLevel.CONSISTENCY_LEVEL_ONE, "ONE"), + /** + * The operation succeeds when a majority of replicas (calculated as + * replication_factor/2 + 1) respond. This provides a balance between + * consistency and availability. + */ QUORUM(WeaviateProtoBase.ConsistencyLevel.CONSISTENCY_LEVEL_ONE, "QUORUM"), + /** + * The operation succeeds only when all replicas respond. This is the most + * consistent but least available and slowest option. + */ ALL(WeaviateProtoBase.ConsistencyLevel.CONSISTENCY_LEVEL_ONE, "ALL"); private final WeaviateProtoBase.ConsistencyLevel consistencyLevel; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/GroupBy.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/GroupBy.java index e79bd1389..2cb430ffd 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/GroupBy.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/GroupBy.java @@ -5,6 +5,13 @@ import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoSearchGet; public record GroupBy(List path, int maxGroups, int maxObjectsPerGroup) { + /** + * Group results by the property value. + * + * @param property Property name. + * @param maxGroups Maximum number of groups to return. + * @param maxObjectsPerGroup Maximum number of objects to include in a group. + */ public static GroupBy property(String property, int maxGroups, int maxObjectsPerGroup) { return new GroupBy(List.of(property), maxGroups, maxObjectsPerGroup); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/Hybrid.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/Hybrid.java index c67412b87..dc5ef608f 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/Hybrid.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/Hybrid.java @@ -62,40 +62,72 @@ public Builder(String query) { this.query = query; } + /** Select properties to be included in the results scoring. */ public Builder queryProperties(String... properties) { return queryProperties(Arrays.asList(properties)); } + /** Select properties to be included in the results scoring. */ public Builder queryProperties(List properties) { this.queryProperties = properties; return this; } + /** + * Select BM25 + * Search Operator to use. + */ public Builder searchOperator(SearchOperator searchOperator) { this.searchOperator = searchOperator; return this; } + /** + * Apply custom weighting between vector search and keyword search components. + * + *

    + *
  • {@code alpha=1}: Pure BM25 search + *
  • {@code alpha=0}: Pure vector search + *
  • {@code alpha>0.5}: More weight to vector search + *
  • {@code alpha<0.5}: More weight to BM25 search + *
+ */ public Builder alpha(float alpha) { this.alpha = alpha; return this; } + /** + * Select the fusion algorithm for combining + * vector search and keyword search results. + */ public Builder fusionType(FusionType fusionType) { this.fusionType = fusionType; return this; } + /** Set the maximum allowable distance for the vector search component. */ public Builder maxVectorDistance(float maxVectorDistance) { this.maxVectorDistance = maxVectorDistance; return this; } + /** + * Vector search component. + * + * @see NearVector#of + */ public Builder nearVector(NearVector nearVector) { this.near = nearVector; return this; } + /** + * Vector search component. + * + * @see NearText#of + */ public Builder nearText(NearText nearText) { this.near = nearText; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java index 3573292ab..25f8f676e 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java @@ -4,13 +4,22 @@ import io.weaviate.client6.v1.api.collections.WeaviateMetadata; import io.weaviate.client6.v1.internal.ObjectBuilder; -public record QueryMetadata(String uuid, +public record QueryMetadata( + /** Object UUID. */ + String uuid, + /** Vector embeddings associated with the object. */ Vectors vectors, + /** Object creation time as a Unix timestamp. */ Long creationTimeUnix, + /** Unix timestamp of the latest object update. */ Long lastUpdateTimeUnix, + /** Distances to the search vector. */ Float distance, + /** Distance metric normalized to {@code 0 <= c <= 1} range. */ Float certainty, + /** BM25 ranking score. */ Float score, + /** Components of the BM25 ranking score. */ String explainScore) implements WeaviateMetadata { private QueryMetadata(Builder builder) { @@ -25,7 +34,7 @@ private QueryMetadata(Builder builder) { builder.explainScore); } - public static class Builder implements ObjectBuilder { + static class Builder implements ObjectBuilder { private String uuid; private Vectors vectors; private Long creationTimeUnix; @@ -35,42 +44,42 @@ public static class Builder implements ObjectBuilder { private Float score; private String explainScore; - public final Builder uuid(String uuid) { + final Builder uuid(String uuid) { this.uuid = uuid; return this; } - public final Builder vectors(Vectors vectors) { + final Builder vectors(Vectors vectors) { this.vectors = vectors; return this; } - public final Builder creationTimeUnix(Long creationTimeUnix) { + final Builder creationTimeUnix(Long creationTimeUnix) { this.creationTimeUnix = creationTimeUnix; return this; } - public final Builder lastUpdateTimeUnix(Long lastUpdateTimeUnix) { + final Builder lastUpdateTimeUnix(Long lastUpdateTimeUnix) { this.lastUpdateTimeUnix = lastUpdateTimeUnix; return this; } - public final Builder distance(Float distance) { + final Builder distance(Float distance) { this.distance = distance; return this; } - public final Builder certainty(Float certainty) { + final Builder certainty(Float certainty) { this.certainty = certainty; return this; } - public final Builder score(Float score) { + final Builder score(Float score) { this.score = score; return this; } - public final Builder explainScore(String explainScore) { + final Builder explainScore(String explainScore) { this.explainScore = explainScore; return this; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java index 1000d6321..f35f3e824 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java @@ -3,8 +3,11 @@ import io.weaviate.client6.v1.api.collections.WeaviateObject; public record QueryObjectGrouped( + /** Object properties. */ T properties, + /** Object metadata. */ QueryMetadata metadata, + /** Name of the group that the object belongs to. */ String belongsToGroup) { QueryObjectGrouped(WeaviateObject object, diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryReference.java index f0a2c84a5..c6aac5a77 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryReference.java @@ -29,19 +29,44 @@ public QueryReference(Builder options) { new ArrayList<>(options.returnMetadata)); } + /** + * Retrieve object referenced by a single-target cross-reference property. + * + * @param property Name of the cross-reference property. + */ public static QueryReference single(String property) { return single(property, ObjectBuilder.identity()); } + /** + * Retrieve object referenced by a single-target cross-reference property. + * + * @param property Name of the cross-reference property. + * @param fn Lambda expression for optional parameters. + */ public static QueryReference single(String property, Function> fn) { return fn.apply(new Builder(null, property)).build(); } // TODO: check if we can supply mutiple collections + + /** + * Retrieve object referenced by a multi-target cross-reference property. + * + * @param property Name of the cross-reference property. + * @param collection Name of the target collection. + */ public static QueryReference multi(String property, String collection) { return multi(property, collection, ObjectBuilder.identity()); } + /** + * Retrieve object referenced by a multi-target cross-reference property. + * + * @param property Name of the cross-reference property. + * @param collection Name of the target collection. + * @param fn Lambda expression for optional parameters. + */ public static QueryReference multi(String property, String collection, Function> fn) { return fn.apply(new Builder(collection, property)).build(); @@ -62,38 +87,46 @@ public Builder(String collection, String property) { returnMetadata(MetadataField.UUID); } + /** Select vectors to return for each referenced object. */ public final Builder includeVectors(String... vectors) { this.includeVectors.addAll(Arrays.asList(vectors)); return this; } + /** Select properties to return for each referenced object. */ public final Builder returnProperties(String... properties) { return returnProperties(Arrays.asList(properties)); } + /** Select properties to return for each referenced object. */ public final Builder returnProperties(List properties) { this.returnProperties.addAll(properties); return this; } + /** Select nested references to return for each referenced object. */ public final Builder returnReferences(QueryReference... references) { return returnReferences(Arrays.asList(references)); } + /** Select nested references to return for each referenced object. */ public final Builder returnReferences(List references) { this.returnReferences.addAll(references); return this; } + /** Select metadata to return about each referenced object. */ public final Builder returnMetadata(Metadata... metadata) { return returnMetadata(Arrays.asList(metadata)); } + /** Select metadata to return about each referenced object. */ public final Builder returnMetadata(List metadata) { this.returnMetadata.addAll(metadata); return this; } + /** Include the default vector of the referenced object. */ public final Builder includeVector() { return returnMetadata(Metadata.VECTOR); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGroup.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGroup.java index 178af862c..5ad750051 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGroup.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGroup.java @@ -3,9 +3,20 @@ import java.util.List; public record QueryResponseGroup( + /** Group name. */ String name, + /** + * The smallest distance value among all objects in the group, indicating the + * most similar object in that group to the query + */ Float minDistance, + /** + * The largest distance value among all objects in the group, indicating the + * least similar object in that group to the query. + */ Float maxDistance, + /** The size of the group. */ long numberOfObjects, + /** Objects retrieved in the query. */ List> objects) { } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGrouped.java index 4c9383527..9ee8442fa 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGrouped.java @@ -4,6 +4,8 @@ import java.util.Map; public record QueryResponseGrouped( + /** All objects retrieved in the query. */ List> objects, + /** Grouped response objects. */ Map> groups) { } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java index 81a7c11b1..d88588450 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java @@ -42,5 +42,4 @@ protected final QueryResponseGrouped performRequest(QueryOperator operator, G var request = new QueryRequest(operator, groupBy); return this.grpcTransport.performRequest(request, QueryRequest.grouped(collection, defaults)); } - } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java index 0c195e80d..a774d0e29 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java @@ -43,5 +43,4 @@ protected final CompletableFuture> performRequest(QueryO var request = new QueryRequest(operator, groupBy); return this.grpcTransport.performRequestAsync(request, QueryRequest.grouped(collection, defaults)); } - } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/Where.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/Where.java index bde53a695..807f9aa6f 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/Where.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/Where.java @@ -94,14 +94,17 @@ public static Where or(List operands) { // Comparison operators return fluid builder. // -------------------------------------------------------------------------- + /** Filter by object UUID. */ public static WhereBuilder uuid() { return property(ById.ID_PROPERTY); } + /** Filter by object property. */ public static WhereBuilder property(String property) { return new WhereBuilder(new PathOperand(property)); } + /** Filter by a property of the referenced object. */ public static WhereBuilder reference(String... path) { return new WhereBuilder(new PathOperand(path)); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/tenants/WeaviateTenantsClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/tenants/WeaviateTenantsClient.java index 37385672a..fadb596db 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/tenants/WeaviateTenantsClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/tenants/WeaviateTenantsClient.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Optional; +import io.weaviate.client6.v1.api.WeaviateApiException; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.RestTransport; @@ -23,71 +24,236 @@ public WeaviateTenantsClient( this.grpcTransport = grpcTransport; } + /** + * Add more tenants to the collection. + * + * @param tenants Tenant configurations. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void create(Tenant... tenants) throws IOException { create(Arrays.asList(tenants)); } + /** + * Add more tenants to the collection. + * + * @param tenants Tenant configurations. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void create(List tenants) throws IOException { this.restTransport.performRequest(new CreateTenantsRequest(tenants), CreateTenantsRequest.endpoint(collection)); } + /** + * Get tenant information. + * + * @param tenant Tenant name. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * due to a malformed request, a networking error + * or the server being unavailable. + */ public Optional get(String tenant) { var tenants = get(List.of(tenant)); return tenants.isEmpty() ? Optional.empty() : Optional.ofNullable(tenants.get(0)); } + /** + * List all existing tenants. + * + * @throws WeaviateApiException in case the server returned with an + * error status code. + * due to a malformed request, a networking error + * or the server being unavailable. + */ public List list() { return get(); } + /** + * List selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * due to a malformed request, a networking error + * or the server being unavailable. + */ public List get(String... tenants) { return get(Arrays.asList(tenants)); } + /** + * List selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + */ public List get(List tenants) { return this.grpcTransport.performRequest(new GetTenantsRequest(tenants), GetTenantsRequest.rpc(collection)); } + /** + * Update tenant configuration. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void update(Tenant... tenants) throws IOException { update(Arrays.asList(tenants)); } + /** + * Update tenant configuration. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void update(List tenants) throws IOException { this.restTransport.performRequest(new UpdateTenantsRequest(tenants), UpdateTenantsRequest.endpoint(collection)); } + /** + * Delete selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void delete(String... tenants) throws IOException { delete(Arrays.asList(tenants)); } + /** + * Delete selected tenants. + * + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void delete(List tenants) throws IOException { this.restTransport.performRequest(new DeleteTenantsRequest(tenants), DeleteTenantsRequest.endpoint(collection)); } + /** + * Check if such tenant exists. + * + * @param tenant Tenant name. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public boolean exists(String tenant) throws IOException { return this.restTransport.performRequest(new TenantExistsRequest(tenant), TenantExistsRequest.endpoint(collection)); } + /** + * Activate selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void activate(String... tenants) throws IOException { activate(Arrays.asList(tenants)); } + /** + * Activate selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void activate(List tenants) throws IOException { update(tenants.stream().map(Tenant::active).toList()); } + /** + * Deactivate selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void deactivate(String... tenants) throws IOException { deactivate(Arrays.asList(tenants)); } + /** + * Deactivate selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void deactivate(List tenants) throws IOException { update(tenants.stream().map(Tenant::inactive).toList()); } + /** + * Offload selected tenants. + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void offload(String... tenants) throws IOException { offload(Arrays.asList(tenants)); } + /** + * Offload selected tenants. + * + * + * @param tenants Tenant names. + * @throws WeaviateApiException in case the server returned with an + * error status code. + * @throws IOException in case the request was not sent successfully + * due to a malformed request, a networking error + * or the server being unavailable. + */ public void offload(List tenants) throws IOException { update(tenants.stream().map(t -> new Tenant(t, TenantStatus.OFFLOADED)).toList()); }