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
14 changes: 9 additions & 5 deletions _includes/code/csharp/QuickstartLocalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,25 @@ public async Task FullQuickstartWorkflowTest()
);
}

// Call InsertMany with the list of objects converted to an array
var insertResponse = await questions.Data.InsertMany(questionsToInsert.ToArray());
// `Batch.InsertMany` imports the list using server-side batching
var insertResponse = await questions.Batch.InsertMany(questionsToInsert);
// highlight-end
// END Import

// Check for errors
if (insertResponse.HasErrors)
{
Console.WriteLine($"Number of failed imports: {insertResponse.Errors.Count()}");
Console.WriteLine($"First failed object error: {insertResponse.Errors.First()}");
// `Objects` holds one entry per object; `Index` is the position of the object in the input
foreach (var entry in insertResponse.Objects.Where(o => o.Error is not null))
{
Console.WriteLine($"Failed object at index {entry.Index}: {entry.Error.Message}");
}
}
else
{
Console.WriteLine($"Successfully inserted {insertResponse.Objects.Count()} objects.");
Console.WriteLine($"Successfully inserted {insertResponse.Count} objects.");
}
// END Import

// START NearText
// highlight-start
Expand Down
14 changes: 9 additions & 5 deletions _includes/code/csharp/QuickstartTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,25 @@ public static async Task FullQuickstartWorkflowTest()
);
}

// Call InsertMany with the list of objects converted to an array
var insertResponse = await questions.Data.InsertMany(questionsToInsert.ToArray());
// `Batch.InsertMany` imports the list using server-side batching
var insertResponse = await questions.Batch.InsertMany(questionsToInsert);
// highlight-end
// END Import

// Check for errors
if (insertResponse.HasErrors)
{
Console.WriteLine($"Number of failed imports: {insertResponse.Errors.Count()}");
Console.WriteLine($"First failed object error: {insertResponse.Errors.First()}");
// `Objects` holds one entry per object; `Index` is the position of the object in the input
foreach (var entry in insertResponse.Objects.Where(o => o.Error is not null))
{
Console.WriteLine($"Failed object at index {entry.Index}: {entry.Error.Message}");
}
}
else
{
Console.WriteLine($"Successfully inserted {insertResponse.Objects.Count()} objects.");
Console.WriteLine($"Successfully inserted {insertResponse.Count} objects.");
}
// END Import

// START NearText
// highlight-start
Expand Down
4 changes: 2 additions & 2 deletions _includes/code/csharp/quickstart/QuickstartCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public static async Task Run()
},
};

// Insert objects using InsertMany
var insertResponse = await movies.Data.InsertMany(dataObjects.ToArray());
// Insert the objects using server-side batching
var insertResponse = await movies.Batch.InsertMany(dataObjects);

if (insertResponse.HasErrors)
{
Expand Down
4 changes: 2 additions & 2 deletions _includes/code/csharp/quickstart/QuickstartCreateVectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public static async Task Run()
),
};

// Insert the objects with vectors
var insertResponse = await movies.Data.InsertMany(dataToInsert);
// Insert the objects with vectors using server-side batching
var insertResponse = await movies.Batch.InsertMany(dataToInsert);

if (insertResponse.HasErrors)
{
Expand Down
4 changes: 2 additions & 2 deletions _includes/code/csharp/quickstart/QuickstartLocalCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static async Task Run()
},
};

// Insert objects using InsertMany
var insertResponse = await movies.Data.InsertMany(dataObjects.ToArray());
// Insert the objects using server-side batching
var insertResponse = await movies.Batch.InsertMany(dataObjects);

if (insertResponse.HasErrors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public static async Task Run()
),
};

// Insert the objects with vectors
var insertResponse = await movies.Data.InsertMany(dataToInsert);
// Insert the objects with vectors using server-side batching
var insertResponse = await movies.Batch.InsertMany(dataToInsert);
if (insertResponse.HasErrors)
{
Console.WriteLine($"Errors during import: {insertResponse.Errors}");
Expand Down
20 changes: 13 additions & 7 deletions _includes/code/java-v6/src/test/java/QuickstartLocalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import io.weaviate.client6.v1.api.collections.Generative;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.VectorConfig;
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.batch.BatchContext;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -94,16 +95,21 @@ void testImportDataWorkflow() throws Exception {
questionsToInsert.add(properties);
});

// Call insertMany with the list of objects
InsertManyResponse insertResponse = questions.data.insertMany(questionsToInsert.toArray(new Map[0]));
// `batch.start()` opens a server-side batch
BatchContext<Map<String, Object>> batch = questions.batch.start();
// Closing the batch sends the remaining objects and waits for the results
try (batch) {
for (Map<String, Object> properties : questionsToInsert) {
batch.add(WeaviateObject.<Map<String, Object>>of(o -> o.properties(properties)));
}
}
// highlight-end

// Check for errors
if (!insertResponse.errors().isEmpty()) {
System.err.printf("Number of failed imports: %d\n", insertResponse.errors().size());
System.err.printf("First failed object error: %s\n", insertResponse.errors().get(0));
if (batch.numberOfErrors() > 0) {
System.err.printf("Number of failed imports: %d\n", batch.numberOfErrors());
} else {
System.out.printf("Successfully inserted %d objects.\n", insertResponse.uuids().size());
System.out.printf("Successfully inserted %d objects.\n", questionsToInsert.size());
}
// END Import
// client.collections.delete(collectionName);
Expand Down
20 changes: 13 additions & 7 deletions _includes/code/java-v6/src/test/java/QuickstartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import io.weaviate.client6.v1.api.collections.Generative;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.VectorConfig;
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.batch.BatchContext;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -115,16 +116,21 @@ void testImportDataWorkflow() throws Exception {
questionsToInsert.add(properties);
});

// Call insertMany with the list of objects
InsertManyResponse insertResponse = questions.data.insertMany(questionsToInsert.toArray(new Map[0]));
// `batch.start()` opens a server-side batch
BatchContext<Map<String, Object>> batch = questions.batch.start();
// Closing the batch sends the remaining objects and waits for the results
try (batch) {
for (Map<String, Object> properties : questionsToInsert) {
batch.add(WeaviateObject.<Map<String, Object>>of(o -> o.properties(properties)));
}
}
// highlight-end

// Check for errors
if (!insertResponse.errors().isEmpty()) {
System.err.printf("Number of failed imports: %d\n", insertResponse.errors().size());
System.err.printf("First failed object error: %s\n", insertResponse.errors().get(0));
if (batch.numberOfErrors() > 0) {
System.err.printf("Number of failed imports: %d\n", batch.numberOfErrors());
} else {
System.out.printf("Successfully inserted %d objects.\n", insertResponse.uuids().size());
System.out.printf("Successfully inserted %d objects.\n", questionsToInsert.size());
}
// END Import
// client.collections.delete(collectionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import io.weaviate.client6.v1.api.collections.CollectionHandle;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.VectorConfig;
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.batch.BatchContext;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -54,18 +55,24 @@ public static void main(String[] args) throws Exception {
"A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.",
"genre", "Fantasy"));

// Insert objects using insertMany
// Insert the objects using server-side batching
CollectionHandle<Map<String, Object>> movies =
client.collections.use(collectionName);
InsertManyResponse insertResponse =
movies.data.insertMany(dataObjects.toArray(new Map[0]));
BatchContext<Map<String, Object>> batch = movies.batch.start();
// Closing the batch sends the remaining objects and waits for the results
try (batch) {
for (Map<String, Object> properties : dataObjects) {
batch.add(
WeaviateObject.<Map<String, Object>>of(o -> o.properties(properties)));
}
}

if (!insertResponse.errors().isEmpty()) {
System.err.println("Errors during import: " + insertResponse.errors());
if (batch.numberOfErrors() > 0) {
System.err
.println("Number of failed imports: " + batch.numberOfErrors());
} else {
System.out
.println("Imported & vectorized " + insertResponse.uuids().size()
+ " objects into the Movie collection");
System.out.println("Imported & vectorized " + dataObjects.size()
+ " objects into the Movie collection");
}
} finally {
if (client != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import io.weaviate.client6.v1.api.collections.VectorConfig;
import io.weaviate.client6.v1.api.collections.Vectors;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse;
import io.weaviate.client6.v1.api.collections.batch.BatchContext;
import java.util.List;
import java.util.Map;

public class QuickstartCreateVectors {
Expand Down Expand Up @@ -63,20 +64,30 @@ public static void main(String[] args) throws Exception {
float[] vector3 =
new float[] {0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f};

// Insert the objects with vectors
// Insert the objects with vectors using server-side batching
CollectionHandle<Map<String, Object>> movies =
client.collections.use(collectionName);
InsertManyResponse insertResponse = movies.data.insertMany(
List<WeaviateObject<Map<String, Object>>> objectsToInsert = List.of(
WeaviateObject.of(v -> v.properties(props1)
.vectors(Vectors.of(vector1))),
WeaviateObject.of(v -> v.properties(props2)
.vectors(Vectors.of(vector2))),
WeaviateObject.of(v -> v.properties(props3)
.vectors(Vectors.of(vector3))));
if (!insertResponse.errors().isEmpty()) {
System.err.println("Errors during import: " + insertResponse.errors());

BatchContext<Map<String, Object>> batch = movies.batch.start();
// Closing the batch sends the remaining objects and waits for the results
try (batch) {
for (WeaviateObject<Map<String, Object>> object : objectsToInsert) {
batch.add(object);
}
}

if (batch.numberOfErrors() > 0) {
System.err
.println("Number of failed imports: " + batch.numberOfErrors());
} else {
System.out.println("Imported " + insertResponse.uuids().size()
System.out.println("Imported " + objectsToInsert.size()
+ " objects with vectors into the Movie collection");
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import io.weaviate.client6.v1.api.collections.CollectionHandle;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.VectorConfig;
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.batch.BatchContext;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -53,18 +54,24 @@ public static void main(String[] args) throws Exception {
"A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.",
"genre", "Fantasy"));

// Insert objects using insertMany
// Insert the objects using server-side batching
CollectionHandle<Map<String, Object>> movies =
client.collections.use(collectionName);
InsertManyResponse insertResponse =
movies.data.insertMany(dataObjects.toArray(new Map[0]));
BatchContext<Map<String, Object>> batch = movies.batch.start();
// Closing the batch sends the remaining objects and waits for the results
try (batch) {
for (Map<String, Object> properties : dataObjects) {
batch.add(
WeaviateObject.<Map<String, Object>>of(o -> o.properties(properties)));
}
}

if (!insertResponse.errors().isEmpty()) {
System.err.println("Errors during import: " + insertResponse.errors());
if (batch.numberOfErrors() > 0) {
System.err
.println("Number of failed imports: " + batch.numberOfErrors());
} else {
System.out
.println("Imported & vectorized " + insertResponse.uuids().size()
+ " objects into the Movie collection");
System.out.println("Imported & vectorized " + dataObjects.size()
+ " objects into the Movie collection");
}
} finally {
if (client != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import io.weaviate.client6.v1.api.collections.VectorConfig;
import io.weaviate.client6.v1.api.collections.Vectors;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse;
import io.weaviate.client6.v1.api.collections.batch.BatchContext;
import java.util.List;
import java.util.Map;

public class QuickstartLocalCreateVectors {
Expand Down Expand Up @@ -59,21 +60,30 @@ public static void main(String[] args) throws Exception {
float[] vector3 =
new float[] {0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f};

// Insert the objects with vectors
// Insert the objects with vectors using server-side batching
CollectionHandle<Map<String, Object>> movies =
client.collections.use(collectionName);
InsertManyResponse insertResponse = movies.data.insertMany(
List<WeaviateObject<Map<String, Object>>> objectsToInsert = List.of(
WeaviateObject.of(v -> v.properties(props1)
.vectors(Vectors.of(vector1))),
WeaviateObject.of(v -> v.properties(props2)
.vectors(Vectors.of(vector2))),
WeaviateObject.of(v -> v.properties(props3)
.vectors(Vectors.of(vector3))));

if (!insertResponse.errors().isEmpty()) {
System.err.println("Errors during import: " + insertResponse.errors());
BatchContext<Map<String, Object>> batch = movies.batch.start();
// Closing the batch sends the remaining objects and waits for the results
try (batch) {
for (WeaviateObject<Map<String, Object>> object : objectsToInsert) {
batch.add(object);
}
}

if (batch.numberOfErrors() > 0) {
System.err
.println("Number of failed imports: " + batch.numberOfErrors());
} else {
System.out.println("Imported " + insertResponse.uuids().size()
System.out.println("Imported " + objectsToInsert.size()
+ " objects with vectors into the Movie collection");
}
} finally {
Expand Down
4 changes: 1 addition & 3 deletions _includes/code/llms-txt/python/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
movies = client.collections.use("Movie__QuickstartPy")

# Import objects
with movies.batch.fixed_size(batch_size=200) as batch:
for obj in data_objects:
batch.add_object(properties=obj)
movies.data.ingest(data_objects)

print(f"Imported & vectorized {len(data_objects)} objects into the Movie collection")

Expand Down
2 changes: 1 addition & 1 deletion _includes/code/llms-txt/typescript/quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (!(await client.collections.exists('Movie__QuickstartTs'))) {
const movies = client.collections.use('Movie__QuickstartTs');

// Import objects
await movies.data.insertMany(dataObjects);
await movies.data.ingest(dataObjects.map((properties) => ({ properties })));

console.log(`Imported & vectorized ${dataObjects.length} objects into the Movie collection`);

Expand Down
Loading
Loading