From f30ce222108ddafa5ff38e9fff36f6c9f587c437 Mon Sep 17 00:00:00 2001 From: clun Date: Wed, 11 Oct 2023 18:21:58 +0200 Subject: [PATCH] Getting ready --- README.md | 6 +- ...ository.java => CollectionRepository.java} | 148 +++++++++----- .../sdk/json/JsonCollectionClient.java | 96 +++++----- .../sdk/json/JsonNamespaceClient.java | 16 +- .../sdk/json/domain/FilterBuilder.java | 2 +- .../sdk/json/domain/JsonApiResponse.java | 5 + .../{JsonRecord.java => JsonDocument.java} | 25 ++- .../stargate/sdk/json/domain/JsonResult.java | 1 - .../sdk/json/domain/SelectQueryBuilder.java | 4 - .../stargate/sdk/json/domain/UpdateQuery.java | 5 +- .../sdk/json/domain/UpdateQueryBuilder.java | 4 +- .../sdk/json/domain/odm/Document.java | 114 +++++++++++ .../stargate/sdk/json/domain/odm/Record.java | 55 ------ .../stargate/sdk/json/domain/odm/Result.java | 37 ++++ .../{RecordMapper.java => ResultMapper.java} | 5 +- .../sdk/json/vector/VectorEmbeddings.java | 25 --- .../stargate/sdk/json/vector/VectorStore.java | 36 +++- stargate-sdk-test/pom.xml | 12 +- .../AbstractJsonClientNamespacesTest.java | 30 +-- .../stargate/test/json/HFDatasetClient.java | 39 ---- .../io/stargate/test/json/HFDatasetPage.java | 55 ------ ...spacesTest.java => JsonApiClientTest.java} | 13 +- .../io/stargate/test/json/LoadQuotes.java | 94 --------- .../json/VectorClientPhilosopherTest.java | 180 +++++++++++++++--- ...Test.java => VectorClientProductTest.java} | 130 +++++++------ .../src/test/resources/philosopher-quotes.csv | 2 +- 26 files changed, 614 insertions(+), 525 deletions(-) rename stargate-sdk-json/src/main/java/io/stargate/sdk/json/{JsonApiRepository.java => CollectionRepository.java} (60%) rename stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/{JsonRecord.java => JsonDocument.java} (85%) create mode 100644 stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Document.java delete mode 100644 stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Record.java create mode 100644 stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Result.java rename stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/{RecordMapper.java => ResultMapper.java} (78%) delete mode 100644 stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorEmbeddings.java delete mode 100644 stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetClient.java delete mode 100644 stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetPage.java rename stargate-sdk-test/src/test/java/io/stargate/test/json/{JsonClientNamespacesTest.java => JsonApiClientTest.java} (91%) delete mode 100644 stargate-sdk-test/src/test/java/io/stargate/test/json/LoadQuotes.java rename stargate-sdk-test/src/test/java/io/stargate/test/json/{JsonClientApiDemoTest.java => VectorClientProductTest.java} (52%) diff --git a/README.md b/README.md index 36019fa..ea66ca1 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ videoTable.upsert(data); data.put("title", "title2"); demoTable.upsert(data); -// Delete a record -KeyClient record = demoTable.key("Sci-Fi", 1990); -record.delete(); +// Delete a document +KeyClient document = demoTable.key("Sci-Fi", 1990); +document.delete(); // Search table (by PK) RowResultPage res1 = demoTable.search( diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonApiRepository.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/CollectionRepository.java similarity index 60% rename from stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonApiRepository.java rename to stargate-sdk-json/src/main/java/io/stargate/sdk/json/CollectionRepository.java index 7409a20..5584511 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonApiRepository.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/CollectionRepository.java @@ -3,14 +3,15 @@ import io.stargate.sdk.core.domain.Page; import io.stargate.sdk.json.domain.DeleteQuery; import io.stargate.sdk.json.domain.Filter; -import io.stargate.sdk.json.domain.JsonRecord; +import io.stargate.sdk.json.domain.JsonDocument; import io.stargate.sdk.json.domain.JsonResultUpdate; import io.stargate.sdk.json.domain.SelectQuery; import io.stargate.sdk.json.domain.UpdateQuery; -import io.stargate.sdk.json.domain.odm.Record; +import io.stargate.sdk.json.domain.odm.Document; +import io.stargate.sdk.json.domain.odm.Result; import lombok.NonNull; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -21,8 +22,9 @@ * Crud repository with Json Api * * @param + * current bean */ -public class JsonApiRepository { +public class CollectionRepository { protected final JsonCollectionClient collectionClient; @@ -37,7 +39,7 @@ public class JsonApiRepository { * @param clazz * working bean class */ - public JsonApiRepository(JsonCollectionClient col, Class clazz) { + public CollectionRepository(JsonCollectionClient col, Class clazz) { this.collectionClient = col; this.docClass = clazz; } @@ -63,9 +65,21 @@ public boolean exists(String id) { } // -------------------------- - // --- Save ---- + // --- insertOne ---- // -------------------------- + /** + * Insert with a Json Document. + * + * @param jsonDocument + * current bean + * @return + * new id + */ + public final String insert(@NonNull JsonDocument jsonDocument) { + return collectionClient.insertOne(jsonDocument); + } + /** * Create a new document a generating identifier. * @param current @@ -73,7 +87,7 @@ public boolean exists(String id) { * @return * generated id */ - public final String create(@NonNull BEAN current) { + public final String insert(@NonNull BEAN current) { return collectionClient.insertOne(current, null); } @@ -85,10 +99,26 @@ public final String create(@NonNull BEAN current) { * @return * generated id */ - public final String create( @NonNull String id, @NonNull BEAN current) { + public final String insert( @NonNull String id, @NonNull BEAN current) { return collectionClient.insertOne(id, current, null); } + /** + * Insert with a Json Document. + * + * @param bean + * current bean + * @return + * new id + */ + public final String insert(@NonNull Document bean) { + return collectionClient.insertOne(bean.toJsonDocument()); + } + + // -------------------------- + // --- SaveOne ---- + // -------------------------- + /** * Generate a new document with a new id. * @@ -98,7 +128,7 @@ public final String create( @NonNull String id, @NonNull BEAN current) { * generated id */ public final String save(@NonNull BEAN current) { - return create(current); + return insert(current); } /** @@ -112,14 +142,14 @@ public final String save(@NonNull BEAN current) { */ public boolean save(String id, @NonNull BEAN current) { if (!exists(id)) { - create(id, current); + insert(id, current); return true; } JsonResultUpdate res = collectionClient .findOneAndReplace(UpdateQuery.builder() .where("_id") .isEqualsTo(id) - .replaceBy(new JsonRecord(id, current)) + .replaceBy(new JsonDocument(id, current)) .build()); return res.getUpdateStatus().getModifiedCount() > 0; } @@ -132,41 +162,54 @@ public boolean save(String id, @NonNull BEAN current) { * @return * an unique identifier for the document */ - public final String save(@NonNull Record current) { - if (current.getId() != null && !exists(current.getId())) { - create(current.getId(), current.getData()); + public final String save(@NonNull Document current) { + String id = current.getId(); + if (id == null || !exists(id)) { + return collectionClient.insertOne(current.getId(), current.getData(), current.getVector()); } + // Already Exist + collectionClient.findOneAndReplace(UpdateQuery.builder() + .where("_id") + .isEqualsTo(id) + .replaceBy(current.toJsonDocument()) + .build()); + return id; + } - - return collectionClient.insertOne(current.asJsonRecord()); + public final String save(@NonNull JsonDocument current) { + String id = current.getId(); + if (id == null || !exists(id)) { + return collectionClient.insertOne(current.getId(), current.getData(), current.getVector()); + } + // Already Exist + collectionClient.findOneAndReplace(UpdateQuery.builder() + .where("_id") + .isEqualsTo(id) + .replaceBy(current) + .build()); + return id; } + // -------------------------- + // --- saveAll ---- + // -------------------------- + /** * Create a new document a generating identifier. * - * @param current + * @param documentList * object Mapping * @return * an unique identifier for the document */ - public final int saveAll(@NonNull Record current) { - //if (current.getId() != null) return save(current.getId(), current.getData()); - //return collectionClient.insertOne(current.asJsonRecord()); - return 0; + public final List saveAll(@NonNull List> documentList) { + if (documentList.isEmpty()) return new ArrayList<>(); + return documentList.stream().map(this::save).collect(Collectors.toList()); } - /** - * Low level insertion of multiple records - * - * @param records - * list of records - * @return - * list of ids - */ - @SafeVarargs - public final Stream createAll(Record... records) { - if (records == null || records.length == 0) return Stream.empty(); - return createAll(Arrays.asList(records)); + public final List saveAllJsonDocuments(@NonNull List documentList) { + if (documentList.isEmpty()) return new ArrayList<>(); + return documentList.stream().map(this::save).collect(Collectors.toList()); } /** @@ -177,13 +220,20 @@ public final Stream createAll(Record... records) { * @return * list of ids */ - public final Stream createAll(List> documents) { - if (documents == null || documents.isEmpty()) return Stream.empty(); + public final List insertAll(List> documents) { + if (documents == null || documents.isEmpty()) return new ArrayList<>(); return collectionClient.insertMany(documents.stream() - .map(Record::asJsonRecord) + .map(Document::toJsonDocument) .collect(Collectors.toList())); } + public final List insertAllJsonDocuments(@NonNull List documentList) { + if (documentList.isEmpty()) return new ArrayList<>(); + return collectionClient.insertMany(documentList); + } + + + // -------------------------- // --- Count ---- // -------------------------- @@ -220,7 +270,7 @@ public final int count(Filter jsonFilter) { * @return * object if presents */ - public Optional> findOne(@NonNull SelectQuery query) { + public Optional> findOne(@NonNull SelectQuery query) { return collectionClient.findOne(query, docClass); } @@ -232,7 +282,7 @@ public Optional> findOne(@NonNull SelectQuery query) { * @return * object if presents */ - public Optional> findById(@NonNull String id) { + public Optional> findById(@NonNull String id) { return collectionClient.findById(id, docClass); } @@ -242,7 +292,7 @@ public Optional> findById(@NonNull String id) { * @return * retrieve all items */ - public Stream> findAll() { + public Stream> findAll() { return collectionClient.findAll(docClass); } @@ -252,8 +302,8 @@ public Stream> findAll() { * @return * retrieve all items */ - public Stream> findAll(SelectQuery query) { - return collectionClient.findAll(query, docClass); + public Stream> findAll(SelectQuery query) { + return collectionClient.query(query, docClass); } /** @@ -264,17 +314,17 @@ public Stream> findAll(SelectQuery query) { * @return * page of records */ - public Page> findPage(SelectQuery query) { - return collectionClient.findPage(query, docClass); + public Page> findPage(SelectQuery query) { + return collectionClient.queryForPage(query, docClass); } // -------------------------- // --- Delete ---- // -------------------------- - public boolean delete(@NonNull Record record) { - if (record.getId() != null) return deleteById(record.getId()); - if (record.getVector() != null) return collectionClient.deleteByVector(record.getVector()) > 0; + public boolean delete(@NonNull Document document) { + if (document.getId() != null) return deleteById(document.getId()); + if (document.getVector() != null) return collectionClient.deleteByVector(document.getVector()) > 0; throw new IllegalArgumentException("Cannot delete record without id or vector"); } @@ -289,13 +339,13 @@ public int deleteAll() { /** * Use parallelism and async to delete all records. * - * @param records + * @param documents * list of records * @return * number of records deleted */ - public int deleteAll(List> records) { - List> futures = records.stream() + public int deleteAll(List> documents) { + List> futures = documents.stream() .map(record -> CompletableFuture.supplyAsync(() -> delete(record) ? 1 : 0)) .collect(Collectors.toList()); return futures.stream() diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonCollectionClient.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonCollectionClient.java index 443b137..3c11e10 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonCollectionClient.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonCollectionClient.java @@ -4,17 +4,18 @@ import io.stargate.sdk.http.LoadBalancedHttpClient; import io.stargate.sdk.http.ServiceHttp; import io.stargate.sdk.json.domain.DeleteQuery; +import io.stargate.sdk.json.domain.Filter; import io.stargate.sdk.json.domain.JsonApiData; import io.stargate.sdk.json.domain.JsonApiResponse; -import io.stargate.sdk.json.domain.Filter; -import io.stargate.sdk.json.domain.JsonRecord; +import io.stargate.sdk.json.domain.JsonDocument; import io.stargate.sdk.json.domain.JsonResult; import io.stargate.sdk.json.domain.JsonResultUpdate; import io.stargate.sdk.json.domain.SelectQuery; import io.stargate.sdk.json.domain.UpdateQuery; import io.stargate.sdk.json.domain.UpdateStatus; -import io.stargate.sdk.json.domain.odm.Record; -import io.stargate.sdk.json.domain.odm.RecordMapper; +import io.stargate.sdk.json.domain.odm.Document; +import io.stargate.sdk.json.domain.odm.Result; +import io.stargate.sdk.json.domain.odm.ResultMapper; import io.stargate.sdk.utils.Assert; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; @@ -127,7 +128,26 @@ public String insertOne(Object bean, float[] vector) { */ public String insertOne(String id, Object bean, float[] vector) { log.debug("insert into {}/{}", green(namespace), green(collection)); - return execute("insertOne", Map.of("document", new JsonRecord(id, bean, vector))) + JsonDocument jsonDocument = new JsonDocument(id, bean, vector); + if (bean instanceof JsonDocument) { + jsonDocument = (JsonDocument) bean; + if (id != null) { + jsonDocument.id(id); + } + if (vector != null) { + jsonDocument.vector(vector); + } + } + if (bean instanceof Document) { + jsonDocument = ((Document) bean).toJsonDocument(); + if (id != null) { + jsonDocument.id(id); + } + if (vector != null) { + jsonDocument.vector(vector); + } + } + return execute("insertOne", Map.of("document", jsonDocument)) .getStatusKeyAsStream("insertedIds") .findAny() .orElse(null); @@ -145,22 +165,10 @@ public String insertOne(String id, Object bean, float[] vector) { * @return * list of ids */ - public final Stream insertMany(JsonRecord... documents) { - Objects.requireNonNull(documents, "documents"); - return insertMany(List.of(documents)); - } - /** - * Low level insertion of multiple records - * - * @param documents - * list of documents - * @return - * list of ids - */ - public final Stream insertMany(List documents) { + public final List insertMany(List documents) { Objects.requireNonNull(documents, "documents"); log.debug("insert into {}/{}", green(namespace), green(collection)); - return execute("insertMany", Map.of("documents", documents)).getStatusKeyAsStream("insertedIds"); + return execute("insertMany", Map.of("documents", documents)).getStatusKeyAsList("insertedIds"); } // -------------------------- @@ -215,8 +223,8 @@ public Optional findOne(SelectQuery query) { * @return * result if exists */ - public Optional> findOne(SelectQuery query, Class clazz) { - return findOne(query).map(r -> new Record<>(r, clazz)); + public Optional> findOne(SelectQuery query, Class clazz) { + return findOne(query).map(r -> new Result<>(r, clazz)); } /** @@ -227,7 +235,7 @@ public Optional> findOne(SelectQuery query, Class clazz) { * @return * result if exists */ - public Optional> findOne(SelectQuery query, RecordMapper mapper) { + public Optional> findOne(SelectQuery query, ResultMapper mapper) { return findOne(query).map(mapper::map); } @@ -239,11 +247,11 @@ public Optional findById(String id) { return findOne(SelectQuery.findById(id)); } - public Optional> findById(@NonNull String id, Class clazz) { - return findById(id).map(r -> new Record<>(r, clazz)); + public Optional> findById(@NonNull String id, Class clazz) { + return findById(id).map(r -> new Result<>(r, clazz)); } - public Optional> findById(@NonNull String id, RecordMapper mapper) { + public Optional> findById(@NonNull String id, ResultMapper mapper) { return findById(id).map(mapper::map); } @@ -255,11 +263,11 @@ public Optional findOneByVector(float[] vector) { return findOne(SelectQuery.findByVector(vector)); } - public Optional> findOneByVector(float[] vector, Class clazz) { - return findOneByVector(vector).map(r -> new Record<>(r, clazz)); + public Optional> findOneByVector(float[] vector, Class clazz) { + return findOneByVector(vector).map(r -> new Result<>(r, clazz)); } - public Optional> findOneByVector(float[] vector, RecordMapper mapper) { + public Optional> findOneByVector(float[] vector, ResultMapper mapper) { return findOneByVector(vector).map(mapper::map); } @@ -274,7 +282,7 @@ public Optional> findOneByVector(float[] vector, RecordMapper m * all items */ public Stream findAll() { - return findAll(SelectQuery.builder().build()); + return query(SelectQuery.builder().build()); } /** @@ -284,13 +292,13 @@ public Stream findAll() { * @return * all items */ - public Stream findAll(SelectQuery pageQuery) { + public Stream query(SelectQuery pageQuery) { List documents = new ArrayList<>(); String pageState = null; AtomicInteger pageCount = new AtomicInteger(0); do { log.debug("Fetching page " + pageCount.incrementAndGet()); - Page pageX = findPage(pageQuery); + Page pageX = queryForPage(pageQuery); if (pageX.getPageState().isPresent()) { pageState = pageX.getPageState().get(); } else { @@ -303,12 +311,12 @@ public Stream findAll(SelectQuery pageQuery) { return documents.stream(); } - public Stream> findAll(SelectQuery pageQuery, Class clazz) { - return findAll(pageQuery).map(r -> new Record<>(r, clazz)); + public Stream> query(SelectQuery pageQuery, Class clazz) { + return query(pageQuery).map(r -> new Result<>(r, clazz)); } - public Stream> findAll(SelectQuery pageQuery, RecordMapper mapper) { - return findAll(pageQuery).map(mapper::map); + public Stream> query(SelectQuery pageQuery, ResultMapper mapper) { + return query(pageQuery).map(mapper::map); } /** @@ -321,11 +329,11 @@ public Stream> findAll(SelectQuery pageQuery, RecordMapper ma * @param * class to be marshalled */ - public Stream> findAll(Class clazz) { - return findAll().map(r -> new Record<>(r, clazz)); + public Stream> findAll(Class clazz) { + return findAll().map(r -> new Result<>(r, clazz)); } - public Stream> findAll(RecordMapper mapper) { + public Stream> findAll(ResultMapper mapper) { return findAll().map(mapper::map); } @@ -337,26 +345,26 @@ public Stream> findAll(RecordMapper mapper) { * @return * page of results */ - public Page findPage(SelectQuery query) { + public Page queryForPage(SelectQuery query) { log.debug("Query in {}/{}", green(namespace), green(collection)); JsonApiData apiData = execute("find", query).getData(); int pageSize = (query != null) ? query.getPageSize() : SelectQuery.DEFAULT_PAGE_SIZE; return new Page<>(pageSize, apiData.getNextPageState(), apiData.getDocuments()); } - public Page> findPage(SelectQuery query, Class clazz) { - Page pageJson = findPage(query); + public Page> queryForPage(SelectQuery query, Class clazz) { + Page pageJson = queryForPage(query); return new Page<>( pageJson.getPageSize(), pageJson.getPageState().orElse(null), pageJson.getResults() .stream() - .map(r -> new Record<>(r, clazz)) + .map(r -> new Result<>(r, clazz)) .collect(Collectors.toList())); } - private Page> findPage(SelectQuery query, RecordMapper mapper) { - Page pageJson = findPage(query); + private Page> queryForPage(SelectQuery query, ResultMapper mapper) { + Page pageJson = queryForPage(query); return new Page<>( pageJson.getPageSize(), pageJson.getPageState().orElse(null), diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonNamespaceClient.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonNamespaceClient.java index 7ec3fbd..26873f9 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonNamespaceClient.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/JsonNamespaceClient.java @@ -94,7 +94,7 @@ public void createCollection(String collection) { * @param dimension * dimension of the vector */ - public void createCollectionVector(String collection, int dimension) { + public void createCollection(String collection, int dimension) { this.createCollection(CollectionDefinition.builder() .name(collection) .vector(dimension, @@ -111,7 +111,7 @@ public void createCollectionVector(String collection, int dimension) { * @param metric * similarity metric */ - public void createCollectionVector(String collection, int dimension, SimilarityMetric metric) { + public void createCollection(String collection, int dimension, SimilarityMetric metric) { this.createCollection(CollectionDefinition.builder() .name(collection) .vector(dimension, metric).build()); @@ -131,7 +131,7 @@ public void createCollectionVector(String collection, int dimension, SimilarityM * @param model * model to be used */ - public void createCollectionVector(String collection, int dimension, SimilarityMetric metric, String llm, String model) { + public void createCollection(String collection, int dimension, SimilarityMetric metric, String llm, String model) { this.createCollection(CollectionDefinition.builder() .name(collection) .vector(dimension, metric) @@ -190,6 +190,15 @@ public JsonCollectionClient collection(String collectionName) { return new JsonCollectionClient(stargateHttpClient, namespace, collectionName); } + public CollectionRepository repository(String collectionName) { + return repository(collectionName, ObjectMap.class); + } + + public CollectionRepository repository(String collectionName, Class clazz) { + if (!existCollection(collectionName)) throw new CollectionNotFoundException(collectionName); + return new CollectionRepository<>(collection(collectionName), clazz); + } + /** * Vector store with object mapping and native function. * @@ -203,6 +212,7 @@ public JsonCollectionClient collection(String collectionName) { * type parameter */ public VectorStore vectorStore(String collectionName, Class recordClass) { + if (!existCollection(collectionName)) throw new CollectionNotFoundException(collectionName); return new VectorStore<>(collection(collectionName), recordClass); } diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/FilterBuilder.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/FilterBuilder.java index 69596c3..134983a 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/FilterBuilder.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/FilterBuilder.java @@ -81,7 +81,7 @@ public Filter isEqualsTo(Object value) { * @return * self reference */ - public Filter isAnArrayContaining(Object[] value) { + public Filter isAnArrayContaining(Object... value) { return simpleOperator(FilterOperator.EQUALS_TO, value); } diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonApiResponse.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonApiResponse.java index 292219c..407a251 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonApiResponse.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonApiResponse.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import java.util.stream.Stream; @Data @@ -45,6 +46,10 @@ public Stream getStatusKeyAsStream(@NonNull String key) { return Stream.empty(); } + public List getStatusKeyAsList(@NonNull String key) { + return getStatusKeyAsStream(key).collect(Collectors.toList()); + } + /** * Syntax sugar. diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonRecord.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonDocument.java similarity index 85% rename from stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonRecord.java rename to stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonDocument.java index 0b4aa4c..aecfb1e 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonRecord.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonDocument.java @@ -24,7 +24,6 @@ import lombok.NonNull; import lombok.Setter; -import java.util.Arrays; import java.util.Map; @@ -32,7 +31,7 @@ * Json Api Payload. */ @Getter @Setter -public class JsonRecord extends AbstractJsonRecord { +public class JsonDocument extends AbstractJsonRecord { /** * Data for inputs. @@ -44,7 +43,7 @@ public class JsonRecord extends AbstractJsonRecord { /** * Default constructor. */ - public JsonRecord() {} + public JsonDocument() {} /** * Constructor with id. @@ -52,7 +51,7 @@ public JsonRecord() {} * @param id * identifier */ - public JsonRecord(String id) { + public JsonDocument(String id) { this(id, null, null); } @@ -64,7 +63,7 @@ public JsonRecord(String id) { * @param data * data as a map */ - public JsonRecord(String id, Map data) { + public JsonDocument(String id, Map data) { this(id, data, null); } @@ -76,7 +75,7 @@ public JsonRecord(String id, Map data) { * @param bean * data as a beam */ - public JsonRecord(String id, Object bean) { + public JsonDocument(String id, Object bean) { this(id, bean, null); } @@ -90,7 +89,7 @@ public JsonRecord(String id, Object bean) { * @param vector * vector */ - public JsonRecord(String id, Map data, float[] vector) { + public JsonDocument(String id, Map data, float[] vector) { this.id = id; this.vector = vector; this.data = asObjectMap(data); @@ -106,7 +105,7 @@ public JsonRecord(String id, Map data, float[] vector) { * @param vector * vector */ - public JsonRecord(String id, Object bean, float[] vector) { + public JsonDocument(String id, Object bean, float[] vector) { this.id = id; this.vector = vector; this.data = asObjectMap(bean); @@ -147,7 +146,7 @@ private ObjectMap asObjectMap(Object bean) { * @return * new JsonRecord */ - public JsonRecord id(String id) { + public JsonDocument id(String id) { this.id = id; return this; } @@ -162,7 +161,7 @@ public JsonRecord id(String id) { * @return * self reference */ - public JsonRecord put(String key, Object value) { + public JsonDocument put(String key, Object value) { if (null == data) data = new ObjectMap(); data.put(key, value); return this; @@ -176,7 +175,7 @@ public JsonRecord put(String key, Object value) { * @return * self reference */ - public JsonRecord data(@NonNull Object bean) { + public JsonDocument data(@NonNull Object bean) { this.data = asObjectMap(bean); return this; } @@ -189,7 +188,7 @@ public JsonRecord data(@NonNull Object bean) { * @return * self reference */ - public JsonRecord data(@NonNull Map map) { + public JsonDocument data(@NonNull Map map) { this.data = asObjectMap(map); return this; } @@ -202,7 +201,7 @@ public JsonRecord data(@NonNull Map map) { * @return * self reference */ - public JsonRecord vector(float[] vector) { + public JsonDocument vector(float[] vector) { this.vector = vector; return this; } diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonResult.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonResult.java index c2ace0b..ea7f2a5 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonResult.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/JsonResult.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import io.stargate.sdk.json.domain.JsonRecord; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/SelectQueryBuilder.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/SelectQueryBuilder.java index 66d3ba0..1e8b9a8 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/SelectQueryBuilder.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/SelectQueryBuilder.java @@ -65,10 +65,6 @@ public SelectQueryBuilder orderBy(String key, Object value) { return this; } - public SelectQueryBuilder orderByAnn(Float... vector) { - return orderBy(FilterKeyword.VECTOR.getKeyword(), vector); - } - public SelectQueryBuilder orderByAnn(float... vector) { return orderBy(FilterKeyword.VECTOR.getKeyword(), vector); } diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQuery.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQuery.java index ea2ef1f..f07929e 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQuery.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQuery.java @@ -1,11 +1,8 @@ package io.stargate.sdk.json.domain; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Getter; -import lombok.NonNull; -import java.util.HashMap; import java.util.Map; /** @@ -23,7 +20,7 @@ public class UpdateQuery { private Map update; - private JsonRecord replacement; + private JsonDocument replacement; /** * Default constructor. diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQueryBuilder.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQueryBuilder.java index 617f2f0..ef309de 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQueryBuilder.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/UpdateQueryBuilder.java @@ -169,9 +169,9 @@ public UpdateQueryFilterBuilder andWhere(String fieldName) { /** * replacement recod */ - public JsonRecord replacement; + public JsonDocument replacement; - public UpdateQueryBuilder replaceBy(JsonRecord replacement) { + public UpdateQueryBuilder replaceBy(JsonDocument replacement) { this.replacement = replacement; return this; } diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Document.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Document.java new file mode 100644 index 0000000..3d37264 --- /dev/null +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Document.java @@ -0,0 +1,114 @@ +package io.stargate.sdk.json.domain.odm; + +import io.stargate.sdk.json.domain.JsonDocument; +import io.stargate.sdk.utils.JsonUtils; +import lombok.Data; + +/** + * Working with entities. + * + * @param + * type of bean in use + */ +@Data +public class Document { + + /** + * Row id for a vector + */ + protected String id; + + /** + * Metadata for a vector + */ + protected T data; + + /** + * Embeddings + */ + protected float[] vector; + + + /** + * Default constructor. + */ + public Document() {} + + /** + * Default document. + * + * @param record + * current json record + * @param clazz + * class + */ + public Document(JsonDocument record, Class clazz) { + this.id = record.getId(); + this.data = JsonUtils.convertValue(record.getData(), clazz); + this.vector = record.getVector(); + } + + /** + * Default document. + * + * @param bean + * current payload + */ + public Document(T bean) { + this(null, bean, null); + } + + /** + * Default document. + * + * @param id + * identifier + * @param bean + * current payload + */ + public Document(String id, T bean) { + this(id, bean, null); + } + + /** + * Default document. + * + * @param id + * identifier + * @param bean + * current payload + * @param vector + * vector embeddings + */ + public Document(String id, T bean, float[] vector) { + this.id = id; + this.data = bean; + this.vector = vector; + } + + /** + * Static initialization. + * + * @param result + * json result + * @param clazz + * current class + * @return + * document + * @param + * typed object + */ + public static Document of(JsonDocument result, Class clazz) { + return new Document(result, clazz); + } + + /** + * Mapping with internal layer. + * + * @return + * json record + */ + public JsonDocument toJsonDocument() { + return new JsonDocument(id, data, vector); + } +} diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Record.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Record.java deleted file mode 100644 index a8c252e..0000000 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Record.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.stargate.sdk.json.domain.odm; - -import io.stargate.sdk.json.domain.JsonRecord; -import io.stargate.sdk.json.domain.JsonResult; -import io.stargate.sdk.utils.JsonUtils; -import lombok.Data; - -import java.util.List; - -/** - * Working with entities. - * - * @param - * type of bean in use - */ -@Data -public class Record { - - /** - * Row id for a vector - */ - protected String id; - - /** - * Metadata for a vector - */ - protected T data; - - /** - * Embeddings - */ - protected float[] vector; - - /** - * Similarity - */ - protected Float similarity; - - public Record(JsonResult result, Class clazz) { - this.id = result.getId(); - this.data = JsonUtils.convertValue(result.getData(), clazz); - this.vector = result.getVector(); - this.similarity = result.getSimilarity(); - } - - /** - * Mapping with internal layer. - * - * @return - * json record - */ - public JsonRecord asJsonRecord() { - return new JsonRecord(id, data, vector); - } -} diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Result.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Result.java new file mode 100644 index 0000000..7cf7300 --- /dev/null +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/Result.java @@ -0,0 +1,37 @@ +package io.stargate.sdk.json.domain.odm; + +import io.stargate.sdk.json.domain.JsonResult; +import io.stargate.sdk.utils.JsonUtils; + +public class Result extends Document { + + /** + * Using an object, can be null + */ + protected Float similarity; + + /** + * Default constructor. + */ + public Result() {} + + public Result(JsonResult result, Class clazz) { + this.id = result.getId(); + this.data = JsonUtils.convertValue(result.getData(), clazz); + this.vector = result.getVector(); + this.similarity = result.getSimilarity(); + } + + public static Result of(JsonResult result, Class clazz) { + return new Result<>(result, clazz); + } + + /** + * Gets similarity + * + * @return value of similarity + */ + public Float getSimilarity() { + return similarity; + } +} diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/RecordMapper.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/ResultMapper.java similarity index 78% rename from stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/RecordMapper.java rename to stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/ResultMapper.java index e5c0121..f8a4612 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/RecordMapper.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/domain/odm/ResultMapper.java @@ -1,6 +1,5 @@ package io.stargate.sdk.json.domain.odm; -import io.stargate.sdk.json.domain.JsonRecord; import io.stargate.sdk.json.domain.JsonResult; /** @@ -10,7 +9,7 @@ * working bean */ @FunctionalInterface -public interface RecordMapper { +public interface ResultMapper { /** * Extension point for the user to implement its own parser for a record. @@ -20,6 +19,6 @@ public interface RecordMapper { * @return * the object marshalled */ - Record map(JsonResult record); + Result map(JsonResult record); } \ No newline at end of file diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorEmbeddings.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorEmbeddings.java deleted file mode 100644 index f70fbe5..0000000 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorEmbeddings.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.stargate.sdk.json.vector; - -import java.util.List; - -/** - * Vector Embeddings. - */ -public class VectorEmbeddings { - - public static float[] of(List embeddings) { - float[] vector = new float[embeddings.size()]; - for (int i = 0; i < embeddings.size(); i++) { - vector[i] = embeddings.get(i); - } - return vector; - } - - public static float[] of(Float[] embeddings) { - float[] vector = new float[embeddings.length]; - for (int i = 0; i < embeddings.length; i++) { - vector[i] = embeddings[i]; - } - return vector; - } -} diff --git a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorStore.java b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorStore.java index b0a51e6..2fec699 100644 --- a/stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorStore.java +++ b/stargate-sdk-json/src/main/java/io/stargate/sdk/json/vector/VectorStore.java @@ -1,18 +1,18 @@ package io.stargate.sdk.json.vector; import io.stargate.sdk.core.domain.Page; -import io.stargate.sdk.json.JsonApiRepository; +import io.stargate.sdk.json.CollectionRepository; import io.stargate.sdk.json.JsonCollectionClient; import io.stargate.sdk.json.domain.Filter; -import io.stargate.sdk.json.domain.JsonRecord; +import io.stargate.sdk.json.domain.JsonDocument; import io.stargate.sdk.json.domain.JsonResultUpdate; import io.stargate.sdk.json.domain.SelectQuery; import io.stargate.sdk.json.domain.SelectQueryBuilder; import io.stargate.sdk.json.domain.UpdateQuery; -import io.stargate.sdk.json.domain.odm.Record; +import io.stargate.sdk.json.domain.odm.Result; import lombok.NonNull; -import java.util.List; +import java.util.HashMap; import java.util.Optional; /** @@ -21,7 +21,7 @@ * @param * curren vector object */ -public class VectorStore extends JsonApiRepository { +public class VectorStore extends CollectionRepository { /** * Default constructor. @@ -36,7 +36,7 @@ public VectorStore(JsonCollectionClient col, Class clazz) { } // -------------------------- - // --- Create ---- + // --- Insert ---- // -------------------------- /** @@ -68,6 +68,10 @@ public String insert(@NonNull BEAN current, float[] vector) { return collectionClient.insertOne(current, vector); } + // -------------------------- + // --- save ---- + // -------------------------- + /** * Generate a new document with a new id. * @@ -98,7 +102,7 @@ public boolean save(String id, @NonNull BEAN current, float[] vector) { .findOneAndReplace(UpdateQuery.builder() .where("_id") .isEqualsTo(id) - .replaceBy(new JsonRecord(id, current, vector)) + .replaceBy(new JsonDocument(id, current, vector)) .build()); return res.getUpdateStatus().getModifiedCount() > 0; } @@ -115,7 +119,7 @@ public boolean save(String id, @NonNull BEAN current, float[] vector) { * @return * object if presents */ - public Optional> findByVector(@NonNull float[] embeddings) { + public Optional> findByVector(@NonNull float[] embeddings) { return collectionClient.findOneByVector(embeddings, docClass); } @@ -123,15 +127,27 @@ public boolean deleteByVector(float[] vector) { return collectionClient.deleteByVector(vector) > 0; } - public Page> annSearch(float[] embeddings, Filter filter, Integer limit) { + public Page> similaritySearch(float[] embeddings) { + return similaritySearch(embeddings, null, null); + } + + public Page> similaritySearch(float[] embeddings, Integer limit) { + return similaritySearch(embeddings, null, limit); + } + + public Page> similaritySearch(float[] embeddings, Filter filter, Integer limit) { SelectQueryBuilder builder = SelectQuery.builder().orderByAnn(embeddings); if (filter != null) { + if (builder.filter == null) { + builder.filter = new HashMap<>(); + } builder.filter.putAll(filter.getFilter()); } + builder.withIncludeSimilarity(); if (limit!=null) { builder.limit(limit); } - return collectionClient.findPage(builder.build(), docClass); + return collectionClient.queryForPage(builder.build(), docClass); } } diff --git a/stargate-sdk-test/pom.xml b/stargate-sdk-test/pom.xml index 6660720..7439299 100644 --- a/stargate-sdk-test/pom.xml +++ b/stargate-sdk-test/pom.xml @@ -34,31 +34,29 @@ logback-classic test - - dev.langchain4j - langchain4j-hugging-face - 0.23.0 - dev.langchain4j langchain4j-open-ai 0.23.0 + test + diff --git a/stargate-sdk-test/src/main/java/io/stargate/sdk/test/json/AbstractJsonClientNamespacesTest.java b/stargate-sdk-test/src/main/java/io/stargate/sdk/test/json/AbstractJsonClientNamespacesTest.java index f26e27f..c7d242e 100644 --- a/stargate-sdk-test/src/main/java/io/stargate/sdk/test/json/AbstractJsonClientNamespacesTest.java +++ b/stargate-sdk-test/src/main/java/io/stargate/sdk/test/json/AbstractJsonClientNamespacesTest.java @@ -6,7 +6,7 @@ import io.stargate.sdk.json.JsonNamespaceClient; import io.stargate.sdk.json.domain.CollectionDefinition; import io.stargate.sdk.json.domain.Filter; -import io.stargate.sdk.json.domain.JsonRecord; +import io.stargate.sdk.json.domain.JsonDocument; import io.stargate.sdk.json.domain.NamespaceDefinition; import lombok.AllArgsConstructor; import lombok.Getter; @@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -140,7 +140,7 @@ public void shouldCreateCollectionWithVector() { .vector(14, cosine) .build()); jsonApiClient.namespace(TEST_NAMESPACE_1) - .createCollectionVector("tmp_vector", 14, cosine); + .createCollection("tmp_vector", 14, cosine); // Then Assertions.assertTrue(nsClient.existCollection(TEST_COLLECTION_VECTOR)); Assertions.assertTrue(nsClient.existCollection("tmp_vector")); @@ -162,7 +162,7 @@ public void shouldCreateCollectionVectorize() { // Then Assertions.assertTrue(nsClient.existCollection(TEST_COLLECTION_VECTORIZE)); - nsClient.createCollectionVector("tmp_vectorize", 14, + nsClient.createCollection("tmp_vectorize", 14, cosine, "openai", "gpt3.5-turbo"); } @@ -205,7 +205,7 @@ public void shouldInsertOne() { col.insertOne("id3", "{\"key\": \"value\"}"); // fine-grained json - col.insertOne(new JsonRecord("pf1844").put("attribute", "test")); + col.insertOne(new JsonDocument("pf1844").put("attribute", "test")); } @Test @@ -213,7 +213,7 @@ public void shouldInsertOne() { @DisplayName("10.Insert One Vector") public void shouldInsertOneVector() { JsonNamespaceClient ns = jsonApiClient.namespace(TEST_NAMESPACE_1); - ns.createCollectionVector(TEST_COLLECTION_VECTOR, 14, cosine); + ns.createCollection(TEST_COLLECTION_VECTOR, 14, cosine); // Insert with a Json record => KV access JsonCollectionClient colVector = ns.collection(TEST_COLLECTION_VECTOR); @@ -233,7 +233,7 @@ public void shouldInsertOneVector() { new float[] {1f, 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}); // Insert a full-fledged object - colVector.insertOne(new JsonRecord() + colVector.insertOne(new JsonDocument() .id("pf2000") .put("attribute", "test") .vector(new float[] {1f, 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f})); @@ -255,27 +255,27 @@ public void shouldInsertMany() { .namespace(TEST_NAMESPACE_1) .collection(TEST_COLLECTION_VECTOR); - myCollection.insertMany( - new JsonRecord() + myCollection.insertMany(List.of( + new JsonDocument() .id("pf1844") .data(new Product("HealthyFresh - Beef raw dog food", 9.99)) .vector(new float[] {1f, 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}), - new JsonRecord("pt0021") + new JsonDocument("pt0021") .data("{ \"product_name\": \"Dog Tennis Ball Toy\" }") .vector(new float[] {0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 1f, 1f, 0f, 0f}), - new JsonRecord() + new JsonDocument() .id("pf1843") .data(Map.of("product_name", "HealthyFresh - Chicken raw dog food")) .vector(new float[] {1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}), - new JsonRecord("pt0041") + new JsonDocument("pt0041") .put("product_name", "Dog Ring Chew Toy") .vector(new float[] {0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f, 1f, 1f, 0f, 0f, 0f, 0f}), - new JsonRecord("pf7043", new Product("Pepper Sausage Bacon dog Treats", 9.99)) + new JsonDocument("pf7043", new Product("Pepper Sausage Bacon dog Treats", 9.99)) .vector(new float[] {0f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 1f}), - new JsonRecord() + new JsonDocument() .id("pf7044") .data(new Product("Pepper Sausage Beef dog Treats", 10.99)) - .vector(new float[] {0f, 0f, 0f, 1f, 0f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f}) + .vector(new float[] {0f, 0f, 0f, 1f, 0f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f})) ); } diff --git a/stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetClient.java b/stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetClient.java deleted file mode 100644 index 20fb47e..0000000 --- a/stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetClient.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.stargate.test.json; - - -import io.stargate.sdk.utils.JsonUtils; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.time.Duration; - -public class HFDatasetClient { - - public static final String ENDPOINT_BASE = "https://datasets-server.huggingface.co/rows"; - - public static String buildEndpoint(String org, String dataset, String split, int offset, int limit) { - - return String.format("%s?dataset=%s%%2F%s&config=default&split=%s&offset=%d&limit=%d", ENDPOINT_BASE, org, dataset, split, offset, limit); - } - - @Test - public void shoulShowDataset() throws IOException, InterruptedException { - HttpClient httpClient = HttpClient.newBuilder() - .version(HttpClient.Version.HTTP_2) - .followRedirects(HttpClient.Redirect.NORMAL) - .connectTimeout(Duration.ofSeconds(20)) - .build(); - - String url = buildEndpoint("datastax", "philosophers-quotes", "train", 0, 100); - - HttpRequest request = HttpRequest.newBuilder().GET().uri(URI.create(url)).build(); - HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); - HFDatasetPage hfDataSet = JsonUtils.unmarshallBean(response.body(), HFDatasetPage.class); - System.out.println(hfDataSet.getNumRowsTotal()); - } - -} diff --git a/stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetPage.java b/stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetPage.java deleted file mode 100644 index 9276f24..0000000 --- a/stargate-sdk-test/src/test/java/io/stargate/test/json/HFDatasetPage.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.stargate.test.json; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; -import java.util.Map; - -@Data @NoArgsConstructor -public class HFDatasetPage { - - private List features; - - private List rows; - - @JsonProperty("num_rows_total") - private int numRowsTotal; - - @JsonProperty("num_rows_per_page") - private int numRowsPerPage; - - // Getters, setters, and default constructor - - @Data @NoArgsConstructor - public static class Feature { - - @JsonProperty("feature_idx") - private int featureIdx; - - private String name; - - private Type type; - - @Data @NoArgsConstructor - public static class Type { - - private String dtype; - - @JsonProperty("_type") - private String type; - } - } - - @Data @NoArgsConstructor - public static class RowData { - - @JsonProperty("row_idx") - private int rowIdx; - private Map row; - - @JsonProperty("truncated_cells") - private List truncatedCells; - } -} diff --git a/stargate-sdk-test/src/test/java/io/stargate/test/json/JsonClientNamespacesTest.java b/stargate-sdk-test/src/test/java/io/stargate/test/json/JsonApiClientTest.java similarity index 91% rename from stargate-sdk-test/src/test/java/io/stargate/test/json/JsonClientNamespacesTest.java rename to stargate-sdk-test/src/test/java/io/stargate/test/json/JsonApiClientTest.java index 6909754..9c20b85 100644 --- a/stargate-sdk-test/src/test/java/io/stargate/test/json/JsonClientNamespacesTest.java +++ b/stargate-sdk-test/src/test/java/io/stargate/test/json/JsonApiClientTest.java @@ -8,7 +8,8 @@ import io.stargate.sdk.json.domain.SelectQuery; import io.stargate.sdk.json.domain.UpdateQuery; import io.stargate.sdk.json.domain.UpdateQueryBuilder; -import io.stargate.sdk.json.domain.odm.Record; +import io.stargate.sdk.json.domain.odm.Document; +import io.stargate.sdk.json.domain.odm.Result; import io.stargate.sdk.test.json.AbstractJsonClientNamespacesTest; import io.stargate.sdk.utils.JsonUtils; import org.junit.jupiter.api.Assertions; @@ -23,7 +24,7 @@ /** * Default settings (localhost:8180). */ -public class JsonClientNamespacesTest extends AbstractJsonClientNamespacesTest { +public class JsonApiClientTest extends AbstractJsonClientNamespacesTest { @BeforeAll public static void initStargateRestApiClient() { jsonApiClient = new JsonApiClient(); @@ -64,7 +65,7 @@ public void testFindOneVector() { Assertions.assertTrue(opt.isPresent()); System.out.println(opt.get()); - Record vector = new Record<>(colClient.findById("pf1844").get(), Product.class); + Result vector = new Result<>(colClient.findById("pf1844").get(), Product.class); } @Test @@ -74,7 +75,7 @@ public void testFindMany() { .namespace(TEST_NAMESPACE_1) .collection(TEST_COLLECTION_VECTOR); - Page page = colClient.findPage(SelectQuery.builder() + Page page = colClient.queryForPage(SelectQuery.builder() // Projection //.selectVector() //.selectSimilarity() @@ -106,7 +107,7 @@ public void testFindWithPaging() { JsonCollectionClient col1 = jsonApiClient .namespace(TEST_NAMESPACE_1) .collection(TEST_COLLECTION); - Page resultSet = col1.findPage(SelectQuery.builder().build()); + Page resultSet = col1.queryForPage(SelectQuery.builder().build()); System.out.println("Page 1: state=" + resultSet.getPageState()); for(JsonResult result : resultSet.getResults()) { System.out.println(result.toString()); @@ -120,7 +121,7 @@ public void testFindAll() { .namespace(TEST_NAMESPACE_1) .collection(TEST_COLLECTION); System.out.println(col1.countDocuments()); - Stream resultSet = col1.findAll(SelectQuery.builder().build()); + Stream resultSet = col1.query(SelectQuery.builder().build()); System.out.println(resultSet.count()); } diff --git a/stargate-sdk-test/src/test/java/io/stargate/test/json/LoadQuotes.java b/stargate-sdk-test/src/test/java/io/stargate/test/json/LoadQuotes.java deleted file mode 100644 index 954df98..0000000 --- a/stargate-sdk-test/src/test/java/io/stargate/test/json/LoadQuotes.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.stargate.test.json; - -import dev.langchain4j.data.embedding.Embedding; -import dev.langchain4j.data.message.AiMessage; -import dev.langchain4j.model.huggingface.HuggingFaceChatModel; -import dev.langchain4j.model.huggingface.HuggingFaceEmbeddingModel; -import lombok.AllArgsConstructor; -import lombok.Data; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Scanner; -import java.util.Set; -import static dev.langchain4j.model.huggingface.HuggingFaceModelName.TII_UAE_FALCON_7B_INSTRUCT; -import static java.time.Duration.ofSeconds; -import static dev.langchain4j.data.message.SystemMessage.systemMessage; -import static dev.langchain4j.data.message.UserMessage.userMessage; - -public class LoadQuotes { - - @Data @AllArgsConstructor - private static class Quote { - private String philosopher; - private String quote; - private Set tags; - } - - public List loadQuotes(String filePath) { - List quotes = new ArrayList<>(); - File csvFile = new File(LoadQuotes.class.getResource(filePath).getFile()); - try (Scanner scanner = new Scanner(csvFile)) { - while (scanner.hasNextLine()) { - quotes.add(mapCsvLine(scanner.nextLine())); - } - } catch (FileNotFoundException fex) { - throw new IllegalArgumentException("file is not in the classpath", fex); - } - return quotes; - } - - private Quote mapCsvLine(String line) { - String[] parts = line.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1); - if (parts.length >= 3) { - String author = parts[0]; - String quote = parts[1].replaceAll("\"", ""); - Set tags = new HashSet<>(Arrays.asList(parts[2].split("\\;"))); - return new Quote(author, quote, tags); - } - return null; - } - - @Test - public void shouldLoadCsv() throws IOException { - loadQuotes("/philosopher-quotes.csv") - .forEach(q -> System.out.println(q.getPhilosopher() + " - " + q.getQuote() + " - " + q.getTags())); - } - - @Test - public void embeddingHuggingFace() { - HuggingFaceEmbeddingModel model = HuggingFaceEmbeddingModel.builder() - .accessToken(System.getenv("HF_API_KEY")) - .modelId("sentence-transformers/all-MiniLM-L6-v2") - .build(); - Embedding embedding = model.embed("This is a demo embeddings").content(); - System.out.println(embedding.dimensions()); - System.out.println(Arrays.toString(embedding.vector())); - } - - @Test - public void generativeAiLlama2() { - HuggingFaceChatModel model = HuggingFaceChatModel.builder() - .accessToken(System.getenv("HF_API_KEY")) - .modelId(TII_UAE_FALCON_7B_INSTRUCT) - .timeout(ofSeconds(15)) - .temperature(0.7) - .maxNewTokens(20) - .waitForModel(true) - .build(); - - AiMessage aiMessage = model.generate( - systemMessage("You are a good friend of mine, who likes to answer with jokes"), - userMessage("Hey Bro, what are you doing?") - ).content(); - System.out.println(aiMessage.text()); - } - - -} diff --git a/stargate-sdk-test/src/test/java/io/stargate/test/json/VectorClientPhilosopherTest.java b/stargate-sdk-test/src/test/java/io/stargate/test/json/VectorClientPhilosopherTest.java index d61cbf7..2ff94d1 100644 --- a/stargate-sdk-test/src/test/java/io/stargate/test/json/VectorClientPhilosopherTest.java +++ b/stargate-sdk-test/src/test/java/io/stargate/test/json/VectorClientPhilosopherTest.java @@ -1,46 +1,58 @@ package io.stargate.test.json; -import dev.langchain4j.model.huggingface.HuggingFaceEmbeddingModel; +import dev.langchain4j.data.message.AiMessage; +import dev.langchain4j.model.chat.ChatLanguageModel; +import dev.langchain4j.model.input.Prompt; +import dev.langchain4j.model.input.PromptTemplate; +import dev.langchain4j.model.openai.OpenAiChatModel; import dev.langchain4j.model.openai.OpenAiEmbeddingModel; import dev.langchain4j.model.openai.OpenAiModelName; -import io.stargate.sdk.core.domain.Page; +import dev.langchain4j.model.output.Response; import io.stargate.sdk.json.JsonApiClient; -import io.stargate.sdk.json.domain.odm.Record; +import io.stargate.sdk.json.JsonNamespaceClient; +import io.stargate.sdk.json.domain.Filter; +import io.stargate.sdk.json.domain.odm.Document; import io.stargate.sdk.json.vector.SimilarityMetric; import io.stargate.sdk.json.vector.VectorStore; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import java.io.File; import java.io.FileNotFoundException; import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Scanner; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +/** + * Philosopher Demo with Vector Client. + */ +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class VectorClientPhilosopherTest { - @Data @AllArgsConstructor + @Data @AllArgsConstructor @NoArgsConstructor private static class Quote { private String philosopher; private String quote; private Set tags; } - static HuggingFaceEmbeddingModel huggingFaceModel = HuggingFaceEmbeddingModel.builder() - .accessToken(System.getenv("HF_API_KEY")) - .modelId("sentence-transformers/all-MiniLM-L6-v2") - .build(); - - public static float[] vectorizeWithHuggingFace(String inputText) { - return huggingFaceModel.embed(inputText).content().vector(); - } + // OpenAI Usual Suspects - static OpenAiEmbeddingModel openAIModel = OpenAiEmbeddingModel.builder() + static OpenAiEmbeddingModel openaiVectorizer = OpenAiEmbeddingModel.builder() .apiKey(System.getenv("OPENAI_API_KEY")) .modelName(OpenAiModelName.TEXT_EMBEDDING_ADA_002) .timeout(Duration.ofSeconds(15)) @@ -48,38 +60,148 @@ public static float[] vectorizeWithHuggingFace(String inputText) { .logResponses(true) .build(); - public static float[] vectorizeWithOpenAi(String inputText) { - return huggingFaceModel.embed(inputText).content().vector(); + public static float[] vectorize(String inputText) { + return openaiVectorizer.embed(inputText).content().vector(); } + public static VectorStore vectorStore; + @Test - public void shouldUseVectorClientLocal() { + @Order(1) + @DisplayName("01. Create a namespace and a collection") + public void init() { // Initialization JsonApiClient jsonApiClient = new JsonApiClient(); - jsonApiClient - .createNamespace("vector3") - .createCollectionVector("philosophers", 384, SimilarityMetric.cosine); + JsonNamespaceClient nsClient = jsonApiClient.createNamespace("vector_openai"); + nsClient.deleteCollection("philosophers"); + nsClient.createCollection("philosophers", 1536, SimilarityMetric.cosine); - // Initializing vector store with object mapping - VectorStore vectorStore = jsonApiClient - .namespace("vector3") + // Low level client + jsonApiClient.namespace("vector_openai").collection("philosophers"); + + // Crud Repository on a Collection + jsonApiClient.namespace("vector_openai").repository("philosophers", Quote.class); + + // Vector = crud repository + vector native + vectorStore = jsonApiClient + .namespace("vector_openai") .vectorStore("philosophers", Quote.class); + } + + @Test + @Order(2) + @DisplayName("02. Loading DataSet") + public void shouldLoadDataset() { // Ingest CSV - loadQuotesFromCsv("/philosopher-quotes.csv") - .forEach(quote -> vectorStore.insert(quote, vectorizeWithHuggingFace(quote.getQuote()))); + AtomicInteger rowId = new AtomicInteger(); + loadQuotesFromCsv("/philosopher-quotes.csv").forEach(quote -> { + System.out.println("Inserting " + rowId.get() + ") " + quote.getQuote()); + vectorStore.insert( + String.valueOf(rowId.incrementAndGet()), + quote, vectorize(quote.getQuote())); + }); + } + + @Test + @Order(3) + @DisplayName("03. Should Similarity Search") + public void shouldSimilaritySearch() { - // Ann Search - float[] embeddings = huggingFaceModel.embed("I think therefore I am").content().vector(); - Page> page = vectorStore.annSearch(embeddings, null, 5); - page.getResults().forEach(record -> System.out.println(record.getData().getQuote())); + vectorStore = new JsonApiClient() + .namespace("vector_openai") + .vectorStore("philosophers", Quote.class); + float[] embeddings = vectorize("We struggle all our life for nothing"); + vectorStore.similaritySearch(embeddings, 3).getResults() + .stream() + .map(Document::getData) + .map(Quote::getQuote) + .forEach(System.out::println); } + @Test + @Order(4) + @DisplayName("04. Should filter with meta data") + public void shouldMetaDataFiltering() { + + new JsonApiClient() + .namespace("vector_openai") + .vectorStore("philosophers", Quote.class) + + .similaritySearch( + vectorize("We struggle all our life for nothing"), + new Filter().where("philosopher").isEqualsTo("plato"), + 2) + + .getResults() + .forEach(r -> System.out.println(r.getSimilarity() + " - " + r.getData().getQuote())); + } + + @Test + @Order(5) + @DisplayName("05. Should filter with meta data tags") + public void shouldMetaDataFilteringWithTags() { + vectorStore = new JsonApiClient() + .namespace("vector_openai") + .vectorStore("philosophers", Quote.class); + vectorStore.count(new Filter().where("tags").isAnArrayContaining("love")); + } + + static ChatLanguageModel openaiGenerator = OpenAiChatModel.builder() + .apiKey(System.getenv("OPENAI_API_KEY")) + .modelName(OpenAiModelName.GPT_3_5_TURBO) + .temperature(0.7) + .timeout(Duration.ofSeconds(15)) + .maxRetries(3) + .logResponses(true) + .logRequests(true) + .build(); + + @Test + @Order(6) + @DisplayName("06. Should Generate new quotes") + public void should_generate_new_quotes() { + vectorStore = new JsonApiClient() + .namespace("vector_openai") + .vectorStore("philosophers", Quote.class); + + // === Params == + String topic = "politics and virtue"; + String author = "nietzsche"; + int records = 4; + + // ==== RAG === + List ragQuotes = vectorStore + .similaritySearch( + vectorize(topic), + new Filter().where("philosopher").isEqualsTo(author),2) + .getResults().stream() + .map(r -> r.getData().getQuote()) + .collect(Collectors.toList()); + + // === Completion === + PromptTemplate promptTemplate = PromptTemplate.from( + "Generate a single short philosophical quote on the given topic,\n" + + "similar in spirit and form to the provided actual example quotes.\n" + + "Do not exceed 20-30 words in your quote.\n" + + "REFERENCE TOPIC: \n{{topic}}" + + "\nACTUAL EXAMPLES:\n{{rag}}"); + Map variables = new HashMap<>(); + variables.put("topic", topic); + variables.put("information", String.join(", ", ragQuotes)); + Prompt prompt = promptTemplate.apply(variables); + Response aiMessage = openaiGenerator.generate(prompt.toUserMessage()); + String answer = aiMessage.content().text(); + System.out.println(answer); + } + + // --- Utilities (loading CSV) --- + private List loadQuotesFromCsv(String filePath) { List quotes = new ArrayList<>(); - File csvFile = new File(LoadQuotes.class.getResource(filePath).getFile()); + File csvFile = new File(VectorClientPhilosopherTest.class.getResource(filePath).getFile()); try (Scanner scanner = new Scanner(csvFile)) { while (scanner.hasNextLine()) { Quote q = mapCsvLine(scanner.nextLine()); diff --git a/stargate-sdk-test/src/test/java/io/stargate/test/json/JsonClientApiDemoTest.java b/stargate-sdk-test/src/test/java/io/stargate/test/json/VectorClientProductTest.java similarity index 52% rename from stargate-sdk-test/src/test/java/io/stargate/test/json/JsonClientApiDemoTest.java rename to stargate-sdk-test/src/test/java/io/stargate/test/json/VectorClientProductTest.java index 8fa6f25..3a56b6c 100644 --- a/stargate-sdk-test/src/test/java/io/stargate/test/json/JsonClientApiDemoTest.java +++ b/stargate-sdk-test/src/test/java/io/stargate/test/json/VectorClientProductTest.java @@ -1,15 +1,20 @@ package io.stargate.test.json; import com.fasterxml.jackson.annotation.JsonProperty; +import io.stargate.sdk.core.domain.Page; import io.stargate.sdk.json.JsonApiClient; import io.stargate.sdk.json.JsonCollectionClient; -import io.stargate.sdk.json.vector.VectorStore; import io.stargate.sdk.json.domain.CollectionDefinition; import io.stargate.sdk.json.domain.Filter; +import io.stargate.sdk.json.domain.JsonDocument; +import io.stargate.sdk.json.domain.JsonResult; import io.stargate.sdk.json.domain.NamespaceDefinition; -import io.stargate.sdk.json.domain.odm.Record; -import lombok.Builder; +import io.stargate.sdk.json.domain.SelectQuery; +import io.stargate.sdk.json.domain.odm.Result; +import io.stargate.sdk.json.vector.VectorStore; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -20,14 +25,15 @@ import java.util.Arrays; import java.util.List; +import java.util.Map; import static io.stargate.sdk.json.vector.SimilarityMetric.cosine; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class JsonClientApiDemoTest { +class VectorClientProductTest { - @Data @Builder - private static class Product { + @Data @NoArgsConstructor @AllArgsConstructor + static class Product { @JsonProperty("product_name") private String name; @@ -36,19 +42,21 @@ private static class Product { private Double price; } - public static final String NAMESPACE = "demo"; - public static final String COLLECTION = "sample_collection"; - public static final String COLLECTION_VECTOR = "pet_supply_vectors"; + static final String NAMESPACE = "demo"; + static final String COLLECTION = "sample_collection"; + static final String COLLECTION_VECTOR = "pet_supply_vectors"; + + static JsonApiClient jsonApi; - public static JsonApiClient jsonApi; + static JsonCollectionClient myCollection; - public static JsonCollectionClient myCollection; + static VectorStore vectorStore; @BeforeAll public static void setup() { // If default (localhost:8181) no parameter needed jsonApi = new JsonApiClient(); - //jsonApi.dropNamespace(NAMESPACE); + jsonApi.dropNamespace(NAMESPACE); } @Test @@ -77,59 +85,49 @@ public void shouldCreateCollection() { Assertions.assertTrue(collections.contains(COLLECTION_VECTOR)); // Vector Store Experience - VectorStore vectorStore = jsonApi - .namespace(NAMESPACE) - .vectorStore(COLLECTION_VECTOR, Product.class); + myCollection = jsonApi.namespace(NAMESPACE).collection(COLLECTION_VECTOR); + vectorStore = jsonApi.namespace(NAMESPACE).vectorStore(COLLECTION_VECTOR, Product.class); + float[] sampleVector = new float[] {1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}; String vectorId1 = vectorStore.insert("1", new Product("HealthyFresh - Beef raw dog food", 12.99), - new float[] {1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}); - - Record ve = vectorStore.findById(vectorId1).get(); - //vectorStore.save(ve); + sampleVector); + Assertions.assertTrue(vectorStore.findById(vectorId1).isPresent()); + Assertions.assertTrue(vectorStore.findByVector(sampleVector).isPresent()); } @Test @Order(2) @DisplayName("02. Insert Records") public void shouldInsertVectors() { - - VectorStore s; -/* // (Insert Many) - myCollection.insert( + myCollection.insertMany(List.of( // Add keys - new JsonVectorRecord("pf1844") + new JsonDocument("pf1844") .put("product_name", "HealthyFresh - Beef raw dog food") .put("product_price", 12.99) - .vector(1d, 0d, 1d, 1d, 1d, 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d), - // Constructor and Map - new JsonRecord("pf1843") - .vector(1d, 1d, 1d, 1d, 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d) - .metadatas(Map.of("product_name", "HealthyFresh - Chicken raw dog food")), - // Builder and json String - JsonRecord.builder() + .vector(new float[] {1f, 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}), + new JsonDocument("pf1843") + .vector(new float[] {1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}) + .data(Map.of("product_name", "HealthyFresh - Chicken raw dog food")), + new JsonDocument() .id("pt0021") - .metadatasJson("{ \"product_name\": \"Dog Tennis Ball Toy\" }") - .vector(0d, 0d, 0d, 1d, 0d, 0d, 0d, 0d, 0d, 1d, 1d, 1d, 0d, 0d) - .build(), + .data("{ \"product_name\": \"Dog Tennis Ball Toy\" }") + .vector(new float[] {0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 1f, 1f, 0f, 0f}), // Builder and bean - JsonRecord.builder() + new JsonDocument() .id("pt0041") - .metadatas(new Product("Dog Ring Chew Toy", 9.99)) - .vector(0d, 0d, 0d, 1d, 0d, 0d, 0d, 1d, 1d, 1d, 0d, 0d, 0d, 0d) - .build(), - JsonRecord.builder() + .data(new Product("Dog Ring Chew Toy", 9.99)) + .vector(new float[] {0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f, 1f, 1f, 0f, 0f, 0f, 0f}), + new JsonDocument() .id("pf7043") - .metadatas(new Product("PupperSausage Bacon dog Treats", 9.99)) - .vector(0d, 0d, 0d, 1d, 0d, 0d, 1d, 0d, 0d, 0d, 0d, 0d, 1d, 1d) - .build(), - JsonRecord.builder() + .data(new Product("Pepper Sausage Bacon dog Treats", 9.99)) + .vector(new float[] {0f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 1f}), + new JsonDocument() .id("pf7044") - .metadatas(new Product("PupperSausage Beef dog Treats", 9.99)) - .vector(0d, 0d, 0d, 1d, 0d, 1d, 1d, 0d, 0d, 0d, 0d, 0d, 1d, 0d) - .build());*/ + .data(new Product("Pepper Sausage Beef dog Treats", 9.99)) + .vector(new float[] {0f, 0f, 0f, 1f, 0f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f}))); } @Test @@ -153,39 +151,47 @@ public void shouldSimilaritySearch() { JsonCollectionClient myCollection = jsonApi .namespace(NAMESPACE) .collection(COLLECTION_VECTOR); -/* - Page page = myCollection.find(Query.builder() - // Projection + + Page page = myCollection.queryForPage(SelectQuery.builder() .selectVector() .selectSimilarity() - // ann search - .orderByAnn(1d, 1d, 1d, 1d, 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d) - .maxResults(2) + .orderByAnn(1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f) + .limit(2) .build()); + Page> pageProduct = myCollection.queryForPage(SelectQuery.builder() + .selectVector() + .selectSimilarity() + .orderByAnn(1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f) + .limit(2) + .build(), Product.class); + System.out.println("Result Size=" + page.getPageSize()); - for(JsonVectorResult result : page.getResults()) { - System.out.println(result.getId() + ") similarity=" + result.getSimilarity() + ", vector=" + result.getVector()); - }*/ + System.out.println("Result Size=" + pageProduct.getPageSize()); + for(JsonResult result : page.getResults()) { + System.out.println(result.getId() + ") similarity=" + result.getSimilarity() + ", vector=" + + Arrays.toString(result.getVector())); + } } @Test @Order(5) @DisplayName("05. Meta Data Filtering") public void shouldMetaDataFiltering() { -/* - Page page = myCollection.find(Query.builder() + + Page page = myCollection.queryForPage(SelectQuery.builder() .selectVector() .selectSimilarity() .where("product_price").isEqualsTo(9.99) - .orderByAnn(1d, 1d, 1d, 1d, 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d) - .maxResults(2) + .orderByAnn(1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f) + .limit(2) .build()); System.out.println("Result Size=" + page.getPageSize()); - for(JsonVectorResult result : page.getResults()) { - System.out.println(result.getId() + ") similarity=" + result.getSimilarity() + ", vector=" + result.getVector()); - }*/ + for(JsonResult result : page.getResults()) { + System.out.println(result.getId() + ") similarity=" + result.getSimilarity() + ", vector=" + + Arrays.toString(result.getVector())); + } } } diff --git a/stargate-sdk-test/src/test/resources/philosopher-quotes.csv b/stargate-sdk-test/src/test/resources/philosopher-quotes.csv index dba340a..22d903a 100644 --- a/stargate-sdk-test/src/test/resources/philosopher-quotes.csv +++ b/stargate-sdk-test/src/test/resources/philosopher-quotes.csv @@ -1,4 +1,4 @@ -/Users/cedricklunven/.sdkman/candidates/java/22.3.1.r17-grl/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=53151:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/cedricklunven/.m2/repository/org/junit/platform/junit-platform-launcher/1.10.0/junit-platform-launcher-1.10.0.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit5-rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-test/target/test-classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-test/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-document/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-commons/target/classes:/Users/cedricklunven/.m2/repository/com/evanlennick/retry4j/0.15.0/retry4j-0.15.0.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/client5/httpclient5/5.2.1/httpclient5-5.2.1.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/core5/httpcore5/5.2/httpcore5-5.2.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/core5/httpcore5-h2/5.2/httpcore5-h2-5.2.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/client5/httpclient5-fluent/5.2.1/httpclient5-fluent-5.2.1.jar:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.15.2/jackson-core-2.15.2.jar:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.15.2/jackson-databind-2.15.2.jar:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.15.2/jackson-datatype-jsr310-2.15.2.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-grpc/target/classes:/Users/cedricklunven/.m2/repository/io/stargate/grpc/grpc-proto/2.0.17/grpc-proto-2.0.17.jar:/Users/cedricklunven/.m2/repository/io/projectreactor/reactor-core/3.4.13/reactor-core-3.4.13.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-protobuf/1.55.1/grpc-protobuf-1.55.1.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-api/1.55.1/grpc-api-1.55.1.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-context/1.55.1/grpc-context-1.55.1.jar:/Users/cedricklunven/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/Users/cedricklunven/.m2/repository/com/google/protobuf/protobuf-java/3.22.3/protobuf-java-3.22.3.jar:/Users/cedricklunven/.m2/repository/com/google/api/grpc/proto-google-common-protos/2.9.0/proto-google-common-protos-2.9.0.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-protobuf-lite/1.55.1/grpc-protobuf-lite-1.55.1.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-stub/1.55.1/grpc-stub-1.55.1.jar:/Users/cedricklunven/.m2/repository/com/salesforce/servicelibs/reactor-grpc-stub/1.2.3/reactor-grpc-stub-1.2.3.jar:/Users/cedricklunven/.m2/repository/com/salesforce/servicelibs/reactive-grpc-common/1.2.3/reactive-grpc-common-1.2.3.jar:/Users/cedricklunven/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-netty-shaded/1.56.1/grpc-netty-shaded-1.56.1.jar:/Users/cedricklunven/.m2/repository/com/google/guava/guava/31.1-android/guava-31.1-android.jar:/Users/cedricklunven/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:/Users/cedricklunven/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/Users/cedricklunven/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar:/Users/cedricklunven/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar:/Users/cedricklunven/.m2/repository/com/google/errorprone/error_prone_annotations/2.18.0/error_prone_annotations-2.18.0.jar:/Users/cedricklunven/.m2/repository/io/perfmark/perfmark-api/0.26.0/perfmark-api-0.26.0.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-core/1.56.1/grpc-core-1.56.1.jar:/Users/cedricklunven/.m2/repository/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar:/Users/cedricklunven/.m2/repository/com/google/android/annotations/4.1.1.4/annotations-4.1.1.4.jar:/Users/cedricklunven/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.23/animal-sniffer-annotations-1.23.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-rest/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-graphql/target/classes:/Users/cedricklunven/.m2/repository/com/netflix/graphql/dgs/codegen/graphql-dgs-codegen-client-core/5.1.17/graphql-dgs-codegen-client-core-5.1.17.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.5.31/kotlin-stdlib-jdk8-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.5.31/kotlin-stdlib-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.5.31/kotlin-stdlib-common-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.5.31/kotlin-stdlib-jdk7-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.5.31/kotlin-reflect-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/reflections/reflections/0.10.2/reflections-0.10.2.jar:/Users/cedricklunven/.m2/repository/org/javassist/javassist/3.28.0-GA/javassist-3.28.0-GA.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-cql/target/classes:/Users/cedricklunven/.m2/repository/com/datastax/oss/java-driver-core/4.17.0/java-driver-core-4.17.0.jar:/Users/cedricklunven/.m2/repository/com/datastax/oss/native-protocol/1.5.1/native-protocol-1.5.1.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-handler/4.1.94.Final/netty-handler-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-common/4.1.94.Final/netty-common-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-resolver/4.1.94.Final/netty-resolver-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-buffer/4.1.94.Final/netty-buffer-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-transport/4.1.94.Final/netty-transport-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-transport-native-unix-common/4.1.94.Final/netty-transport-native-unix-common-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-codec/4.1.94.Final/netty-codec-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/com/datastax/oss/java-driver-shaded-guava/25.1-jre-graal-sub-1/java-driver-shaded-guava-25.1-jre-graal-sub-1.jar:/Users/cedricklunven/.m2/repository/com/typesafe/config/1.4.1/config-1.4.1.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-posix/3.1.15/jnr-posix-3.1.15.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-ffi/2.2.11/jnr-ffi-2.2.11.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jffi/1.3.9/jffi-1.3.9.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jffi/1.3.9/jffi-1.3.9-native.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm/9.2/asm-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-util/9.2/asm-util-9.2.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-a64asm/1.0.0/jnr-a64asm-1.0.0.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-x86asm/1.0.2/jnr-x86asm-1.0.2.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-constants/0.10.3/jnr-constants-0.10.3.jar:/Users/cedricklunven/.m2/repository/io/dropwizard/metrics/metrics-core/4.1.18/metrics-core-4.1.18.jar:/Users/cedricklunven/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.12/HdrHistogram-2.1.12.jar:/Users/cedricklunven/.m2/repository/org/reactivestreams/reactive-streams/1.0.3/reactive-streams-1.0.3.jar:/Users/cedricklunven/.m2/repository/com/github/stephenc/jcip/jcip-annotations/1.0-1/jcip-annotations-1.0-1.jar:/Users/cedricklunven/.m2/repository/com/github/spotbugs/spotbugs-annotations/3.1.12/spotbugs-annotations-3.1.12.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-json/target/classes:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.15.2/jackson-annotations-2.15.2.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter/5.10.0/junit-jupiter-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.10.0/junit-jupiter-params-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar:/Users/cedricklunven/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/Users/cedricklunven/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/cedricklunven/.m2/repository/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar:/Users/cedricklunven/.m2/repository/ch/qos/logback/logback-classic/1.4.11/logback-classic-1.4.11.jar:/Users/cedricklunven/.m2/repository/ch/qos/logback/logback-core/1.4.11/logback-core-1.4.11.jar:/Users/cedricklunven/.m2/repository/org/slf4j/slf4j-api/2.0.9/slf4j-api-2.0.9.jar:/Users/cedricklunven/.m2/repository/org/json/json/20210307/json-20210307.jar:/Users/cedricklunven/.m2/repository/commons-io/commons-io/2.11.0/commons-io-2.11.0.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 io.stargate.test.json.LoadQuotes,shoudConvertCsv +/Users/cedricklunven/.sdkman/candidates/java/22.3.1.r17-grl/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=53151:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/cedricklunven/.m2/repository/org/junit/platform/junit-platform-launcher/1.10.0/junit-platform-launcher-1.10.0.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit5-rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-test/target/test-classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-test/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-document/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-commons/target/classes:/Users/cedricklunven/.m2/repository/com/evanlennick/retry4j/0.15.0/retry4j-0.15.0.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/client5/httpclient5/5.2.1/httpclient5-5.2.1.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/core5/httpcore5/5.2/httpcore5-5.2.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/core5/httpcore5-h2/5.2/httpcore5-h2-5.2.jar:/Users/cedricklunven/.m2/repository/org/apache/httpcomponents/client5/httpclient5-fluent/5.2.1/httpclient5-fluent-5.2.1.jar:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.15.2/jackson-core-2.15.2.jar:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.15.2/jackson-databind-2.15.2.jar:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.15.2/jackson-datatype-jsr310-2.15.2.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-grpc/target/classes:/Users/cedricklunven/.m2/repository/io/stargate/grpc/grpc-proto/2.0.17/grpc-proto-2.0.17.jar:/Users/cedricklunven/.m2/repository/io/projectreactor/reactor-core/3.4.13/reactor-core-3.4.13.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-protobuf/1.55.1/grpc-protobuf-1.55.1.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-api/1.55.1/grpc-api-1.55.1.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-context/1.55.1/grpc-context-1.55.1.jar:/Users/cedricklunven/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/Users/cedricklunven/.m2/repository/com/google/protobuf/protobuf-java/3.22.3/protobuf-java-3.22.3.jar:/Users/cedricklunven/.m2/repository/com/google/api/grpc/proto-google-common-protos/2.9.0/proto-google-common-protos-2.9.0.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-protobuf-lite/1.55.1/grpc-protobuf-lite-1.55.1.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-stub/1.55.1/grpc-stub-1.55.1.jar:/Users/cedricklunven/.m2/repository/com/salesforce/servicelibs/reactor-grpc-stub/1.2.3/reactor-grpc-stub-1.2.3.jar:/Users/cedricklunven/.m2/repository/com/salesforce/servicelibs/reactive-grpc-common/1.2.3/reactive-grpc-common-1.2.3.jar:/Users/cedricklunven/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-netty-shaded/1.56.1/grpc-netty-shaded-1.56.1.jar:/Users/cedricklunven/.m2/repository/com/google/guava/guava/31.1-android/guava-31.1-android.jar:/Users/cedricklunven/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:/Users/cedricklunven/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/Users/cedricklunven/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar:/Users/cedricklunven/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar:/Users/cedricklunven/.m2/repository/com/google/errorprone/error_prone_annotations/2.18.0/error_prone_annotations-2.18.0.jar:/Users/cedricklunven/.m2/repository/io/perfmark/perfmark-api/0.26.0/perfmark-api-0.26.0.jar:/Users/cedricklunven/.m2/repository/io/grpc/grpc-core/1.56.1/grpc-core-1.56.1.jar:/Users/cedricklunven/.m2/repository/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar:/Users/cedricklunven/.m2/repository/com/google/android/annotations/4.1.1.4/annotations-4.1.1.4.jar:/Users/cedricklunven/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.23/animal-sniffer-annotations-1.23.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-rest/target/classes:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-graphql/target/classes:/Users/cedricklunven/.m2/repository/com/netflix/graphql/dgs/codegen/graphql-dgs-codegen-client-core/5.1.17/graphql-dgs-codegen-client-core-5.1.17.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.5.31/kotlin-stdlib-jdk8-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.5.31/kotlin-stdlib-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.5.31/kotlin-stdlib-common-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.5.31/kotlin-stdlib-jdk7-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.5.31/kotlin-reflect-1.5.31.jar:/Users/cedricklunven/.m2/repository/org/reflections/reflections/0.10.2/reflections-0.10.2.jar:/Users/cedricklunven/.m2/repository/org/javassist/javassist/3.28.0-GA/javassist-3.28.0-GA.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-cql/target/classes:/Users/cedricklunven/.m2/repository/com/datastax/oss/java-driver-core/4.17.0/java-driver-core-4.17.0.jar:/Users/cedricklunven/.m2/repository/com/datastax/oss/native-protocol/1.5.1/native-protocol-1.5.1.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-handler/4.1.94.Final/netty-handler-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-common/4.1.94.Final/netty-common-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-resolver/4.1.94.Final/netty-resolver-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-buffer/4.1.94.Final/netty-buffer-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-transport/4.1.94.Final/netty-transport-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-transport-native-unix-common/4.1.94.Final/netty-transport-native-unix-common-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/io/netty/netty-codec/4.1.94.Final/netty-codec-4.1.94.Final.jar:/Users/cedricklunven/.m2/repository/com/datastax/oss/java-driver-shaded-guava/25.1-jre-graal-sub-1/java-driver-shaded-guava-25.1-jre-graal-sub-1.jar:/Users/cedricklunven/.m2/repository/com/typesafe/config/1.4.1/config-1.4.1.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-posix/3.1.15/jnr-posix-3.1.15.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-ffi/2.2.11/jnr-ffi-2.2.11.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jffi/1.3.9/jffi-1.3.9.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jffi/1.3.9/jffi-1.3.9-native.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm/9.2/asm-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar:/Users/cedricklunven/.m2/repository/org/ow2/asm/asm-util/9.2/asm-util-9.2.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-a64asm/1.0.0/jnr-a64asm-1.0.0.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-x86asm/1.0.2/jnr-x86asm-1.0.2.jar:/Users/cedricklunven/.m2/repository/com/github/jnr/jnr-constants/0.10.3/jnr-constants-0.10.3.jar:/Users/cedricklunven/.m2/repository/io/dropwizard/metrics/metrics-core/4.1.18/metrics-core-4.1.18.jar:/Users/cedricklunven/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.12/HdrHistogram-2.1.12.jar:/Users/cedricklunven/.m2/repository/org/reactivestreams/reactive-streams/1.0.3/reactive-streams-1.0.3.jar:/Users/cedricklunven/.m2/repository/com/github/stephenc/jcip/jcip-annotations/1.0-1/jcip-annotations-1.0-1.jar:/Users/cedricklunven/.m2/repository/com/github/spotbugs/spotbugs-annotations/3.1.12/spotbugs-annotations-3.1.12.jar:/Users/cedricklunven/dev/datastax/sdk/stargate-sdk-java/stargate-sdk-json/target/classes:/Users/cedricklunven/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.15.2/jackson-annotations-2.15.2.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter/5.10.0/junit-jupiter-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.10.0/junit-jupiter-params-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar:/Users/cedricklunven/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/Users/cedricklunven/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar:/Users/cedricklunven/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar:/Users/cedricklunven/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/cedricklunven/.m2/repository/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar:/Users/cedricklunven/.m2/repository/ch/qos/logback/logback-classic/1.4.11/logback-classic-1.4.11.jar:/Users/cedricklunven/.m2/repository/ch/qos/logback/logback-core/1.4.11/logback-core-1.4.11.jar:/Users/cedricklunven/.m2/repository/org/slf4j/slf4j-api/2.0.9/slf4j-api-2.0.9.jar:/Users/cedricklunven/.m2/repository/org/json/json/20210307/json-20210307.jar:/Users/cedricklunven/.m2/repository/commons-io/commons-io/2.11.0/commons-io-2.11.0.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 io.stargate.test.json.HugginFace,shoudConvertCsv author,quote,tags aristotle,"True happiness comes from gaining insight and growing into your best possible self. Otherwise all you're having is immediate gratification pleasure, which is fleeting and doesn't grow you as a person.",knowledge aristotle,"The roots of education are bitter, but the fruit is sweet.",education;knowledge