Skip to content

Commit 7681b0e

Browse files
author
Milder Hernandez
authored
Merge pull request #225 from johnoliver/hsqldb-2
Add support for HSQLDB store
2 parents 6600f4a + 96e5a3e commit 7681b0e

File tree

25 files changed

+866
-233
lines changed

25 files changed

+866
-233
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Upgraded to openai sdk 1.0.0-beta.11
55
- Added convenience method `FunctionInvocation.withResultTypeAutoConversion` which sets the return type and registers a
66
type converter based on Jackson for the return type.
7+
- Added localization support for error/debug messages
78

89
### Bug Fixes
910

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ in a different direction, but also to consider the impact on the larger ecosyste
5050
To learn more and get started:
5151

5252
- Read the [documentation](https://learn.microsoft.com/en-us/semantic-kernel/overview/?tabs=Java&pivots=programming-language-java)
53-
- Learn how to [contribute](https://learn.microsoft.com/en-us/semantic-kernel/get-started/contributing?tabs=Java&pivots=programming-language-java) to the project
53+
- Learn how to [contribute](https://learn.microsoft.com/en-us/semantic-kernel/support/contributing?tabs=Java&pivots=programming-language-java) to the project
5454
- Join the [Discord community](https://aka.ms/SKDiscord)
5555
- Attend [regular office hours and SK community events](COMMUNITY.md)
5656
- Follow the team on our [blog](https://aka.ms/sk/blog)

aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/textembedding/OpenAITextEmbeddingGenerationService.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,37 @@
88
import com.microsoft.semantickernel.aiservices.openai.OpenAiService;
99
import com.microsoft.semantickernel.exceptions.AIException;
1010
import com.microsoft.semantickernel.services.openai.OpenAiServiceBuilder;
11-
import com.microsoft.semantickernel.services.textcompletion.TextGenerationService;
1211
import com.microsoft.semantickernel.services.textembedding.Embedding;
1312
import com.microsoft.semantickernel.services.textembedding.TextEmbeddingGenerationService;
13+
import java.util.ArrayList;
14+
import java.util.Arrays;
15+
import java.util.List;
16+
import javax.annotation.Nullable;
1417
import org.slf4j.Logger;
1518
import org.slf4j.LoggerFactory;
1619
import reactor.core.publisher.Mono;
1720

18-
import javax.annotation.Nullable;
19-
import java.util.ArrayList;
20-
import java.util.List;
21-
2221
/**
2322
* An OpenAI implementation of a {@link TextEmbeddingGenerationService}.
24-
*
2523
*/
2624
public class OpenAITextEmbeddingGenerationService extends OpenAiService<OpenAIAsyncClient>
2725
implements TextEmbeddingGenerationService {
26+
2827
private static final Logger LOGGER = LoggerFactory
2928
.getLogger(OpenAITextEmbeddingGenerationService.class);
3029
private static final int DEFAULT_DIMENSIONS = 1536;
3130
private final int dimensions;
3231

32+
public static final int EMBEDDING_DIMENSIONS_SMALL = 1536;
33+
public static final int EMBEDDING_DIMENSIONS_LARGE = 3072;
34+
3335
/**
3436
* Creates a new {@link OpenAITextEmbeddingGenerationService}.
3537
*
36-
* @param client OpenAI client
38+
* @param client OpenAI client
3739
* @param deploymentName deployment name
38-
* @param modelId OpenAI model id
39-
* @param serviceId Service id
40+
* @param modelId OpenAI model id
41+
* @param serviceId Service id
4042
*/
4143
public OpenAITextEmbeddingGenerationService(
4244
OpenAIAsyncClient client,
@@ -57,6 +59,24 @@ public static Builder builder() {
5759
return new Builder();
5860
}
5961

62+
/**
63+
* Generates embeddings for the given data.
64+
*
65+
* @param data The data to generate embeddings for.
66+
* @return A Mono that completes with the embeddings.
67+
*/
68+
@Override
69+
public Mono<Embedding> generateEmbeddingAsync(String data) {
70+
return this.internalGenerateTextEmbeddingsAsync(Arrays.asList(data))
71+
.flatMap(embeddings -> {
72+
if (embeddings.isEmpty()) {
73+
return Mono.empty();
74+
}
75+
76+
return Mono.just(embeddings.get(0));
77+
});
78+
}
79+
6080
/**
6181
* Generates embeddings for the given data.
6282
*
@@ -88,6 +108,7 @@ protected Mono<List<Embedding>> internalGenerateTextEmbeddingsAsync(List<String>
88108
*/
89109
public static class Builder extends
90110
OpenAiServiceBuilder<OpenAIAsyncClient, OpenAITextEmbeddingGenerationService, OpenAITextEmbeddingGenerationService.Builder> {
111+
91112
private int dimensions = DEFAULT_DIMENSIONS;
92113

93114
/**

api-test/integration-tests/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@
122122
<artifactId>jsonschema-module-jackson</artifactId>
123123
<scope>test</scope>
124124
</dependency>
125+
126+
127+
<dependency>
128+
<groupId>org.hsqldb</groupId>
129+
<artifactId>hsqldb</artifactId>
130+
<version>2.7.3</version>
131+
<scope>test</scope>
132+
</dependency>
125133
</dependencies>
126134

127135
<dependencyManagement>

api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/connectors/memory/jdbc/Hotel.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.microsoft.semantickernel.data.vectorstorage.attributes.VectorStoreRecordDataAttribute;
66
import com.microsoft.semantickernel.data.vectorstorage.attributes.VectorStoreRecordKeyAttribute;
77
import com.microsoft.semantickernel.data.vectorstorage.attributes.VectorStoreRecordVectorAttribute;
8+
import com.microsoft.semantickernel.data.vectorstorage.definition.DistanceFunction;
89

910
import java.util.List;
1011

@@ -24,19 +25,19 @@ public class Hotel {
2425
private final String description;
2526

2627
@JsonProperty("summaryEmbedding1")
27-
@VectorStoreRecordVectorAttribute(dimensions = 8, distanceFunction = "euclidean")
28+
@VectorStoreRecordVectorAttribute(dimensions = 8, distanceFunction = DistanceFunction.EUCLIDEAN_DISTANCE)
2829
private final List<Float> euclidean;
2930

3031
@JsonProperty("summaryEmbedding2")
31-
@VectorStoreRecordVectorAttribute(dimensions = 8, distanceFunction = "cosineDistance")
32+
@VectorStoreRecordVectorAttribute(dimensions = 8, distanceFunction = DistanceFunction.COSINE_DISTANCE)
3233
private final List<Float> cosineDistance;
3334

3435
@JsonProperty("summaryEmbedding3")
35-
@VectorStoreRecordVectorAttribute(dimensions = 8, distanceFunction = "dotProduct")
36+
@VectorStoreRecordVectorAttribute(dimensions = 8, distanceFunction = DistanceFunction.DOT_PRODUCT)
3637
private final List<Float> dotProduct;
3738

3839
@JsonProperty("indexedSummaryEmbedding")
39-
@VectorStoreRecordVectorAttribute(dimensions = 8, indexKind = "hnsw", distanceFunction = "euclidean")
40+
@VectorStoreRecordVectorAttribute(dimensions = 8, indexKind = "hnsw", distanceFunction = DistanceFunction.EUCLIDEAN_DISTANCE)
4041
private final List<Float> indexedEuclidean;
4142
@VectorStoreRecordDataAttribute
4243
private double rating;

0 commit comments

Comments
 (0)