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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ record Artist(String firstName, String lastName, int age) {};

record Song(String title, Artist artist) {};

var song1 = songs.query.byId(
var song1 = songs.query.fetchObjectById(
uuid1,
song -> song.returnReferences(QueryReference.single("artist"))
);
Expand Down
18 changes: 9 additions & 9 deletions src/it/java/io/weaviate/integration/DataITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testCreateGetDelete() throws IOException {
.uuid(id)
.vectors(Vectors.of(VECTOR_INDEX, vector)));

var object = artists.query.byId(id, query -> query
var object = artists.query.fetchObjectById(id, query -> query
.returnProperties("name")
.returnMetadata(
MetadataField.VECTOR,
Expand Down Expand Up @@ -99,7 +99,7 @@ public void testBlobData() throws IOException {
"breed", "ragdoll",
"img", ragdollPng));

var got = cats.query.byId(ragdoll.metadata().uuid(),
var got = cats.query.fetchObjectById(ragdoll.metadata().uuid(),
cat -> cat.returnProperties("img"));

Assertions.assertThat(got).get()
Expand Down Expand Up @@ -145,7 +145,7 @@ public void testReferences_AddReplaceDelete() throws IOException {
Reference.object(albie));

// Assert
var johnWithFriends = persons.query.byId(john.metadata().uuid(),
var johnWithFriends = persons.query.fetchObjectById(john.metadata().uuid(),
query -> query.returnReferences(
QueryReference.single("hasFriend",
friend -> friend.returnProperties("name"))));
Expand All @@ -165,7 +165,7 @@ public void testReferences_AddReplaceDelete() throws IOException {
"hasFriend",
Reference.object(barbara));

johnWithFriends = persons.query.byId(john.metadata().uuid(),
johnWithFriends = persons.query.fetchObjectById(john.metadata().uuid(),
query -> query.returnReferences(
QueryReference.single("hasFriend",
friend -> friend.returnProperties("name"))));
Expand All @@ -185,7 +185,7 @@ public void testReferences_AddReplaceDelete() throws IOException {
Reference.object(barbara));

// Assert
johnWithFriends = persons.query.byId(john.metadata().uuid(),
johnWithFriends = persons.query.fetchObjectById(john.metadata().uuid(),
query -> query.returnReferences(
QueryReference.single("hasFriend")));

Expand Down Expand Up @@ -214,7 +214,7 @@ public void testReplace() throws IOException {
replace -> replace.properties(Map.of("year", 1819)));

// Assert
var replacedIvanhoe = books.query.byId(ivanhoe.metadata().uuid());
var replacedIvanhoe = books.query.fetchObjectById(ivanhoe.metadata().uuid());

Assertions.assertThat(replacedIvanhoe).get()
.as("has ONLY year property")
Expand Down Expand Up @@ -258,7 +258,7 @@ public void testUpdate() throws IOException {
.vectors(Vectors.of(vector)));

// Assert
var updIvanhoe = books.query.byId(
var updIvanhoe = books.query.fetchObjectById(
ivanhoe.metadata().uuid(),
query -> query
.includeVector()
Expand Down Expand Up @@ -387,7 +387,7 @@ public void testReferenceAddMany() throws IOException {
// Assert
Assertions.assertThat(response.errors()).isEmpty();

var goodburgAirports = cities.query.byId(goodburg.metadata().uuid(),
var goodburgAirports = cities.query.fetchObjectById(goodburg.metadata().uuid(),
city -> city.returnReferences(
QueryReference.single("hasAirports")));

Expand Down Expand Up @@ -469,7 +469,7 @@ public void testDataTypes() throws IOException {

// Act
var object = types.data.insert(want);
var got = types.query.byId(object.uuid()); // return all properties
var got = types.query.fetchObjectById(object.uuid()); // return all properties

// Assert
Assertions.assertThat(got).get()
Expand Down
4 changes: 2 additions & 2 deletions src/it/java/io/weaviate/integration/ORMITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void test_insertAndQuery() throws Exception {
var inserted = things.data.insert(thing);

// Assert
var response = things.query.byId(inserted.uuid());
var response = things.query.fetchObjectById(inserted.uuid());
var got = Assertions.assertThat(response).get().actual();

Assertions.assertThat(got.properties())
Expand Down Expand Up @@ -353,7 +353,7 @@ public void test_partialScan() throws IOException {
null));

// Act: return subset of the properties
var got = songs.query.byId(dystopia.uuid(),
var got = songs.query.fetchObjectById(dystopia.uuid(),
q -> q.returnProperties("title", "hasAward"));

// Assert
Expand Down
4 changes: 2 additions & 2 deletions src/it/java/io/weaviate/integration/ReferencesITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testReferences() throws IOException {
.extracting(ReferenceProperty::dataTypes, InstanceOfAssertFactories.list(String.class))
.containsOnly(nsMovies);

var gotAlex = artists.query.byId(alex.metadata().uuid(),
var gotAlex = artists.query.fetchObjectById(alex.metadata().uuid(),
opt -> opt.returnReferences(
QueryReference.multi("hasAwards", nsOscar),
QueryReference.multi("hasAwards", nsGrammy)));
Expand Down Expand Up @@ -155,7 +155,7 @@ public void testNestedReferences() throws IOException {
.reference("hasAwards", Reference.objects(grammy_1)));

// Assert: fetch nested references
var gotAlex = artists.query.byId(alex.metadata().uuid(),
var gotAlex = artists.query.fetchObjectById(alex.metadata().uuid(),
opt -> opt.returnReferences(
QueryReference.single("hasAwards",
ref -> ref
Expand Down
18 changes: 12 additions & 6 deletions src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public void test_includeVectors() throws IOException {
Vectors.of("v3", new float[] { 7, 8, 9 })));

// Act
var got = things.query.byId(
var got = things.query.fetchObjectById(
thing_1.uuid(),
q -> q.includeVector("v1", "v2"));

Expand Down Expand Up @@ -597,7 +597,7 @@ public void testGenerative_bm25() throws IOException {
// Act
var french = things.generate.bm25(
"fork",
bm25 -> bm25.queryProperties("title").limit(2),
bm25 -> bm25.queryProperties("title").limit(2).includeVector(),
generate -> generate
.singlePrompt("translate to French")
.groupedTask("count letters R"));
Expand All @@ -606,12 +606,18 @@ public void testGenerative_bm25() throws IOException {
Assertions.assertThat(french.objects())
.as("individual results")
.hasSize(2)
.extracting(GenerativeObject::generated)
.allSatisfy(obj -> {
Assertions.assertThat(obj).as("uuid shorthand")
.returns(obj.uuid(), GenerativeObject::uuid);
Assertions.assertThat(obj).as("vectors shorthand")
.returns(obj.vectors(), GenerativeObject::vectors);
})
.extracting(GenerativeObject::generative)
.allSatisfy(generated -> {
Assertions.assertThat(generated.text()).isNotBlank();
});

Assertions.assertThat(french.generated())
Assertions.assertThat(french.generative())
.as("summary")
.extracting(TaskOutput::text, InstanceOfAssertFactories.STRING)
.isNotBlank();
Expand Down Expand Up @@ -655,14 +661,14 @@ public void testGenerative_bm25_groupBy() throws IOException {
.describedAs("objects in group %s", groupName)
.hasSize(1);

Assertions.assertThat(group.generated())
Assertions.assertThat(group.generative())
.describedAs("summary group %s", groupName)
.extracting(TaskOutput::text, InstanceOfAssertFactories.STRING)
.isNotBlank();

});

Assertions.assertThat(french.generated())
Assertions.assertThat(french.generative())
.as("summary")
.extracting(TaskOutput::text, InstanceOfAssertFactories.STRING)
.isNotBlank();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ public static Generative awsBedrock(String region, String model,
/**
* Configure a default {@code generative-aws} module with Sagemaker integration.
*
* @param region AWS region.
* @param baseUrl Base inference URL.
* @param region AWS region.
* @param endpoint Base inference URL.
*/
public static Generative awsSagemaker(String region, String baseUrl) {
return AwsGenerative.sagemaker(region, baseUrl);
public static Generative awsSagemaker(String region, String endpoint) {
return AwsGenerative.sagemaker(region, endpoint);
}

/**
* Configure a {@code generative-aws} module with Sagemaker integration.
*
* @param region AWS region.
* @param baseUrl Base inference URL.
* @param fn Lambda expression for optional parameters.
* @param region AWS region.
* @param endpoint Base inference URL.
* @param fn Lambda expression for optional parameters.
*/
public static Generative awsSagemaker(String region, String baseUrl,
public static Generative awsSagemaker(String region, String endpoint,
Function<AwsGenerative.SagemakerBuilder, ObjectBuilder<AwsGenerative>> fn) {
return AwsGenerative.sagemaker(region, baseUrl, fn);
return AwsGenerative.sagemaker(region, endpoint, fn);
}

/** Configure a default {@code generative-cohere} module. */
Expand All @@ -154,21 +154,21 @@ public static Generative cohere(Function<CohereGenerative.Builder, ObjectBuilder
/**
* Configure a default {@code generative-databricks} module.
*
* @param baseURL Base URL for the generative service.
* @param endpoint Base URL for the generative service.
*/
public static Generative databricks(String baseURL) {
return DatabricksGenerative.of(baseURL);
public static Generative databricks(String endpoint) {
return DatabricksGenerative.of(endpoint);
}

/**
* Configure a {@code generative-databricks} module.
*
* @param baseURL Base URL for the generative service.
* @param fn Lambda expression for optional parameters.
* @param endpoint Base URL for the generative service.
* @param fn Lambda expression for optional parameters.
*/
public static Generative databricks(String baseURL,
public static Generative databricks(String endpoint,
Function<DatabricksGenerative.Builder, ObjectBuilder<DatabricksGenerative>> fn) {
return DatabricksGenerative.of(baseURL, fn);
return DatabricksGenerative.of(endpoint, fn);
}

/** Configure a default {@code generative-frienliai} module. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,48 +619,48 @@ public static Map.Entry<String, VectorConfig> text2vecAwsBedrock(String vectorNa
* Create a vector index with an {@code text2vec-aws} vectorizer with Sagemaker
* integration.
*
* @param baseUrl Base URL of the inference service.
* @param endpoint Base URL of the inference service.
*/
public static Map.Entry<String, VectorConfig> text2vecAwsSagemaker(String baseUrl) {
return text2vecAwsSagemaker(VectorIndex.DEFAULT_VECTOR_NAME, baseUrl);
public static Map.Entry<String, VectorConfig> text2vecAwsSagemaker(String endpoint) {
return text2vecAwsSagemaker(VectorIndex.DEFAULT_VECTOR_NAME, endpoint);
}

/**
* Create a vector index with an {@code text2vec-aws} vectorizer with Sagemaker
* integration.
*
* @param baseUrl Base URL of the inference service.
* @param fn Lambda expression for optional parameters.
* @param endpoint Base URL of the inference service.
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, VectorConfig> text2vecAwsSagemaker(
String baseUrl,
String endpoint,
Function<Text2VecAwsVectorizer.SagemakerBuilder, ObjectBuilder<Text2VecAwsVectorizer>> fn) {
return text2vecAwsSagemaker(VectorIndex.DEFAULT_VECTOR_NAME, baseUrl, fn);
return text2vecAwsSagemaker(VectorIndex.DEFAULT_VECTOR_NAME, endpoint, fn);
}

/**
* Create a named vector index with an {@code text2vec-aws}
* vectorizer with Sagemaker integration.
*
* @param vectorName Vector name.
* @param baseUrl Base URL of the inference service.
* @param endpoint Base URL of the inference service.
*/
public static Map.Entry<String, VectorConfig> text2vecAwsSagemaker(String vectorName, String baseUrl) {
return Map.entry(vectorName, Text2VecAwsVectorizer.sagemaker(baseUrl));
public static Map.Entry<String, VectorConfig> text2vecAwsSagemaker(String vectorName, String endpoint) {
return Map.entry(vectorName, Text2VecAwsVectorizer.sagemaker(endpoint));
}

/**
* Create a named vector index with an {@code text2vec-aws}
* vectorizer with Sagemaker integration.
*
* @param vectorName Vector name.
* @param baseUrl Base URL of the inference service.
* @param endpoint Base URL of the inference service.
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, VectorConfig> text2vecAwsSagemaker(String vectorName,
String baseUrl,
String endpoint,
Function<Text2VecAwsVectorizer.SagemakerBuilder, ObjectBuilder<Text2VecAwsVectorizer>> fn) {
return Map.entry(vectorName, Text2VecAwsVectorizer.sagemaker(baseUrl, fn));
return Map.entry(vectorName, Text2VecAwsVectorizer.sagemaker(endpoint, fn));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public record WeaviateObject<P, R, M extends WeaviateMetadata>(
Map<String, List<R>> references,
M metadata) {

/** Shorthand for accesing objects's UUID from metadata. */
/** Shorthand for accessing objects's UUID from metadata. */
public String uuid() {
return metadata.uuid();
}

/** Shorthand for accesing objects's vectors from metadata. */
/** Shorthand for accessing objects's vectors from metadata. */
public Vectors vectors() {
return metadata.vectors();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public WeaviateObject<PropertiesT, Object, ObjectMetadata> insert(InsertObjectRe
}

public boolean exists(String uuid) {
return this.query.byId(uuid).isPresent();
return this.query.fetchObjectById(uuid).isPresent();
}

public void update(String uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CompletableFuture<InsertManyResponse> insertMany(InsertManyRequest<Proper
}

public CompletableFuture<Boolean> exists(String uuid) {
return this.query.byId(uuid).thenApply(Optional::isPresent);
return this.query.fetchObjectById(uuid).thenApply(Optional::isPresent);
}

public CompletableFuture<Void> update(String uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public static DynamicProvider awsBedrock(
/**
* Configure {@code generative-aws} as a dynamic provider.
*
* @param region AWS region.
* @param baseUrl Base inference URL.
* @param fn Lambda expression for optional parameters.
* @param region AWS region.
* @param endpoint Base inference URL.
* @param fn Lambda expression for optional parameters.
*/
public static DynamicProvider awsSagemaker(
String region,
String baseUrl,
String endpoint,
Function<AwsGenerative.Provider.SagemakerBuilder, ObjectBuilder<AwsGenerative.Provider>> fn) {
return AwsGenerative.Provider.sagemaker(region, baseUrl, fn);
return AwsGenerative.Provider.sagemaker(region, endpoint, fn);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package io.weaviate.client6.v1.api.collections.generate;

import io.weaviate.client6.v1.api.collections.Vectors;
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;

public record GenerativeObject<PropertiesT>(
/** Object properties. */
PropertiesT properties,
/** Object metadata. */
QueryMetadata metadata,
/** Generative task output. */
TaskOutput generated) {
/** Object properties. */
PropertiesT properties,
/** Object metadata. */
QueryMetadata metadata,
/** Generative task output. */
TaskOutput generative) {

/** Shorthand for accessing objects's UUID from metadata. */
public String uuid() {
return metadata.uuid();
}

/** Shorthand for accessing objects's vectors from metadata. */
public Vectors vectors() {
return metadata.vectors();
}
}
Loading