Skip to content

Commit c670f0f

Browse files
agnieszka-mdfokina
andauthored
Docs: update SentenceWindowRetriever docstrings (#8138)
* update docstrings * Update haystack/components/retrievers/sentence_window_retriever.py Co-authored-by: Daria Fokina <[email protected]> * Update haystack/components/retrievers/sentence_window_retriever.py Co-authored-by: Daria Fokina <[email protected]> --------- Co-authored-by: Daria Fokina <[email protected]>
1 parent ffbaed8 commit c670f0f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

haystack/components/retrievers/sentence_window_retriever.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@
1212
@component
1313
class SentenceWindowRetriever:
1414
"""
15-
A component that retrieves surrounding documents of a given document from the document store.
15+
Retrieves documents adjacent to a given document in the Document Store.
1616
17-
It relies on the `source_id` and on the `doc.meta['split_id']` to get the surrounding documents from the document.
18-
This component is designed to work together with one of the existing retrievers, e.g. BM25Retriever,
19-
EmbeddingRetriever. One of these retrievers can be used to retrieve documents based on a query and then use this
20-
component to get the surrounding documents of the retrieved documents.
17+
During indexing, documents are broken into smaller chunks, or sentences. When you submit a query,
18+
the Retriever fetches the most relevant sentence. To provide full context,
19+
SentenceWindowRetriever fetches a number of neighboring sentences before and after each
20+
relevant one. You can set this number with the `window_size` parameter.
21+
It uses `source_id` and `doc.meta['split_id']` to locate the surrounding documents.
2122
23+
This component works with existing Retrievers, like BM25Retriever or
24+
EmbeddingRetriever. First, use a Retriever to find documents based on a query and then use
25+
SentenceWindowRetriever to get the surrounding documents for context.
26+
27+
28+
### Usage example
2229
23-
Usage example:
2430
```python
2531
from haystack import Document, Pipeline
2632
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
@@ -56,8 +62,9 @@ def __init__(self, document_store: DocumentStore, window_size: int = 3):
5662
"""
5763
Creates a new SentenceWindowRetriever component.
5864
59-
:param document_store: The document store to use for retrieving the surrounding documents.
60-
:param window_size: The number of surrounding documents to retrieve.
65+
:param document_store: The Document Store to retrieve the surrounding documents from.
66+
:param window_size: The number of documents to retrieve before and after the relevant one.
67+
For example, `window_size: 2` fetches 2 preceding and 2 following documents.
6168
"""
6269
if window_size < 1:
6370
raise ValueError("The window_size parameter must be greater than 0.")

0 commit comments

Comments
 (0)