@@ -29,7 +29,8 @@ class FilterRetriever:
2929 doc_store.write_documents(docs)
3030 retriever = FilterRetriever(doc_store, filters={"field": "lang", "operator": "==", "value": "en"})
3131
32- # if passed in the run method, filters override those provided at initialization
32+ # If passed in the run method, filters override those provided at initialization.
33+ # Passing an empty dictionary explicitly clears the initialization filters.
3334 result = retriever.run(filters={"field": "lang", "operator": "==", "value": "de"})
3435
3536 print(result["documents"])
@@ -44,6 +45,7 @@ def __init__(self, document_store: DocumentStore, filters: dict[str, Any] | None
4445 An instance of a Document Store to use with the Retriever.
4546 :param filters:
4647 A dictionary with filters to narrow down the search space.
48+ Passing an empty dictionary explicitly clears filters provided at initialization.
4749 """
4850 self .document_store = document_store
4951 self .filters = filters
@@ -82,11 +84,12 @@ def run(self, filters: dict[str, Any] | None = None) -> dict[str, Any]:
8284
8385 :param filters:
8486 A dictionary with filters to narrow down the search space.
87+ Passing an empty dictionary explicitly clears filters provided at initialization.
8588 If not specified, the FilterRetriever uses the values provided at initialization.
8689 :returns:
8790 A list of retrieved documents.
8891 """
89- return {"documents" : self .document_store .filter_documents (filters = filters or self . filters )}
92+ return {"documents" : self .document_store .filter_documents (filters = self . filters if filters is None else filters )}
9093
9194 @component .output_types (documents = list [Document ])
9295 async def run_async (self , filters : dict [str , Any ] | None = None ) -> dict [str , Any ]:
@@ -100,7 +103,9 @@ async def run_async(self, filters: dict[str, Any] | None = None) -> dict[str, An
100103 A list of retrieved documents.
101104 """
102105 # 'ignore' since filter_documents_async is not defined in the Protocol but exists in the implementations
103- out_documents = await self .document_store .filter_documents_async (filters = filters or self .filters ) # type: ignore[attr-defined]
106+ out_documents = await self .document_store .filter_documents_async ( # type: ignore[attr-defined]
107+ filters = self .filters if filters is None else filters
108+ )
104109 return {"documents" : out_documents }
105110
106111 def close (self ) -> None :
0 commit comments