|
6 | 6 | import io.stargate.sdk.json.domain.Filter; |
7 | 7 | import io.stargate.sdk.json.domain.SelectQuery; |
8 | 8 | import io.stargate.sdk.json.domain.odm.Result; |
9 | | - |
10 | 9 | import java.util.List; |
11 | 10 | import java.util.Optional; |
12 | 11 |
|
13 | 12 | public class ObjectMappingFindVector { |
14 | | - static class Product { |
15 | | - @JsonProperty("product_name") private String name; |
16 | | - @JsonProperty("product_price") private Double price; |
17 | | - } |
| 13 | + static class Product { |
| 14 | + @JsonProperty("product_name") private String name; |
| 15 | + @JsonProperty("product_price") private Double price; |
| 16 | + } |
18 | 17 |
|
19 | | - public static void main(String[] args) { |
20 | | - AstraDB db = new AstraDB("<token>", "<api_endpoint>"); |
21 | | - AstraDBRepository<Product> productRepository = db |
22 | | - .createCollection("collection_vector1", 14, Product.class); |
| 18 | + public static void main(String[] args) { |
| 19 | + AstraDB db = new AstraDB("<token>", "<api_endpoint>"); |
| 20 | + AstraDBRepository<Product> productRepository = |
| 21 | + db.createCollection("collection_vector1", 14, Product.class); |
23 | 22 |
|
24 | | - // Perform a semantic search |
25 | | - float[] embeddings = new float[]{1f, 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}; |
26 | | - Filter metadataFilter = new Filter().where("product_price").isEqualsTo(9.99); |
27 | | - int maxRecord = 10; |
28 | | - List<Result<Product>> res = productRepository.findVector(embeddings, metadataFilter, maxRecord); |
| 23 | + // Perform a semantic search |
| 24 | + float[] embeddings = new float[]{1f, 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}; |
| 25 | + Filter metadataFilter = new Filter().where("product_price").isEqualsTo(9.99); |
| 26 | + int maxRecord = 10; |
| 27 | + List<Result<Product>> res = productRepository.findVector(embeddings, metadataFilter, maxRecord); |
29 | 28 |
|
30 | | - // If you do not have max record or metadata filter, you can use the following |
31 | | - productRepository.findVector(embeddings, maxRecord); |
32 | | - productRepository.findVector(embeddings, metadataFilter); |
33 | | - } |
| 29 | + // If you do not have max record or metadata filter, you can use the following |
| 30 | + productRepository.findVector(embeddings, maxRecord); |
| 31 | + productRepository.findVector(embeddings, metadataFilter); |
| 32 | + } |
34 | 33 | } |
0 commit comments