Skip to content

fix: pass the caller's limit to redisvl in RedisDb.keyword_search - #10781

Merged
sannya-singal merged 3 commits into
agno-agi:mainfrom
Ayoubhm07:fix/redis-keyword-search-limit
Oct 26, 2026
Merged

sannya-singal merged 3 commits into
agno-agi:mainfrom
Ayoubhm07:fix/redis-keyword-search-limit

Conversation

@Ayoubhm07

Copy link
Copy Markdown
Contributor

RedisDb.keyword_search takes a limit and never uses it : the TextQuery it builds omits num_results so redisvl applies its own default of 10

It went unnoticed because two defaults collide : Knowledge.max_results is 10 at knowledge/knowledge.py:92 and TextQuery.num_results is 10 as well
On the stock path you ask for 10 and get 10 : the right answer from the wrong mechanism
Move max_results and it breaks both ways with no exception and no log : ask for 50 get 10 — ask for 3 get 10

Nothing downstream compensates and the comment at knowledge/knowledge.py:245-247 says so :

if self.reranker is None:
    # Unchanged from before this hook existed: the adapter already applied the limit.
    return documents

vector_search at redisdb.py:662 and hybrid_search at :731 share the same signature and both pass num_results=limit
Every query in the file passes it except this one : even the bulk reads annotate why they want everything with num_results=1000, # Get all matching documents
Redis is also the only one of the 8 keyword_search implementations under vectordb/ that drops it

The fix

             text_query = TextQuery(
                 text=query,
                 text_field_name="content",
+                num_results=limit,
                 filter_expression=filter_expression,
             )

Proof

test_keyword_search_passes_the_limit_to_redisvl added beside test_search_vector_keyword_hybrid

Before :

>       assert idx.query.call_args[0][0]._num_results == 3
E       assert 10 == 3
1 failed in 1.89s

After :

59 passed, 3 warnings in 5.78s

The existing test_search_vector_keyword_hybrid could not have caught this : it sets idx.query.return_value itself so len(docs) == 1 holds because the mock was told to return one row and not because limit=1 reached redisvl
The new test asserts on idx.query.call_args : what the adapter asked for rather than what the fake returned

One limitation worth naming : the test reads _num_results which is private
redisvl 0.27.2 exposes no public accessor and the only alternative is asserting on a mocked len() — the exact assertion that let this through

Searched the open pull requests : the two touching vectordb/ are #10545 and #10689 and neither touches redisdb.py

Disclosure per CONTRIBUTING.md point 5 : this change was produced with my claude
Every line number above and the redisvl default were read off the source rather than assumed

keyword_search accepted a limit and never used it. The TextQuery it builds was missing num_results, so redisvl applied its own default of 10 and every keyword search returned at most 10 documents regardless of the request.

vector_search and hybrid_search in the same file, with the same signature, already pass num_results=limit.
@Ayoubhm07
Ayoubhm07 requested a review from a team as a code owner October 3, 2026 11:46

@VANDRANKI VANDRANKI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Community review, not a maintainer review and it does not clear the merge gate. I read the full diff and ran it on Windows with Python 3.13.3, redisvl 0.28.0 and redis-py 8.1.0, against main at 1f2aac5. I did not run it against a live Redis server.

I ran the bug on main and the fix on the PR, and I think the change is correct.

What I ran:

  • With the PR's tests/unit/vectordb/test_redisdb.py on main's source, test_keyword_search_passes_the_limit_to_redisvl fails and the other 11 tests pass. On the PR branch all 12 pass.
  • Built the redisvl TextQuery the way keyword_search does, with and without num_results. Without it the generated arguments end in LIMIT 0 10, with num_results=3 they end in LIMIT 0 3. So on main, keyword_search always asked Redis for 10 results, whatever limit was. The vector and hybrid paths already pass num_results=limit, and keyword_search is the only TextQuery( call site in redisdb.py.

One visible effect: RedisDB.search defaults to limit=5, so on main a default keyword search returned up to 10 documents, and with the fix it returns at most 5. That is the documented behavior, but anyone relying on the accidental 10 will see fewer results. limit values above 10 now work as well.

I did not check what convert_bytes or Document.from_dict do with the query results, since the PR does not touch them.

@Ayoubhm07

Copy link
Copy Markdown
Contributor Author

Thanks for taking it this far. Rebuilding the TextQuery by hand and reading the arguments it generates is the part that actually settles this, and it did not come from me.

You are right about the visible effect, and it is worth saying out loud for whoever merges this.

All four methods on this class declare the same default: search, vector_search, keyword_search and hybrid_search are each limit: int = 5, and three of them honour it. So on main a default vector search already returns 5 while a default keyword search returns 10. The siblings disagree with each other today. This patch does not introduce the 5, it stops keyword_search from being the one method that ignores the number it was handed.

The breakage that is actually reachable runs the other way: anything above 10 was silently capped. Ask for 50, get 10, no exception and no log.

Happy to add a changelog line about the default keyword search returning 5 if you would rather surface it to users.

@Ayoubhm07
Ayoubhm07 requested a review from VANDRANKI October 21, 2026 11:06
@Himanshu040604 Himanshu040604 self-assigned this Oct 26, 2026
@Himanshu040604

Copy link
Copy Markdown
Contributor

Thanks @Ayoubhm07 for your contribution!

@sannya-singal
sannya-singal merged commit 0e950ff into agno-agi:main Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants