mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-17 08:21:12 -05:00
[GH-ISSUE #12150] issue: Bug Report: Controlling Vector Results Count in RAG System #119793
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @chalitbkb on GitHub (Mar 28, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/12150
Problem Description: The number of vector data references related to user inputs remains high even after reducing the "RAG_TOP_K" results to consider for embedding when using RAG, and decreasing the "RAG_TOP_K_RERANKER" results as specified in the documentation. This causes errors in certain models that support small context window sizes, such as OpenAI's services. However, when I switched to using Gemini 2.0 Pro, which supports larger context window sizes, the model successfully generated responses to user questions because Gemini 2.0 Pro can handle a context window size of up to 2 million tokens, thus avoiding this issue. For other models, this problem persists because the "vector" dataset returns an excessive number of aggregated results. Therefore, I attempted to reduce the number of aggregated results from the "vector DB" but was unsuccessful in enabling models that support small context windows to function properly.
Additionally, regarding the "RAG_TOP_K_RERANKER" setting, I do not see it in the UI as the documentation states that "This environment variable is a PersistentConfig variable." I only see the "RAG_TOP_K" and "RAG_RELEVANCE_THRESHOLD" sections. Therefore, I am unsure where the "RAG_TOP_K_RERANKER" setting can be found in the UI as described in the documentation as a "PersistentConfig." I tried setting the number of search results for "vector" by configuring "RAG_TOP_K_RERANKER" directly in the environment variables, but it still did not work.
Summary: Currently, I am experiencing an issue with an excessive number of vector data search results, ranging from 50-100 sets, each containing large content sizes due to my own specifications for Chunk Size and Chunk Overlap. This occurs even though the "RAG_TOP_K" and "RAG_RELEVANCE_THRESHOLD" settings have been configured with lower values.
Check Existing Issues
Installation Method
Docker
Open WebUI Version
v0.5.20
Ollama Version (if applicable)
No response
Operating System
Windows 11
Browser (if applicable)
Chrome 134.0.6998.118
Confirmation
README.md.Expected Behavior
RAG_TOP_K_RERANKER. When this value is set lower, the number of results sent to the LLM model should decrease accordingly.RAG_TOP_K_RERANKERsetting should be possible through the UI or environment variables as specified in the documentation. This value should directly control the amount of data aggregated from the vector database.Actual Behavior
RAG_TOP_Kvalue and settingRAG_TOP_K_RERANKERto a low value, the system continues to send an excessive number of vector results (50-100 sets) to the LLM model.RAG_TOP_K_RERANKERoption is not found in the UI as described in the documentation as a "PersistentConfig variable". OnlyRAG_TOP_KandRAG_RELEVANCE_THRESHOLDare visible.RAG_TOP_K_RERANKERdirectly through environment variables has no effect on reducing the number of vector results.Steps to Reproduce
RAG_TOP_Kto a low value (e.g., 3-5) through the UI.RAG_RELEVANCE_THRESHOLDto a high value (e.g., 0.7-0.8) to limit results.RAG_TOP_K_RERANKERthrough environment variables to a low value (e.g., 3-5).Logs & Screenshots
Try using a model that supports large context windows. The Gemini 2.0 Pro model is capable of processing.

It’s noticeable that the up and down sliders are small, indicating that there are numerous vector data components with many items. I examined the list and found that there are 50 to 100 entries. Even though I attempted to adjust the relevant sections for re-ranking, it still produces a large number of related results.
When testing models with smaller context windows, like the o3-mini, the model couldn't process them because there were too many vector results.

Additional Information
The main issue is the inability to effectively control the number of aggregated vector results through the
RAG_TOP_K_RERANKERsetting as described in the documentation, which prevents proper use of models with context window limitations.@tjbck commented on GitHub (Mar 28, 2025):
Are you 100% sure you configured everything right? @chalitbkb
cc @mahenning
@chalitbkb commented on GitHub (Mar 28, 2025):
I’ve thoroughly reviewed all the relevant documents and feel reasonably confident that I’ve configured everything correctly. However, I’m uncertain if I’ve overlooked something. Even though I’ve tried to reduce the vector aggregation settings, the aggregation results still remain high. Therefore, I’m bringing up this issue.
@mahenning commented on GitHub (Mar 28, 2025):
You wrote you're on Open-WebUI
v0.5.20. Did you clone the repo and run on thedevbranch or do you run Open-WebUI normally and are onv0.5.20? TheRAG_TOP_K_RERANKERfeature is not yet inv0.5.20, only on the dev branch at the moment. The feature is likely included in the next version.When I run Open-WebUI on the dev branch, I get
@mahenning commented on GitHub (Mar 28, 2025):
Ah I see, the variable is already listed in the list of environment variables, because https://github.com/open-webui/docs (the repo for the documentation and stuff) has no
devbranch, an my PR to include the documentation forRAG_TOP_K_RERANKERwas merged into main. It seems the documentation is a bit ahead of the actual features of the main version of Open-WebUI ;)@chalitbkb commented on GitHub (Mar 28, 2025):
Thank you. I'm currently using the DEV version of Open-WebUI and am enjoying the RAG_TOP_K_RERANKER feature. However, I've tested configuring RAG_TOP_K_RERANKER, but I still encounter the aforementioned problem.
@mahenning commented on GitHub (Mar 28, 2025):
Thanks for the fast reply. Just to make sure I follow everything correctly:
Can you tell me how you start your dev version? Maybe our ways of starting/building differ and I can reconstruct it that way.
You said earlier you can neither set the variable in the UI nor as an environment variable, in the comment above you write you're "enjoying the RAG_TOP_K_RERANKER feature". Is it somehow/sometimes working for you now, or still not set-able in both ways?
If you have the local code at hand, can you look into the code if you find "k_reranker"? For instance, it should be a parameter for the function
query_collection_with_hybrid_searchin backend/open_webui/retrieval/utils.py:280.Another question (please don't be mad at me for this), but did you make sure you're on the latest dev version? Did you pull changes/update your local version?
@chalitbkb commented on GitHub (Mar 28, 2025):
Is it currently working intermittently or is it still unable to be configured in both ways?
Ans: I mean, I tried testing with the dev version and found the "RAG_TOP_K_RERANKER" option on the UI. I set it to 1, but it still didn't work. It still returns a large number of vector components. It seems that configuring RAG_TOP_K_RERANKER has no effect.
To your question, "How do I start the development version?"
Ans: I use GHCR to update the version with a Dockerfile like:
@mahenning commented on GitHub (Mar 28, 2025):
(For a (maybe) quick answer and solution, scroll down to the edit. It seems you asked 7 min before a new dev version was pushed)
I tried to reproduce your problem, but alas, "for me it works".. (That sentence again..)
Steps:
docker pull ghcr.io/open-webui/open-webui:devdocker run -p 3003:8080 --add-host=host.docker.internal:host-gateway --name open-webui-dev ghcr.io/open-webui/open-webui :devI used the default settings for chunks, etc. I used
sentence-transformers/all-MiniLM-L6-v2andBAAI/bge-reranker-v2-m3. In the UI, Top K and Top K Reranker were set default to 3 and 3. I changed it to top k=10 and top k reranker=1, uploaded a document in the chat and asked a question. Then I changed the settings to top k=10, top k reranker=5.In the logging of the container, I could see the following (truncated and shortened for readability)
top k reranker = 1:
Batches: 100%|██████████| 1/1 [00:00<00:00, 21.30it/s]
Batches: 100%|██████████| 1/1 [00:02<00:00, 2.06s/it]
2025-03-28 16:08:47.179 | INFO | open_webui.retrieval.utils:query_doc_with_hybrid_search:160 - query_doc_with_hybrid_search:result [...] 'score': 0.11954475939273834} 0.11954475939273834 - {}
Batches: 100%|██████████| 1/1 [00:00<00:00, 3.97it/s]
Batches: 100%|██████████| 1/1 [00:02<00:00, 2.14s/it]
2025-03-28 16:08:49.613 | INFO | open_webui.retrieval.utils:query_doc_with_hybrid_search:160 - query_doc_with_hybrid_search:result [...] 'score': 0.01118550170212984} 0.01118550170212984 - {}
Batches: 100%|██████████| 1/1 [00:00<00:00, 71.87it/s]
Batches: 100%|██████████| 1/1 [00:01<00:00, 1.90s/it]
2025-03-28 16:08:51.567 | INFO | open_webui.retrieval.utils:query_doc_with_hybrid_search:160 - query_doc_with_hybrid_search:result [....] 'score': 0.017430100589990616} 0.017430100589990616 - {}
top k reranker=5
Batches: 100%|██████████| 1/1 [00:00<00:00, 21.85it/s]
Batches: 100%|██████████| 1/1 [00:02<00:00, 2.07s/it]
2025-03-28 16:09:59.597 | INFO | open_webui.retrieval.utils:query_doc_with_hybrid_search:160 - query_doc_with_hybrid_search:result 'score': 0.002910345559939742} 0.01118550170212984, 0.009643329307436943, 0.006689450703561306, 0.0032938995864242315, 0.002910345559939742 - {}
Batches: 100%|██████████| 1/1 [00:00<00:00, 97.11it/s]
Batches: 100%|██████████| 1/1 [00:01<00:00, 1.57s/it]
2025-03-28 16:10:01.210 | INFO | open_webui.retrieval.utils:query_doc_with_hybrid_search:160 - query_doc_with_hybrid_search:result 'score': 0.0007439087494276464} 0.007581176236271858, 0.003316872753202915, 0.0012548574013635516, 0.0012110307579860091, 0.0007439087494276464 - {}
Batches: 100%|██████████| 1/1 [00:00<00:00, 74.65it/s]
Batches: 100%|██████████| 1/1 [00:01<00:00, 1.96s/it]
2025-03-28 16:10:03.216 | INFO | open_webui.retrieval.utils:query_doc_with_hybrid_search:160 - query_doc_with_hybrid_search:result 'score': 0.0025328141637146473} 0.01953815668821335, 0.016017155721783638, 0.011503961868584156, 0.008491785265505314, 0.0025328141637146473 - {}
I tried to highlight the important part bold. Each chat question started 3 queries for documents. You can see that for top k reranker=1, there is only one score vector at the end in bold, while for top k reranker=5 there are 5 scores each. This and the fact that I got many more references with top k reranker=5 shows me that it worked, at least for me.
The question now is, why is it not working for you? You could try to again pull the newest image for dev. Both your issue and the newest dev image are "6 hours ago" and for the image, I can not see the exact time it got pushed. It could be that your image version is not the latest anymore?
Edit: Okay, found the time (2025-03-28T02:37:39-7:00), which is apparently 9:37 (UTC, London time). You started the issue at 9:30 UTC if I'm not mistaken, so the newest image should be newer than your issue. Can you re-pull and try again? :)
@chalitbkb commented on GitHub (Mar 28, 2025):
@mahenning
I'm confident that it's the latest version, but I'm still encountering this problem. The results from the vector data still have too many components, even after reducing the Top K and Top K Reranker.
@chalitbkb commented on GitHub (Mar 28, 2025):
@mahenning
Then I switched to using the Gemini model to test how many results obtained from the vector were discovered. I found that there were still many items even though the model was able to respond to me. This means that the "RAG_TOP_K_RERANKER" setting was not actually implemented or may be due to a defect elsewhere.
@mahenning commented on GitHub (Mar 28, 2025):
I see in your screenshot below that "full context mode" is enabled. If thats enabled, the full document(s) are loaded into the chat, disabling the "chunking -> scoring -> reranking" pipeline that retrieves only (relevant) chunks of the documents. That could also explain your many results, and why top k and top k reranker settings are ignored. There is no filtering for the best, the LLM gets it all.
@mahenning commented on GitHub (Mar 28, 2025):
@tjbck Maybe it would be a good ida to hide the hybrid / top k / etc stuff if full context mode is enabled to signal that these settings are ignored in that case.
@tjbck commented on GitHub (Mar 28, 2025):
@mahenning Addressed with 0413c747a9ba33275dc4e4d3146581ed52979474!
@mahenning commented on GitHub (Mar 28, 2025):
Committed 2 mins ago? That was ninja-level fast.
@chalitbkb commented on GitHub (Mar 28, 2025):
@mahenning
I was so focused on a tiny problem, it was like staring at a breadcrumb and forgetting I had a whole pizza!🍕😂
Thank you, it's working now. However, there seems to be a 20-30 second delay for the RERANKER.
@mahenning commented on GitHub (Mar 28, 2025):
If Open-WebUI does not run with GPU support, the embedding/reranking models runs on CPU. Depending on how many document chunks have to be reranked, this could take a while. Embedding only has do be done one time per document, reranking every time you ask something in the chat with documents available. If you habe a few GB VRAM to spare, you can run the
:cuda(or :dev-cuda) image.Would be actually a nice PR to enable e.g. only the reranker to GPU and letting the embedding model run on CPU..