Skip to content

Commit f372ca4

Browse files
authored
bm25 retriever docstrings (#8087)
1 parent 1f58ec2 commit f372ca4

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

haystack/components/retrievers/in_memory/bm25_retriever.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
@component
1313
class InMemoryBM25Retriever:
1414
"""
15-
Retrieves documents using the BM25 algorithm.
15+
Retrieves documents that are most similar to the query using keyword-based algorithm.
16+
17+
Use this retriever with the InMemoryDocumentStore.
18+
19+
### Usage example
1620
17-
Usage example:
1821
```python
1922
from haystack import Document
2023
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
@@ -47,15 +50,19 @@ def __init__(
4750
Create the InMemoryBM25Retriever component.
4851
4952
:param document_store:
50-
An instance of InMemoryDocumentStore.
53+
An instance of InMemoryDocumentStore where the retriever should search for relevant documents.
5154
:param filters:
52-
A dictionary with filters to narrow down the search space.
55+
A dictionary with filters to narrow down the retriever's search space in the document store.
5356
:param top_k:
5457
The maximum number of documents to retrieve.
5558
:param scale_score:
56-
Scales the BM25 score to a unit interval in the range of 0 to 1, where 1 means extremely relevant.
57-
If set to `False`, uses raw similarity scores.
59+
When `True`, scales the score of retrieved documents to a range of 0 to 1, where 1 means extremely relevant.
60+
When `False`, uses raw similarity scores.
5861
:param filter_policy: The filter policy to apply during retrieval.
62+
Filter policy determines how filters are applied when retrieving documents. You can choose:
63+
- `REPLACE` (default): Overrides the initialization filters with the filters specified at runtime.
64+
Use this policy to dynamically change filtering for specific queries.
65+
- `MERGE`: Combines runtime filters with initialization filters to narrow down the search.
5966
:raises ValueError:
6067
If the specified `top_k` is not > 0.
6168
"""
@@ -131,13 +138,12 @@ def run(
131138
:param query:
132139
The query string for the Retriever.
133140
:param filters:
134-
A dictionary with filters to narrow down the search space.
141+
A dictionary with filters to narrow down the search space when retrieving documents.
135142
:param top_k:
136143
The maximum number of documents to return.
137144
:param scale_score:
138-
Scales the BM25 score to a unit interval in the range of 0 to 1, where 1 means extremely relevant.
139-
If set to `False`, uses raw similarity scores. If not specified, the value provided at initialization
140-
is used.
145+
When `True`, scales the score of retrieved documents to a range of 0 to 1, where 1 means extremely relevant.
146+
When `False`, uses raw similarity scores.
141147
:returns:
142148
The retrieved documents.
143149

0 commit comments

Comments
 (0)