|
3 | 3 | import com.dtsx.astra.sdk.AstraDB; |
4 | 4 | import com.dtsx.astra.sdk.AstraDBCollection; |
5 | 5 | import io.stargate.sdk.json.domain.JsonDocument; |
6 | | - |
7 | 6 | import java.util.List; |
8 | 7 |
|
9 | 8 | public class InsertMany { |
10 | | - public static void main(String[] args) { |
11 | | - |
12 | | -// Given an active db and a collection with a vector field (see CreateCollection.java) |
13 | | -AstraDB db = new AstraDB("<token>", "<api_endpoint>"); |
14 | | - |
15 | | -// Create collection if not exists |
16 | | -AstraDBCollection collection = db |
17 | | - .createCollection("collection_vector1",14); |
| 9 | + public static void main(String[] args) { |
| 10 | + AstraDB db = new AstraDB("<token>", "<api_endpoint>"); |
| 11 | + AstraDBCollection collection = db.createCollection("collection_vector1",14); |
18 | 12 |
|
19 | | -// Insert documents, ids are generated here |
20 | | -List<String> identifiers = collection.insertMany(List.of( |
21 | | - new JsonDocument() |
22 | | - .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
23 | | - .put("product_name", "Yet another product") |
24 | | - .put("product_price", 99.99), |
25 | | - new JsonDocument() |
26 | | - .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
27 | | - .put("product_name", "product3") |
28 | | - .put("product_price", 99.99))); |
29 | | - |
30 | | -} |
| 13 | + // Insert documents into the collection (IDs are generated automatically) |
| 14 | + List<String> identifiers = collection.insertMany(List.of( |
| 15 | + new JsonDocument() |
| 16 | + .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
| 17 | + .put("product_name", "Yet another product") |
| 18 | + .put("product_price", 99.99), |
| 19 | + new JsonDocument() |
| 20 | + .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
| 21 | + .put("product_name", "product3") |
| 22 | + .put("product_price", 99.99))); |
| 23 | + } |
31 | 24 | } |
0 commit comments