wenjin272 commented on code in PR #425: URL: https://github.com/apache/flink-agents/pull/425#discussion_r2681067843
########## runtime/src/main/java/org/apache/flink/agents/runtime/memory/VectorStoreLongTermMemory.java: ########## @@ -0,0 +1,307 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.flink.agents.runtime.memory; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.flink.agents.api.context.RunnerContext; +import org.apache.flink.agents.api.memory.BaseLongTermMemory; +import org.apache.flink.agents.api.memory.LongTermMemoryOptions; +import org.apache.flink.agents.api.memory.MemorySet; +import org.apache.flink.agents.api.memory.MemorySetItem; +import org.apache.flink.agents.api.memory.compaction.CompactionStrategy; +import org.apache.flink.agents.api.resource.ResourceType; +import org.apache.flink.agents.api.vectorstores.BaseVectorStore; +import org.apache.flink.agents.api.vectorstores.CollectionManageableVectorStore; +import org.apache.flink.agents.api.vectorstores.CollectionManageableVectorStore.Collection; +import org.apache.flink.agents.api.vectorstores.Document; +import org.apache.flink.agents.api.vectorstores.VectorStoreQuery; +import org.apache.flink.agents.api.vectorstores.VectorStoreQueryResult; +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.util.ExecutorUtils; +import org.apache.flink.util.concurrent.ExecutorThreadFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static org.apache.flink.agents.runtime.memory.CompactionFunctions.summarize; + +public class VectorStoreLongTermMemory implements BaseLongTermMemory { + private static final Logger LOG = LoggerFactory.getLogger(VectorStoreLongTermMemory.class); + + public static final ObjectMapper mapper = new ObjectMapper(); + public static final DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; + + private final RunnerContext ctx; + private final boolean asyncCompaction; + + private String jobId; + private String key; + private transient ExecutorService lazyCompactExecutor; + private Object vectorStore; + + public VectorStoreLongTermMemory(RunnerContext ctx, Object vectorStore, String jobId) { + this(ctx, vectorStore, jobId, null); + } + + @VisibleForTesting + public VectorStoreLongTermMemory( + RunnerContext ctx, Object vectorStore, String jobId, String key) { + this.ctx = ctx; + this.vectorStore = vectorStore; + this.jobId = jobId; + this.key = key; + this.asyncCompaction = ctx.getConfig().get(LongTermMemoryOptions.ASYNC_COMPACTION); + } + + @Override + public void switchContext(String key) { + this.key = key; Review Comment: Currently, python will create a new LTM object each time when switch context. Because the underlying resource is reused, it won't cause too much cost. After we unify the implementation of LTM to java, this should be also removed in python. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
