|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -package org.springframework.ai.model.chat.memory.mongodb.autoconfigure; |
| 17 | +package org.springframework.ai.model.chat.memory.mongo.autoconfigure; |
18 | 18 |
|
19 | 19 | import org.slf4j.Logger;
|
20 | 20 | import org.slf4j.LoggerFactory;
|
21 |
| -import org.springframework.ai.chat.memory.mongodb.Conversation; |
| 21 | +import org.springframework.ai.chat.memory.mongo.Conversation; |
22 | 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
23 | 23 | import org.springframework.context.event.ContextRefreshedEvent;
|
24 | 24 | import org.springframework.context.event.EventListener;
|
|
33 | 33 | * field if the TTL is set in properties.
|
34 | 34 | *
|
35 | 35 | * @author Łukasz Jernaś
|
36 |
| - * @see MongoDbChatMemoryProperties |
| 36 | + * @see MongoChatMemoryProperties |
37 | 37 | * @since 1.0.0
|
38 | 38 | */
|
39 | 39 | @Component
|
40 | 40 | @ConditionalOnProperty(value = "spring.ai.chat.memory.mongodb.create-indices", havingValue = "true")
|
41 |
| -public class MongoDbChatMemoryIndexCreator { |
| 41 | +public class MongoChatMemoryIndexCreator { |
42 | 42 |
|
43 |
| - private static final Logger logger = LoggerFactory.getLogger(MongoDbChatMemoryIndexCreator.class); |
| 43 | + private static final Logger logger = LoggerFactory.getLogger(MongoChatMemoryIndexCreator.class); |
44 | 44 |
|
45 | 45 | private final MongoTemplate mongoTemplate;
|
46 | 46 |
|
47 |
| - private final MongoDbChatMemoryProperties mongoDbChatMemoryProperties; |
| 47 | + private final MongoChatMemoryProperties mongoChatMemoryProperties; |
48 | 48 |
|
49 |
| - public MongoDbChatMemoryIndexCreator(MongoTemplate mongoTemplate, |
50 |
| - MongoDbChatMemoryProperties mongoDbChatMemoryProperties) { |
| 49 | + public MongoChatMemoryIndexCreator(MongoTemplate mongoTemplate, |
| 50 | + MongoChatMemoryProperties mongoChatMemoryProperties) { |
51 | 51 | this.mongoTemplate = mongoTemplate;
|
52 |
| - this.mongoDbChatMemoryProperties = mongoDbChatMemoryProperties; |
| 52 | + this.mongoChatMemoryProperties = mongoChatMemoryProperties; |
53 | 53 | }
|
54 | 54 |
|
55 | 55 | @EventListener(ContextRefreshedEvent.class)
|
56 | 56 | public void initIndicesAfterStartup() {
|
57 | 57 | logger.info("Creating MongoDB indices for ChatMemory");
|
58 | 58 | // Create a main index
|
59 | 59 | mongoTemplate.indexOps(Conversation.class)
|
60 |
| - .ensureIndex(new Index().on("conversationId", Sort.Direction.ASC).on("timestamp", Sort.Direction.DESC)); |
| 60 | + .ensureIndex(new Index().on("conversationId", Sort.Direction.ASC).on("timestamp", Sort.Direction.DESC)); |
61 | 61 |
|
62 | 62 | createOrUpdateTtlIndex();
|
63 | 63 | }
|
64 | 64 |
|
65 | 65 | private void createOrUpdateTtlIndex() {
|
66 |
| - if (!this.mongoDbChatMemoryProperties.getTtl().isZero()) { |
| 66 | + if (!this.mongoChatMemoryProperties.getTtl().isZero()) { |
67 | 67 | // Check for existing TTL index
|
68 | 68 | mongoTemplate.indexOps(Conversation.class).getIndexInfo().forEach(idx -> {
|
69 | 69 | if (idx.getExpireAfter().isPresent()
|
70 |
| - && !idx.getExpireAfter().get().equals(this.mongoDbChatMemoryProperties.getTtl())) { |
| 70 | + && !idx.getExpireAfter().get().equals(this.mongoChatMemoryProperties.getTtl())) { |
71 | 71 | logger.warn("Dropping existing TTL index, because TTL is different");
|
72 | 72 | mongoTemplate.indexOps(Conversation.class).dropIndex(idx.getName());
|
73 | 73 | }
|
74 | 74 | });
|
75 | 75 | mongoTemplate.indexOps(Conversation.class)
|
76 |
| - .ensureIndex(new Index().on("timestamp", Sort.Direction.ASC) |
77 |
| - .expire(this.mongoDbChatMemoryProperties.getTtl())); |
| 76 | + .ensureIndex(new Index().on("timestamp", Sort.Direction.ASC) |
| 77 | + .expire(this.mongoChatMemoryProperties.getTtl())); |
78 | 78 | }
|
79 | 79 | }
|
80 | 80 |
|
|
0 commit comments