Skip to content

Commit 89bac8b

Browse files
add refresh policy; add checkpoint id field (#4305) (#4306)
(cherry picked from commit 709ba4b) Signed-off-by: Yaliang Wu <[email protected]> Co-authored-by: Yaliang Wu <[email protected]>
1 parent 2f717c0 commit 89bac8b

File tree

10 files changed

+224
-185
lines changed

10 files changed

+224
-185
lines changed

common/src/main/java/org/opensearch/ml/common/memorycontainer/MLWorkingMemory.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
99
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.AGENT_ID_FIELD;
1010
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.BINARY_DATA_FIELD;
11+
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.CHECKPOINT_ID_FIELD;
1112
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.CREATED_TIME_FIELD;
1213
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.INFER_FIELD;
1314
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.LAST_UPDATED_TIME_FIELD;
@@ -68,6 +69,9 @@ public class MLWorkingMemory implements ToXContentObject, Writeable {
6869
private Instant lastUpdateTime;
6970
private String ownerId;
7071

72+
// Checkpoint field
73+
private String checkpointId;
74+
7175
@Builder
7276
public MLWorkingMemory(
7377
String memoryContainerId,
@@ -82,7 +86,8 @@ public MLWorkingMemory(
8286
Map<String, String> tags,
8387
Instant createdTime,
8488
Instant lastUpdateTime,
85-
String ownerId
89+
String ownerId,
90+
String checkpointId
8691
) {
8792
// MAX_MESSAGES_PER_REQUEST limit removed for performance testing
8893

@@ -100,6 +105,7 @@ public MLWorkingMemory(
100105
this.createdTime = createdTime;
101106
this.lastUpdateTime = lastUpdateTime;
102107
this.ownerId = ownerId;
108+
this.checkpointId = checkpointId;
103109
}
104110

105111
public MLWorkingMemory(StreamInput in) throws IOException {
@@ -131,6 +137,7 @@ public MLWorkingMemory(StreamInput in) throws IOException {
131137
this.createdTime = in.readOptionalInstant();
132138
this.lastUpdateTime = in.readOptionalInstant();
133139
this.ownerId = in.readOptionalString();
140+
this.checkpointId = in.readOptionalString();
134141
}
135142

136143
@Override
@@ -177,6 +184,7 @@ public void writeTo(StreamOutput out) throws IOException {
177184
out.writeOptionalInstant(createdTime);
178185
out.writeOptionalInstant(lastUpdateTime);
179186
out.writeOptionalString(ownerId);
187+
out.writeOptionalString(checkpointId);
180188
}
181189

182190
@Override
@@ -225,6 +233,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
225233
if (ownerId != null) {
226234
builder.field(OWNER_ID_FIELD, ownerId);
227235
}
236+
if (checkpointId != null) {
237+
builder.field(CHECKPOINT_ID_FIELD, checkpointId);
238+
}
228239
builder.endObject();
229240
return builder;
230241
}
@@ -243,6 +254,7 @@ public static MLWorkingMemory parse(XContentParser parser) throws IOException {
243254
Instant createdTime = null;
244255
Instant lastUpdateTime = null;
245256
String ownerId = null;
257+
String checkpointId = null;
246258

247259
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
248260
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
@@ -293,6 +305,9 @@ public static MLWorkingMemory parse(XContentParser parser) throws IOException {
293305
case OWNER_ID_FIELD:
294306
ownerId = parser.text();
295307
break;
308+
case CHECKPOINT_ID_FIELD:
309+
checkpointId = parser.text();
310+
break;
296311
default:
297312
parser.skipChildren();
298313
break;
@@ -314,6 +329,7 @@ public static MLWorkingMemory parse(XContentParser parser) throws IOException {
314329
.createdTime(createdTime)
315330
.lastUpdateTime(lastUpdateTime)
316331
.ownerId(ownerId)
332+
.checkpointId(checkpointId)
317333
.build();
318334
}
319335

common/src/main/java/org/opensearch/ml/common/memorycontainer/MemoryContainerConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public class MemoryContainerConstants {
8686
public static final String TEXT_FIELD = "text";
8787
public static final String UPDATE_CONTENT_FIELD = "update_content";
8888

89+
// Checkpoint field
90+
public static final String CHECKPOINT_ID_FIELD = "checkpoint_id";
91+
8992
// KNN index settings
9093
public static final String KNN_ENGINE = "lucene";
9194
public static final String KNN_SPACE_TYPE = "cosinesimil";

common/src/main/java/org/opensearch/ml/common/transport/memorycontainer/memory/MLAddMemoriesInput.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
99
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.AGENT_ID_FIELD;
1010
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.BINARY_DATA_FIELD;
11+
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.CHECKPOINT_ID_FIELD;
1112
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.CREATED_TIME_FIELD;
1213
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.INFER_FIELD;
1314
import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.LAST_UPDATED_TIME_FIELD;
@@ -69,6 +70,9 @@ public class MLAddMemoriesInput implements ToXContentObject, Writeable {
6970
private Map<String, Object> parameters;
7071
private String ownerId;
7172

73+
// Checkpoint field
74+
private String checkpointId;
75+
7276
public MLAddMemoriesInput(
7377
String memoryContainerId,
7478
PayloadType payloadType,
@@ -81,7 +85,8 @@ public MLAddMemoriesInput(
8185
Map<String, String> metadata,
8286
Map<String, String> tags,
8387
Map<String, Object> parameters,
84-
String ownerId
88+
String ownerId,
89+
String checkpointId
8590
) {
8691
// MAX_MESSAGES_PER_REQUEST limit removed for performance testing
8792

@@ -100,6 +105,7 @@ public MLAddMemoriesInput(
100105
this.parameters.putAll(parameters);
101106
}
102107
this.ownerId = ownerId;
108+
this.checkpointId = checkpointId;
103109
validate();
104110
}
105111

@@ -144,6 +150,7 @@ public MLAddMemoriesInput(StreamInput in) throws IOException {
144150
this.parameters = in.readMap();
145151
}
146152
this.ownerId = in.readOptionalString();
153+
this.checkpointId = in.readOptionalString();
147154
}
148155

149156
@Override
@@ -193,6 +200,7 @@ public void writeTo(StreamOutput out) throws IOException {
193200
out.writeBoolean(false);
194201
}
195202
out.writeOptionalString(ownerId);
203+
out.writeOptionalString(checkpointId);
196204
}
197205

198206
@Override
@@ -239,6 +247,9 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
239247
if (ownerId != null) {
240248
builder.field(OWNER_ID_FIELD, ownerId);
241249
}
250+
if (checkpointId != null) {
251+
builder.field(CHECKPOINT_ID_FIELD, checkpointId);
252+
}
242253
if (withTimeStamp) {
243254
Instant now = Instant.now();
244255
builder.field(CREATED_TIME_FIELD, now.toEpochMilli());
@@ -260,6 +271,7 @@ public static MLAddMemoriesInput parse(XContentParser parser, String memoryConta
260271
Map<String, String> tags = null;
261272
Map<String, Object> parameters = null;
262273
String ownerId = null;
274+
String checkpointId = null;
263275

264276
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
265277
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
@@ -307,6 +319,9 @@ public static MLAddMemoriesInput parse(XContentParser parser, String memoryConta
307319
case OWNER_ID_FIELD:
308320
ownerId = parser.text();
309321
break;
322+
case CHECKPOINT_ID_FIELD:
323+
checkpointId = parser.text();
324+
break;
310325
default:
311326
parser.skipChildren();
312327
break;
@@ -327,6 +342,7 @@ public static MLAddMemoriesInput parse(XContentParser parser, String memoryConta
327342
.tags(tags)
328343
.parameters(parameters)
329344
.ownerId(ownerId)
345+
.checkpointId(checkpointId)
330346
.build();
331347
}
332348

common/src/main/resources/index-mappings/ml_memory_working.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"message_id": {
2727
"type": "integer"
2828
},
29+
"checkpoint_id": {
30+
"type": "keyword"
31+
},
2932
"binary_data": {
3033
"type": "binary"
3134
},

0 commit comments

Comments
 (0)