File tree Expand file tree Collapse file tree 15 files changed +761
-0
lines changed
java/com/baeldung/utility
test/java/com/baeldung/milvus Expand file tree Collapse file tree 15 files changed +761
-0
lines changed Original file line number Diff line number Diff line change 769769 <module >timefold-solver</module >
770770 <module >vaadin</module >
771771 <module >vavr-modules</module >
772+ <module >vector-db</module >
772773 <module >vertx-modules</module >
773774 <module >web-modules</module >
774775 <module >webrtc</module >
10221023 <module >timefold-solver</module >
10231024 <module >vaadin</module >
10241025 <module >vavr-modules</module >
1026+ <module >vector-db</module >
10251027 <module >vertx-modules</module >
10261028 <module >web-modules</module >
10271029 <module >webrtc</module >
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+ <parent >
5+ <groupId >com.baeldung</groupId >
6+ <artifactId >vector-db</artifactId >
7+ <version >1.0-SNAPSHOT</version >
8+ </parent >
9+ <artifactId >milvus</artifactId >
10+ <dependencies >
11+ <dependency >
12+ <groupId >io.milvus</groupId >
13+ <artifactId >milvus-sdk-java</artifactId >
14+ <version >${milvus.version} </version >
15+ </dependency >
16+ </dependencies >
17+ <build >
18+ <plugins >
19+ <plugin >
20+ <groupId >org.apache.maven.plugins</groupId >
21+ <artifactId >maven-compiler-plugin</artifactId >
22+ <configuration >
23+ <source >9</source >
24+ <target >9</target >
25+ </configuration >
26+ </plugin >
27+ </plugins >
28+ </build >
29+
30+ <properties >
31+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
32+ <milvus .version>2.3.6</milvus .version>
33+ </properties >
34+
35+ </project >
Original file line number Diff line number Diff line change 1+ package com .baeldung .utility ;
2+
3+ import java .io .FileNotFoundException ;
4+ import java .io .FileReader ;
5+ import java .io .IOException ;
6+ import java .util .ArrayList ;
7+ import java .util .List ;
8+
9+ import com .alibaba .fastjson .JSONObject ;
10+ import com .alibaba .fastjson .JSONReader ;
11+ import com .google .gson .JsonArray ;
12+ import com .google .gson .JsonObject ;
13+ import com .google .gson .JsonParser ;
14+
15+ public class JsonUtil {
16+
17+ public static List <JsonObject > getListOfJsonObjectFromFile (String filePath ) throws IOException {
18+ List <JsonObject > lstOfJsonObject = new ArrayList <>();
19+ try (FileReader fileReader = new FileReader (filePath )) {
20+ JsonArray jsonArray = JsonParser .parseReader (fileReader ).getAsJsonArray ();
21+ for (int i = 0 ; i < jsonArray .size (); i ++) {
22+ JsonObject jsonObject = jsonArray .get (i ).getAsJsonObject ();
23+ lstOfJsonObject .add (jsonObject );
24+ }
25+ }
26+ return lstOfJsonObject ;
27+ }
28+
29+ public static List <JSONObject > getJsonObjects (String filePath ) throws FileNotFoundException {
30+ List <JSONObject > jsons = new ArrayList <>();
31+ try (JSONReader jsonReader = new JSONReader (new FileReader (filePath ))) {
32+ jsonReader .startArray ();
33+ while (jsonReader .hasNext ()) {
34+ jsons .add (jsonReader .readObject (JSONObject .class ));
35+ }
36+ jsonReader .endArray ();
37+ }
38+ return jsons ;
39+ }
40+
41+
42+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .utility ;
2+
3+ import java .io .FileInputStream ;
4+ import java .io .FileNotFoundException ;
5+ import java .io .IOException ;
6+ import java .io .InputStreamReader ;
7+ import java .util .HashMap ;
8+ import java .util .Map ;
9+ import java .util .Properties ;
10+
11+ public class PropertyUtil {
12+
13+ private static Map <String , Properties > MAP_OF_FILE_PROPERTIES = new HashMap ();
14+
15+ public static String getVal (String key , String propertyFile ) {
16+ if (MAP_OF_FILE_PROPERTIES .containsKey (propertyFile )) {
17+ return MAP_OF_FILE_PROPERTIES .get (propertyFile )
18+ .getProperty (key );
19+ } else {
20+ Properties properties = new Properties ();
21+ try (InputStreamReader inputStreamReader = new InputStreamReader (new FileInputStream (
22+ PropertyUtil .class .getClassLoader ()
23+ .getResource (propertyFile )
24+ .getPath ()))) {
25+ properties .load (inputStreamReader );
26+ MAP_OF_FILE_PROPERTIES .put (propertyFile , properties );
27+ } catch (IOException e ) {
28+ throw new RuntimeException (e );
29+ }
30+ return properties .getProperty (key );
31+ }
32+ }
33+
34+ }
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "book_id" : 1 ,
4+ "book_name" : " Tai Chi" ,
5+ "book_vector" : [
6+ 0.11585523338498954 ,
7+ 0.1783094496382904 ,
8+ -0.45512536123938796 ,
9+ -0.1138644337515659 ,
10+ -0.443425571406138
11+ ]
12+ },
13+ {
14+ "book_id" : 2 ,
15+ "book_name" : " Tai Chi" ,
16+ "book_vector" : [
17+ -0.03848166924730294 ,
18+ 0.7512903867821886 ,
19+ -0.01761663307560972 ,
20+ -0.33933745957967576 ,
21+ 0.36460985888476477
22+ ]
23+ },
24+ {
25+ "book_id" : 3 ,
26+ "book_name" : " Tai Chi" ,
27+ "book_vector" : [
28+ 0.5798311209884598 ,
29+ -0.014426831453109669 ,
30+ 0.0028486161949678158 ,
31+ -0.06036312928117309 ,
32+ -0.0601188165631914
33+ ]
34+ },
35+ {
36+ "book_id" : 4 ,
37+ "book_name" : " Yoga" ,
38+ "book_vector" : [
39+ -0.2977628409186709 ,
40+ 0.1195853535068145 ,
41+ -0.3823894217675929 ,
42+ 0.6885571147536734 ,
43+ 0.038907623760061204
44+ ]
45+ },
46+ {
47+ "book_id" : 5 ,
48+ "book_name" : " Yoga" ,
49+ "book_vector" : [
50+ -0.38657198360621114 ,
51+ 0.18076404029459892 ,
52+ 0.7274554020057162 ,
53+ 0.13125000541185 ,
54+ -0.30467826630061984
55+ ]
56+ },
57+ {
58+ "book_id" : 6 ,
59+ "book_name" : " Yoga" ,
60+ "book_vector" : [
61+ 0.35310470650822334 ,
62+ -0.18954545425054384 ,
63+ 0.1648929943409253 ,
64+ 0.3256386413418297 ,
65+ 0.23418123842211788
66+ ]
67+ },
68+ {
69+ "book_id" : 7 ,
70+ "book_name" : " Qigong" ,
71+ "book_vector" : [
72+ -0.37263809804085496 ,
73+ -0.3529793199622947 ,
74+ -0.15692998585783513 ,
75+ -0.36248569699937094 ,
76+ -0.26495408736924747
77+ ]
78+ },
79+ {
80+ "book_id" : 8 ,
81+ "book_name" : " Qigong" ,
82+ "book_vector" : [
83+ -0.36514369336848695 ,
84+ -0.4307163618848384 ,
85+ -0.06811672848773721 ,
86+ -0.19534894748369602 ,
87+ 0.4719572093010265
88+ ]
89+ },
90+ {
91+ "book_id" : 9 ,
92+ "book_name" : " Qigong" ,
93+ "book_vector" : [
94+ 0.4118072242998536 ,
95+ -0.24228126267110547 ,
96+ 0.18498111788655408 ,
97+ -0.07404609441187124 ,
98+ -0.036479188728774384
99+ ]
100+ }
101+ ]
Original file line number Diff line number Diff line change 1+ @startuml
2+ 'https://plantuml.com/class-diagram
3+ hide empty attributes
4+ skinparam Handwritten false
5+ skinparam ClassBorderColor black
6+ skinparam BackgroundColor #fffce8/#f8f9fa
7+ skinparam class {
8+ ArrowColor SeaGreen
9+ BackgroundColor #fffce8
10+ }
11+
12+ class MilvusClientV2 {
13+ + createCollection ()
14+
15+ }
16+
17+ class IndexParam {
18+ + builder ()
19+ }
20+ class IndexParamBuilder {
21+ + fieldName ()
22+ + indexName ()
23+ + metricType ()
24+ + indexType ()
25+ + build ()
26+ }
27+
28+ class FieldSchemaBuilder {
29+ + name ()
30+ + description ()
31+ + isPrimary ()
32+ + dimension ()
33+ + dataType ()
34+ + build ()
35+ }
36+
37+ class CreateCollectionReq {
38+ + builder ()
39+ }
40+
41+ class FieldSchema {
42+ + builder ()
43+ }
44+
45+ class CollectionSchema {
46+ + builder ()
47+ }
48+
49+ class CollectionSchemaBuilder {
50+ + fieldSchemaList(List<FieldSchema>)
51+ + build ()
52+ }
53+
54+ class CreateCollectionReqBuilder {
55+ + collectionName ()
56+ indexParams(List<IndexParam>)
57+ + description ()
58+ + collectionSchema ()
59+ + build ()
60+ }
61+
62+ CreateCollectionReqBuilder -down -+ CreateCollectionReq : contains
63+ CollectionSchema -left -+ CreateCollectionReq : uses
64+ CollectionSchema -down -+ CollectionSchemaBuilder : contains
65+ FieldSchema -up -+ CreateCollectionReq : uses
66+ FieldSchema -left -+ FieldSchemaBuilder : contains
67+ CollectionSchemaBuilder -left -> FieldSchema : uses
68+ MilvusClientV2 -down -> CreateCollectionReq : uses
69+ IndexParam +-up - IndexParamBuilder : contains
70+ CreateCollectionReqBuilder -down -> IndexParam : uses
71+
72+ @enduml
Original file line number Diff line number Diff line change 1+ @startuml
2+ 'https://plantuml.com/class-diagram
3+ hide empty attributes
4+ skinparam Handwritten false
5+ skinparam ClassBorderColor black
6+ skinparam BackgroundColor #fffce8/#f8f9fa
7+ skinparam class {
8+ ArrowColor SeaGreen
9+ BackgroundColor #fffce8
10+ }
11+
12+ class MilvusClientV2 {
13+ + createCollection ()
14+ + dropCollection ()
15+ + listCollections ()
16+ + describeCollection ()
17+ + createIndex ()
18+ + createPartition ()
19+ + insert ()
20+ + query ()
21+ }
22+
23+ class ConnectConfig {
24+ + builder ()
25+ }
26+
27+ class ConnectConfigBuilder {
28+ + uri ()
29+ + token ()
30+ + username ()
31+ + password ()
32+ }
33+
34+ ConnectConfig -left -+ ConnectConfigBuilder : contains
35+ MilvusClientV2 -left -> ConnectConfig : uses
36+
37+
38+
39+ @enduml
Original file line number Diff line number Diff line change 1+ @startuml
2+ 'https://plantuml.com/class-diagram
3+ hide empty attributes
4+ skinparam Handwritten false
5+ skinparam ClassBorderColor black
6+ skinparam BackgroundColor #fffce8/#f8f9fa
7+ skinparam class {
8+ ArrowColor SeaGreen
9+ BackgroundColor #fffce8
10+ }
11+
12+ class MilvusClientV2 {
13+ + createPartition(CreatePartitionReq)
14+ }
15+
16+ class CreatePartitionReq {
17+ + builder ()
18+ + setPartitionName ()
19+ + setCollectionName ()
20+ }
21+
22+
23+ class CreatePartitionReqBuilder {
24+ + collectionName ()
25+ + paritionName ()
26+ + build ()
27+ }
28+
29+ CreatePartitionReqBuilder -up -+ CreatePartitionReq : contains
30+ MilvusClientV2 -down -> CreatePartitionReq : uses
31+
32+ @enduml
You can’t perform that action at this time.
0 commit comments