Skip to content

Commit 8e40df9

Browse files
committed
Add embed model params.
1 parent cf17ccb commit 8e40df9

File tree

4 files changed

+295
-3
lines changed

4 files changed

+295
-3
lines changed

src/main/java/org/typesense/model/Field.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.typesense.model;
22

3+
import org.typesense.model.FieldEmbed;
34

45
import io.swagger.v3.oas.annotations.media.Schema;
56
import javax.xml.bind.annotation.XmlElement;
@@ -44,6 +45,9 @@ public class Field {
4445

4546
@Schema(example = "true", description = "")
4647
private Boolean drop = null;
48+
49+
@Schema(description = "")
50+
private FieldEmbed embed = null;
4751
/**
4852
* Get name
4953
* @return name
@@ -224,6 +228,24 @@ public Field drop(Boolean drop) {
224228
return this;
225229
}
226230

231+
/**
232+
* Get embed
233+
* @return embed
234+
**/
235+
@JsonProperty("embed")
236+
public FieldEmbed getEmbed() {
237+
return embed;
238+
}
239+
240+
public void setEmbed(FieldEmbed embed) {
241+
this.embed = embed;
242+
}
243+
244+
public Field embed(FieldEmbed embed) {
245+
this.embed = embed;
246+
return this;
247+
}
248+
227249

228250
@Override
229251
public String toString() {
@@ -240,6 +262,7 @@ public String toString() {
240262
sb.append(" infix: ").append(toIndentedString(infix)).append("\n");
241263
sb.append(" numDim: ").append(toIndentedString(numDim)).append("\n");
242264
sb.append(" drop: ").append(toIndentedString(drop)).append("\n");
265+
sb.append(" embed: ").append(toIndentedString(embed)).append("\n");
243266
sb.append("}");
244267
return sb.toString();
245268
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.typesense.model;
2+
3+
import java.util.List;
4+
import org.typesense.model.FieldEmbedModelConfig;
5+
6+
import io.swagger.v3.oas.annotations.media.Schema;
7+
import javax.xml.bind.annotation.XmlElement;
8+
import javax.xml.bind.annotation.XmlRootElement;
9+
import javax.xml.bind.annotation.XmlAccessType;
10+
import javax.xml.bind.annotation.XmlAccessorType;
11+
import javax.xml.bind.annotation.XmlType;
12+
import javax.xml.bind.annotation.XmlEnum;
13+
import javax.xml.bind.annotation.XmlEnumValue;
14+
import com.fasterxml.jackson.annotation.JsonProperty;
15+
import com.fasterxml.jackson.annotation.JsonValue;
16+
import com.fasterxml.jackson.annotation.JsonCreator;
17+
18+
public class FieldEmbed {
19+
20+
@Schema(required = true, description = "")
21+
private List from = null;
22+
23+
@Schema(required = true, description = "")
24+
private FieldEmbedModelConfig modelConfig = null;
25+
/**
26+
* Get from
27+
* @return from
28+
**/
29+
@JsonProperty("from")
30+
public List getFrom() {
31+
return from;
32+
}
33+
34+
public void setFrom(List from) {
35+
this.from = from;
36+
}
37+
38+
public FieldEmbed from(List from) {
39+
this.from = from;
40+
return this;
41+
}
42+
43+
/**
44+
* Get modelConfig
45+
* @return modelConfig
46+
**/
47+
@JsonProperty("model_config")
48+
public FieldEmbedModelConfig getModelConfig() {
49+
return modelConfig;
50+
}
51+
52+
public void setModelConfig(FieldEmbedModelConfig modelConfig) {
53+
this.modelConfig = modelConfig;
54+
}
55+
56+
public FieldEmbed modelConfig(FieldEmbedModelConfig modelConfig) {
57+
this.modelConfig = modelConfig;
58+
return this;
59+
}
60+
61+
62+
@Override
63+
public String toString() {
64+
StringBuilder sb = new StringBuilder();
65+
sb.append("class FieldEmbed {\n");
66+
67+
sb.append(" from: ").append(toIndentedString(from)).append("\n");
68+
sb.append(" modelConfig: ").append(toIndentedString(modelConfig)).append("\n");
69+
sb.append("}");
70+
return sb.toString();
71+
}
72+
73+
/**
74+
* Convert the given object to string with each line indented by 4 spaces
75+
* (except the first line).
76+
*/
77+
private static String toIndentedString(java.lang.Object o) {
78+
if (o == null) {
79+
return "null";
80+
}
81+
return o.toString().replace("\n", "\n ");
82+
}
83+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package org.typesense.model;
2+
3+
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import javax.xml.bind.annotation.XmlElement;
6+
import javax.xml.bind.annotation.XmlRootElement;
7+
import javax.xml.bind.annotation.XmlAccessType;
8+
import javax.xml.bind.annotation.XmlAccessorType;
9+
import javax.xml.bind.annotation.XmlType;
10+
import javax.xml.bind.annotation.XmlEnum;
11+
import javax.xml.bind.annotation.XmlEnumValue;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import com.fasterxml.jackson.annotation.JsonValue;
14+
import com.fasterxml.jackson.annotation.JsonCreator;
15+
16+
public class FieldEmbedModelConfig {
17+
18+
@Schema(required = true, description = "")
19+
private String modelName = null;
20+
21+
@Schema(description = "")
22+
private String apiKey = null;
23+
24+
@Schema(description = "")
25+
private String accessToken = null;
26+
27+
@Schema(description = "")
28+
private String clientId = null;
29+
30+
@Schema(description = "")
31+
private String clientSecret = null;
32+
33+
@Schema(description = "")
34+
private String projectId = null;
35+
/**
36+
* Get modelName
37+
* @return modelName
38+
**/
39+
@JsonProperty("model_name")
40+
public String getModelName() {
41+
return modelName;
42+
}
43+
44+
public void setModelName(String modelName) {
45+
this.modelName = modelName;
46+
}
47+
48+
public FieldEmbedModelConfig modelName(String modelName) {
49+
this.modelName = modelName;
50+
return this;
51+
}
52+
53+
/**
54+
* Get apiKey
55+
* @return apiKey
56+
**/
57+
@JsonProperty("api_key")
58+
public String getApiKey() {
59+
return apiKey;
60+
}
61+
62+
public void setApiKey(String apiKey) {
63+
this.apiKey = apiKey;
64+
}
65+
66+
public FieldEmbedModelConfig apiKey(String apiKey) {
67+
this.apiKey = apiKey;
68+
return this;
69+
}
70+
71+
/**
72+
* Get accessToken
73+
* @return accessToken
74+
**/
75+
@JsonProperty("access_token")
76+
public String getAccessToken() {
77+
return accessToken;
78+
}
79+
80+
public void setAccessToken(String accessToken) {
81+
this.accessToken = accessToken;
82+
}
83+
84+
public FieldEmbedModelConfig accessToken(String accessToken) {
85+
this.accessToken = accessToken;
86+
return this;
87+
}
88+
89+
/**
90+
* Get clientId
91+
* @return clientId
92+
**/
93+
@JsonProperty("client_id")
94+
public String getClientId() {
95+
return clientId;
96+
}
97+
98+
public void setClientId(String clientId) {
99+
this.clientId = clientId;
100+
}
101+
102+
public FieldEmbedModelConfig clientId(String clientId) {
103+
this.clientId = clientId;
104+
return this;
105+
}
106+
107+
/**
108+
* Get clientSecret
109+
* @return clientSecret
110+
**/
111+
@JsonProperty("client_secret")
112+
public String getClientSecret() {
113+
return clientSecret;
114+
}
115+
116+
public void setClientSecret(String clientSecret) {
117+
this.clientSecret = clientSecret;
118+
}
119+
120+
public FieldEmbedModelConfig clientSecret(String clientSecret) {
121+
this.clientSecret = clientSecret;
122+
return this;
123+
}
124+
125+
/**
126+
* Get projectId
127+
* @return projectId
128+
**/
129+
@JsonProperty("project_id")
130+
public String getProjectId() {
131+
return projectId;
132+
}
133+
134+
public void setProjectId(String projectId) {
135+
this.projectId = projectId;
136+
}
137+
138+
public FieldEmbedModelConfig projectId(String projectId) {
139+
this.projectId = projectId;
140+
return this;
141+
}
142+
143+
144+
@Override
145+
public String toString() {
146+
StringBuilder sb = new StringBuilder();
147+
sb.append("class FieldEmbedModelConfig {\n");
148+
149+
sb.append(" modelName: ").append(toIndentedString(modelName)).append("\n");
150+
sb.append(" apiKey: ").append(toIndentedString(apiKey)).append("\n");
151+
sb.append(" accessToken: ").append(toIndentedString(accessToken)).append("\n");
152+
sb.append(" clientId: ").append(toIndentedString(clientId)).append("\n");
153+
sb.append(" clientSecret: ").append(toIndentedString(clientSecret)).append("\n");
154+
sb.append(" projectId: ").append(toIndentedString(projectId)).append("\n");
155+
sb.append("}");
156+
return sb.toString();
157+
}
158+
159+
/**
160+
* Convert the given object to string with each line indented by 4 spaces
161+
* (except the first line).
162+
*/
163+
private static String toIndentedString(java.lang.Object o) {
164+
if (o == null) {
165+
return "null";
166+
}
167+
return o.toString().replace("\n", "\n ");
168+
}
169+
}

src/test/java/org/typesense/api/CollectionsTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import org.junit.jupiter.api.AfterEach;
44
import org.junit.jupiter.api.BeforeEach;
55
import org.junit.jupiter.api.Test;
6-
import org.typesense.model.CollectionResponse;
7-
import org.typesense.model.CollectionSchema;
8-
import org.typesense.model.Field;
6+
import org.typesense.model.*;
97

108
import java.util.ArrayList;
119

@@ -62,4 +60,23 @@ void testCreateCollection() throws Exception {
6260
CollectionResponse cr = client.collections().create(collectionSchema);
6361
System.out.println(cr);
6462
}
63+
64+
@Test
65+
void testCreateCollectionWithModel() throws Exception {
66+
ArrayList<Field> fields = new ArrayList<>();
67+
fields.add(new Field().name("title").type(FieldTypes.STRING));
68+
69+
ArrayList<String> embedFrom = new ArrayList<>();
70+
embedFrom.add("title");
71+
72+
fields.add(new Field().name("embedding").type(FieldTypes.FLOAT_ARRAY).embed(
73+
new FieldEmbed().from(embedFrom).modelConfig(new FieldEmbedModelConfig().modelName("ts/e5-small"))
74+
));
75+
76+
CollectionSchema collectionSchema = new CollectionSchema();
77+
collectionSchema.name("titles").fields(fields);
78+
79+
//CollectionResponse cr = client.collections().create(collectionSchema);
80+
//System.out.println(cr);
81+
}
6582
}

0 commit comments

Comments
 (0)