High severity beginner · Fix: 2-5 min

ValueError

haystack.document_stores.base.ValueError

What this error means
This error occurs when a Haystack retriever is used without setting or linking a document store instance.

Stack trace

traceback
ValueError: Document store not set for retriever. Please assign a document store before using the retriever.
QUICK FIX
Pass a valid document store instance to the retriever constructor or assign it before calling retrieval methods.

Why it happens

Haystack retrievers require a document store to fetch documents for querying. If the document store attribute is not set or linked to the retriever instance, the retriever cannot function and raises this error.

Detection

Check if the retriever instance has a non-null document_store attribute before calling retrieval methods to catch this error early.

Causes & fixes

1

Retriever instance was created without passing a document store parameter.

✓ Fix

Instantiate the retriever with a valid document store object, e.g., `retriever = DenseRetriever(document_store=your_document_store)`.

2

Document store was not assigned to the retriever after creation.

✓ Fix

Assign the document store explicitly after retriever creation using `retriever.document_store = your_document_store`.

3

Using a retriever method before initializing or connecting the document store backend.

✓ Fix

Ensure the document store is properly initialized and connected before using the retriever.

Code: broken vs fixed

Broken - triggers the error
python
from haystack.nodes import DenseRetriever

retriever = DenseRetriever()  # Missing document_store parameter
retriever.retrieve(query="example")  # This line triggers the error
Fixed - works correctly
python
import os
from haystack.document_stores import FAISSDocumentStore
from haystack.nodes import DenseRetriever

os.environ["FAISS_INDEX_PATH"] = "/path/to/index"
document_store = FAISSDocumentStore(faiss_index_path=os.environ["FAISS_INDEX_PATH"])
retriever = DenseRetriever(document_store=document_store)  # Fixed: document_store set
results = retriever.retrieve(query="example")
print(results)
Added a properly initialized document store and passed it to the retriever constructor to ensure the retriever has access to documents.

Workaround

Wrap retriever calls in try/except ValueError and check if the document_store attribute is None; if so, initialize or assign a document store before retrying.

Prevention

Always initialize and assign a document store to your retriever before using it, preferably during retriever instantiation to avoid runtime errors.

Python 3.8+ · haystack >=1.0.0 · tested on 1.14.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.