Dify retrieval node returns empty results when knowledge base has many documents
Why Dify workflow retrieval returns empty results with a large knowledge base, how to confirm the thread-pool failure, and how to fix or route around it.
The symptom
You have a self-hosted Dify instance, you load a knowledge base with a few hundred documents, and the workflow retrieval node stops returning anything. The query is fine: if you run the same query in the knowledge base retrieval testing panel, you get hits. Run it through the retrieval node inside a workflow or chatflow and the node output is an empty result set, so downstream LLM nodes receive no context and answer from the prompt alone.
The distinguishing detail in this thread is the count boundary. With all 200 documents active the workflow node returned nothing; after deactivating 100 documents and leaving about 100 active, the same node returned results. That pattern points at concurrency or resource pressure rather than at a bad embedding, a missing index, or a permissions problem, because the retrieval test panel and the workflow node share the same knowledge base.
The API container logs are the place to look. The reporter's docker compose output shows a Python traceback in a thread whose target is named _retriever, starting from threading internals. In this thread the traceback is truncated, so the final exception type is not visible in the pasted output. Treat the thread name, not a specific exception string, as your first signal.
- Workflow retrieval node returns an empty result list while the knowledge base retrieval test returns matches.
- Behavior changes with the number of active documents, not with the query text.
- API container logs show a traceback inside a thread named _retriever.
Why it happens
Ranked by how well the thread supports each explanation.
1. Thread pool or resource exhaustion during multi-threaded retrieval. A reply in the thread states that the retrieval node runs retrieval across multiple threads and aggregates their outcomes, so if one thread fails the node can end up with no usable results. Confirm it by checking the API container logs for a traceback in a _retriever thread at the moment the node returns empty, and by watching container memory and CPU while the node runs. This is the best-supported explanation in the thread but was not confirmed by a maintainer.
2. Too many concurrent database or vector store connections. More active documents means more parallel lookups against the vector store and the metadata database. Confirm it by checking your vector store and database connection limits and their logs for refused or timed-out connections during the failing run. The thread raises this as a practical limit rather than a hardcoded cap; it is a hypothesis.
3. A single malformed or oversized document breaking one thread. If one document produces an error during parsing or message handling, the aggregate can come back empty. Confirm it by bisecting: keep the full set active, then deactivate documents in halves until the node returns results, and inspect the last deactivated batch. The thread mentions a message-parsing style error as a possibility but does not show the full exception, so this remains unverified.
4. No hardcoded document limit. The thread explicitly says there is no fixed document cap in the code path; the ceiling you hit is environmental. That matters because raising a config number will not help unless it is the specific pool or connection setting that is saturated.
How to fix it
- Reproduce with a controlled count. Keep the full document set active, run the workflow retrieval node, then deactivate documents in batches until results return. Note the count where behavior flips; this gives you a reproducible test case.
- Capture the full traceback. Run docker compose logs -f api (or your service name) while triggering the node, and copy the complete exception, including the final line that names the exception type. The pasted log in the thread stops mid-traceback, so the exception type is unknown.
- Check resource headroom. Watch container memory and CPU during the failing run. If the API container approaches its memory limit or the host swaps, raise the container limit or reduce concurrent workflow executions before changing retrieval settings.
- Check vector store and database connections. Compare active connections during the failing run against the configured maximum for your vector store and metadata database. If you are near the ceiling, lower retrieval concurrency or raise the connection limit, then retest at the same document count.
- Bisect for a bad document. If the failure tracks one batch rather than a count, deactivate that batch and retest. Re-upload or re-index the offending file, or split it, then reactivate documents one at a time.
- Reduce the working set as a stopgap. The reporter's own workaround was to keep roughly half the documents active. If you need all documents searchable, split the knowledge base into several smaller ones and query them from separate retrieval nodes, then merge results before the LLM node.
- Retest the exact boundary. After any change, rerun at the document count that previously failed and confirm the node returns non-empty results, not just that the logs are clean.
When this is not the cause
If the retrieval test panel also returns nothing, the problem is upstream of the workflow node: indexing, embedding, or the query itself. Check document status and index completion first.
If results are empty only for certain queries at any document count, suspect the retrieval settings, score threshold, or top-k rather than concurrency. A threshold that filters everything out looks identical to a failed retrieval at the node output.
If the node fails with an explicit configuration or credential error, this thread does not apply. The signature here is an empty result set with a thread traceback in the API logs.
One participant reported indexing 260 documents and using the knowledge base in a chatflow without issues. So a high document count alone does not reproduce the failure; treat count as a trigger that exposes resource pressure, not as the root cause.
If your deployment is not Dify 1.11.1 self-hosted on Docker, verify your own version and logs before applying anything here; the thread only covers that configuration.
How to apply this with Admesh
The failure above is about retrieval inside Dify, not about the model provider. But once retrieval returns context, the generation step is where a single provider key, quota, or endpoint issue can turn a working workflow into an empty or failed answer. Routing generation through Admesh gives you one OpenAI-compatible base URL at https://api.admesh.ai/v1 and one Anthropic-compatible endpoint at https://api.admesh.ai/v1/messages, with a single API key and one balance across OpenAI, Anthropic, Google, DeepSeek, Qwen, Moonshot, Zhipu, and MiniMax model families.
In Dify, open the model provider settings and add a custom OpenAI-compatible provider. Set the base URL to https://api.admesh.ai/v1 and paste your Admesh API key. If you prefer an Anthropic-style provider entry, use https://api.admesh.ai/v1/messages instead. Pick model names from the live catalog at https://admesh.ai/models rather than hardcoding anything from an article, since available models and pricing change.
Then isolate variables. Run the retrieval node alone and confirm it returns documents. Only after that, attach the LLM node backed by Admesh and check that the answer uses the retrieved context. If retrieval is empty, the model provider is not your problem; if retrieval works and the answer is empty or errors, check the provider configuration and your balance in the console at https://console.admesh.ai.
Keep one key and one balance for every model family you test, so switching between providers while debugging does not mean juggling credentials. Setup details are in the docs at https://docs.admesh.ai.
FAQ
FAQ
Is there a hardcoded document limit in Dify retrieval?
Why does retrieval work in the knowledge base test but not in the workflow node?
Does deactivating documents actually fix it?
Someone indexed more documents and had no problem. Why?
References
Call these models through one gateway
Admesh provides a unified OpenAI-compatible API: one Base URL and one key for Claude, GPT, DeepSeek and more. New accounts get trial credit that never expires.
