Skip to content

Commit 81cd60d

Browse files
authored
fix-common-因缓存无法存记忆 (#2181)
1 parent 3ffc8c3 commit 81cd60d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

common/src/main/java/com/tencent/supersonic/common/service/impl/EmbeddingServiceImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void addQuery(String collectionName, List<TextSegment> queries) {
4949
try {
5050
EmbeddingModel embeddingModel = ModelProvider.getEmbeddingModel();
5151
Embedding embedding = embeddingModel.embed(question).content();
52-
boolean existSegment = existSegment(embeddingStore, query, embedding);
52+
boolean existSegment = existSegment(collectionName,embeddingStore, query, embedding);
5353
if (existSegment) {
5454
continue;
5555
}
@@ -62,14 +62,14 @@ public void addQuery(String collectionName, List<TextSegment> queries) {
6262
}
6363
}
6464

65-
private boolean existSegment(EmbeddingStore embeddingStore, TextSegment query,
65+
private boolean existSegment(String collectionName,EmbeddingStore embeddingStore, TextSegment query,
6666
Embedding embedding) {
6767
String queryId = TextSegmentConvert.getQueryId(query);
6868
if (queryId == null) {
6969
return false;
7070
}
7171
// Check cache first
72-
Boolean cachedResult = cache.getIfPresent(queryId);
72+
Boolean cachedResult = cache.getIfPresent(collectionName+queryId);
7373
if (cachedResult != null) {
7474
return cachedResult;
7575
}
@@ -82,7 +82,7 @@ private boolean existSegment(EmbeddingStore embeddingStore, TextSegment query,
8282
EmbeddingSearchResult result = embeddingStore.search(request);
8383
List<EmbeddingMatch<TextSegment>> relevant = result.matches();
8484
boolean exists = CollectionUtils.isNotEmpty(relevant);
85-
cache.put(queryId, exists);
85+
cache.put(collectionName+queryId, exists);
8686
return exists;
8787
}
8888

0 commit comments

Comments
 (0)