Skip to content

Commit 5614eb6

Browse files
Merge pull request #206 from rosette-api/RD-2603
RD-2603: Add Rosette options to control the semantics endpoints’ embeddings
2 parents 3857d18 + 109c6cf commit 5614eb6

File tree

5 files changed

+75
-30
lines changed

5 files changed

+75
-30
lines changed

examples/src/main/java/com/basistech/rosette/examples/SemanticVectorsExample.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
/*
2-
* Copyright 2022 Basis Technology Corp.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright 2023 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616
package com.basistech.rosette.examples;
1717

1818
import com.basistech.rosette.api.HttpRosetteAPI;
1919
import com.basistech.rosette.apimodel.DocumentRequest;
20+
import com.basistech.rosette.apimodel.EmbeddingsMode;
2021
import com.basistech.rosette.apimodel.SemanticVectorsOptions;
2122
import com.basistech.rosette.apimodel.SemanticVectorsResponse;
2223

@@ -50,6 +51,9 @@ private void run() throws IOException {
5051
// When no options, use <?>.
5152
DocumentRequest<SemanticVectorsOptions> request = DocumentRequest.<SemanticVectorsOptions>builder()
5253
.content(semanticVectorsData)
54+
.options(SemanticVectorsOptions.builder()
55+
.embeddingsMode(EmbeddingsMode.GEN_1)
56+
.build())
5357
.build();
5458
SemanticVectorsResponse response = rosetteApi.perform(SEMANTIC_VECTORS_SERVICE_PATH, request, SemanticVectorsResponse.class);
5559
System.out.println(responseToJson(response));

examples/src/main/java/com/basistech/rosette/examples/SimilarTermsExample.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Basis Technology Corp.
2+
* Copyright 2023 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import com.basistech.rosette.api.HttpRosetteAPI;
2020
import com.basistech.rosette.apimodel.DocumentRequest;
21+
import com.basistech.rosette.apimodel.EmbeddingsMode;
2122
import com.basistech.rosette.apimodel.SimilarTermsOptions;
2223
import com.basistech.rosette.apimodel.SimilarTermsResponse;
2324
import com.basistech.util.LanguageCode;
@@ -54,6 +55,7 @@ private void run() throws IOException {
5455
DocumentRequest<SimilarTermsOptions> request = DocumentRequest.<SimilarTermsOptions>builder()
5556
.content(similarTermsData)
5657
.options(SimilarTermsOptions.builder()
58+
.embeddingsMode(EmbeddingsMode.GEN_1)
5759
.resultLanguages(Lists.newArrayList(LanguageCode.SPANISH, LanguageCode.GERMAN, LanguageCode.JAPANESE))
5860
.build())
5961
.build();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2023 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.apimodel;
18+
19+
/**
20+
* The generation of embeddings to use for all languages. Defaults to second generation unless the language only
21+
* supports first generation embeddings
22+
*/
23+
public enum EmbeddingsMode {
24+
DEFAULT,
25+
GEN_1,
26+
GEN_2,
27+
/**/;
28+
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
* Copyright 2018 Basis Technology Corp.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright 2023 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616
package com.basistech.rosette.apimodel;
1717

1818
import com.basistech.rosette.annotations.JacksonMixin;
@@ -32,4 +32,9 @@ public class SemanticVectorsOptions extends Options {
3232
*/
3333
private Boolean perToken;
3434

35+
/**
36+
* @return the generation of embeddings to use for all languages, defaulting to second generation embeddings unless
37+
* the language supports first generation embeddings
38+
*/
39+
private EmbeddingsMode embeddingsMode;
3540
}

model/src/main/java/com/basistech/rosette/apimodel/SimilarTermsOptions.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Basis Technology Corp.
2+
* Copyright 2023 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,4 +42,10 @@ public class SimilarTermsOptions extends Options {
4242
* @return the number of similar terms requested
4343
*/
4444
private final Integer count;
45+
46+
/**
47+
* @return the generation of embeddings to use for all languages, defaulting to second generation embeddings unless
48+
* the language supports first generation embeddings
49+
*/
50+
private EmbeddingsMode embeddingsMode;
4551
}

0 commit comments

Comments
 (0)