Skip to content

Commit 44d4b29

Browse files
committed
Fix java build
1 parent 984f438 commit 44d4b29

14 files changed

Lines changed: 298 additions & 221 deletions

File tree

‎java/connectors/semantickernel-connectors-memory-redis/src/main/java/com/microsoft/semantickernel/connectors/memory/redis/JsonMemoryRecord.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import com.microsoft.semantickernel.ai.embeddings.Embedding;
77
import com.microsoft.semantickernel.memory.MemoryRecord;
88
import com.microsoft.semantickernel.memory.MemoryRecordMetadata;
9-
10-
import javax.annotation.Nullable;
119
import java.nio.charset.StandardCharsets;
1210
import java.util.*;
11+
import javax.annotation.Nullable;
1312

1413
/** Represents an entry in the Semantic Kernel Memory Table. */
1514
public class JsonMemoryRecord {
@@ -49,7 +48,6 @@ public JsonMemoryRecord(
4948
this.isReference = isReference;
5049
}
5150

52-
5351
/**
5452
* Record ID. The record is not filterable to save quota, also SK uses only semantic search.
5553
*
@@ -169,5 +167,4 @@ static String decodeId(@Nullable String encodedId) {
169167
byte[] bytes = Base64.getUrlDecoder().decode(encodedId.getBytes(StandardCharsets.UTF_8));
170168
return new String(bytes, StandardCharsets.UTF_8);
171169
}
172-
173170
}

‎java/connectors/semantickernel-connectors-memory-redis/src/main/java/com/microsoft/semantickernel/connectors/memory/redis/RedisException.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package com.microsoft.semantickernel.connectors.memory.redis;
33

44
import com.microsoft.semantickernel.SKException;
5-
65
import javax.annotation.Nonnull;
76
import javax.annotation.Nullable;
87

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// Copyright (c) Microsoft. All rights reserved.
12
package com.microsoft.semantickernel.connectors.memory.redis;
23

34
public class RedisIndexSchemaParams {
45

5-
public static final String TYPE = "TYPE";
6-
public static final String DIM = "DIM";
7-
public static final String DIST = "DISTANCE_METRIC";
6+
public static final String TYPE = "TYPE";
7+
public static final String DIM = "DIM";
8+
public static final String DIST = "DISTANCE_METRIC";
89
}

‎java/connectors/semantickernel-connectors-memory-redis/src/main/java/com/microsoft/semantickernel/connectors/memory/redis/RedisMemoryRecord.java‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,40 @@
44
import com.fasterxml.jackson.core.JsonProcessingException;
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.microsoft.semantickernel.ai.embeddings.Embedding;
7-
import com.microsoft.semantickernel.memory.DataEntryBase;
87
import com.microsoft.semantickernel.memory.MemoryRecord;
9-
import redis.clients.jedis.search.Document;
10-
118
import java.time.ZonedDateTime;
129
import java.util.HashMap;
1310
import java.util.List;
1411
import java.util.Map;
1512
import java.util.stream.Collectors;
1613
import java.util.stream.StreamSupport;
14+
import redis.clients.jedis.search.Document;
1715

1816
/** Represents an entry in the Semantic Kernel Memory Table. */
1917
public class RedisMemoryRecord extends JsonMemoryRecord {
2018

21-
public RedisMemoryRecord(String id, String text, String description, String additionalMetadata,
22-
List<Float> embedding, String externalSourceName, boolean isReference) {
23-
super(id, text, description, additionalMetadata, embedding, externalSourceName, isReference);
19+
public RedisMemoryRecord(
20+
String id,
21+
String text,
22+
String description,
23+
String additionalMetadata,
24+
List<Float> embedding,
25+
String externalSourceName,
26+
boolean isReference) {
27+
super(
28+
id,
29+
text,
30+
description,
31+
additionalMetadata,
32+
embedding,
33+
externalSourceName,
34+
isReference);
2435
}
2536

2637
/**
2738
* Converts a RedisSearch Document to a HashMap.
2839
*
2940
* @param document A Redis Search Document
30-
*
3141
* @return A HashMap containing the iterator's entries
3242
*/
3343
protected Map<String, Object> documentToMap(Document document) {
@@ -39,8 +49,8 @@ protected Map<String, Object> documentToMap(Document document) {
3949
* Gets the embedding information associated with the entry.
4050
*
4151
* @param map A hashmap with keys representing a record
42-
* @param withEmbedding A boolean flag indicating that the embedding should be returned with the metadata
43-
*
52+
* @param withEmbedding A boolean flag indicating that the embedding should be returned with the
53+
* metadata
4454
* @return A MemoryRecord object.
4555
*/
4656
public static MemoryRecord mapToRecord(Map<String, String> map, boolean withEmbedding) {
@@ -49,17 +59,18 @@ public static MemoryRecord mapToRecord(Map<String, String> map, boolean withEmbe
4959
ObjectMapper mapper = new ObjectMapper();
5060
try {
5161
if (map.get(TIME) != null) {
52-
time = mapper.readValue(map.getOrDefault(TIME, ZonedDateTime.now().toString()), ZonedDateTime.class);
62+
time =
63+
mapper.readValue(
64+
map.getOrDefault(TIME, ZonedDateTime.now().toString()),
65+
ZonedDateTime.class);
5366
}
5467
if (withEmbedding) {
5568
List<Float> embeddings = mapper.readValue(map.get(EMBEDDING), List.class);
5669
embedding = new Embedding(embeddings);
5770
}
5871
} catch (JsonProcessingException e) {
5972
throw new RedisException(
60-
RedisException.ErrorCodes.REDIS_ERROR,
61-
"Error deserializing Redis entry",
62-
e);
73+
RedisException.ErrorCodes.REDIS_ERROR, "Error deserializing Redis entry", e);
6374
}
6475

6576
return MemoryRecord.localRecord(
@@ -69,15 +80,13 @@ public static MemoryRecord mapToRecord(Map<String, String> map, boolean withEmbe
6980
embedding,
7081
map.get(ADDITIONAL_METADATA),
7182
map.get(EXTERNAL_SOURCE_NAME),
72-
time
73-
);
83+
time);
7484
}
7585

7686
/**
7787
* Gets the embedding information associated with the entry.
7888
*
7989
* @param record A MemoryRecord object
80-
*
8190
* @return A hashmap containing the entries of the record.
8291
*/
8392
public static Map<String, Object> recordToMap(MemoryRecord record) {

0 commit comments

Comments
 (0)