mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
fix-common-因缓存无法存记忆 (#2181)
This commit is contained in:
@@ -49,7 +49,7 @@ public class EmbeddingServiceImpl implements EmbeddingService {
|
|||||||
try {
|
try {
|
||||||
EmbeddingModel embeddingModel = ModelProvider.getEmbeddingModel();
|
EmbeddingModel embeddingModel = ModelProvider.getEmbeddingModel();
|
||||||
Embedding embedding = embeddingModel.embed(question).content();
|
Embedding embedding = embeddingModel.embed(question).content();
|
||||||
boolean existSegment = existSegment(embeddingStore, query, embedding);
|
boolean existSegment = existSegment(collectionName,embeddingStore, query, embedding);
|
||||||
if (existSegment) {
|
if (existSegment) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -62,14 +62,14 @@ public class EmbeddingServiceImpl implements EmbeddingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean existSegment(EmbeddingStore embeddingStore, TextSegment query,
|
private boolean existSegment(String collectionName,EmbeddingStore embeddingStore, TextSegment query,
|
||||||
Embedding embedding) {
|
Embedding embedding) {
|
||||||
String queryId = TextSegmentConvert.getQueryId(query);
|
String queryId = TextSegmentConvert.getQueryId(query);
|
||||||
if (queryId == null) {
|
if (queryId == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check cache first
|
// Check cache first
|
||||||
Boolean cachedResult = cache.getIfPresent(queryId);
|
Boolean cachedResult = cache.getIfPresent(collectionName+queryId);
|
||||||
if (cachedResult != null) {
|
if (cachedResult != null) {
|
||||||
return cachedResult;
|
return cachedResult;
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ public class EmbeddingServiceImpl implements EmbeddingService {
|
|||||||
EmbeddingSearchResult result = embeddingStore.search(request);
|
EmbeddingSearchResult result = embeddingStore.search(request);
|
||||||
List<EmbeddingMatch<TextSegment>> relevant = result.matches();
|
List<EmbeddingMatch<TextSegment>> relevant = result.matches();
|
||||||
boolean exists = CollectionUtils.isNotEmpty(relevant);
|
boolean exists = CollectionUtils.isNotEmpty(relevant);
|
||||||
cache.put(queryId, exists);
|
cache.put(collectionName+queryId, exists);
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user