You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RedisVectorStore return incorrect amount of results when calling similaritySearch. It will only return the first 10 documents when topK is greater than 10.
Environment
Spring Ai version: 1.0.0-SNAPSHOT
Java version: 17
Spring Boot version: 3.3.4
Steps to reproduce
Search with topK greater than 10, then RedisVectorStore will only return the first 10 documents.
@TestvoidtestSearch() {
List<Document> documents = List.of(
newDocument("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("meta1", "meta1")),
newDocument("The World is Big and Salvation Lurks Around the Corner"),
newDocument("AAAAAA"),
newDocument("BBBBBB"),
newDocument("CCCCCC"),
newDocument("DDDDDD"),
newDocument("EEEEEE"),
newDocument("FFFFFF"),
newDocument("GGGGGG"),
newDocument("HHHHHH"),
newDocument("IIIIII"),
newDocument("JJJJJJ"),
newDocument("You walk forward facing the past and you turn back toward the future.", Map.of("meta2", "meta2")));
// Add the documents to RedisvectorStore.add(documents);
// Retrieve documents similar to a queryList<Document> results = vectorStore.similaritySearch(SearchRequest.query("Spring").withTopK(12));
results.forEach(System.out::println);
assertThat(results).hasSize(12);
}
Expected behavior
Return correct amount of documents.
Minimal Complete Reproducible example
@TestvoidtestSearch() {
List<Document> documents = List.of(
newDocument("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("meta1", "meta1")),
newDocument("The World is Big and Salvation Lurks Around the Corner"),
newDocument("AAAAAA"),
newDocument("BBBBBB"),
newDocument("CCCCCC"),
newDocument("DDDDDD"),
newDocument("EEEEEE"),
newDocument("FFFFFF"),
newDocument("GGGGGG"),
newDocument("HHHHHH"),
newDocument("IIIIII"),
newDocument("JJJJJJ"),
newDocument("You walk forward facing the past and you turn back toward the future.", Map.of("meta2", "meta2")));
// Add the documents to RedisvectorStore.add(documents);
limits the results to the offset and number of results given. Note that the offset is zero-indexed. The default is 0 10, which returns 10 items starting from the first result. You can use LIMIT 0 0 to count the number of documents in the result set without actually returning them.
Queryquery = newQuery(queryString).addParam(EMBEDDING_PARAM_NAME, RediSearchUtil.toByteArray(embedding))
.returnFields(returnFields.toArray(newString[0]))
.setSortBy(DISTANCE_FIELD_NAME, true)
// Below line should be added
.limit(0, request.getTopK())
.dialect(2);
The text was updated successfully, but these errors were encountered:
Bug description
RedisVectorStore
return incorrect amount of results when callingsimilaritySearch
. It will only return the first 10 documents whentopK
is greater than 10.Environment
Spring Ai version: 1.0.0-SNAPSHOT
Java version: 17
Spring Boot version: 3.3.4
Steps to reproduce
Search with
topK
greater than 10, thenRedisVectorStore
will only return the first 10 documents.Expected behavior
Return correct amount of documents.
Minimal Complete Reproducible example
Fix suggest
Should add
limit
toQuery
according to Redis DocumentThe text was updated successfully, but these errors were encountered: