IRISBm25Retriever¶
IRISBm25Retriever ¶
IRISBm25Retriever(*, document_store: IRISDocumentStore, filters: dict[str, Any] | None = None, top_k: int = 10, filter_policy: FilterPolicy | str = FilterPolicy.REPLACE)
Retrieve documents from :class:IRISDocumentStore using Okapi BM25.
The BM25 index is rebuilt in-memory over the (optionally filtered) document set on every :meth:run call. For large collections, apply filters to narrow the candidate set before ranking.
Usage in a pipeline
.. code-block:: python
from haystack import Pipeline
from intersystems_iris_haystack.document_stores import IRISDocumentStore
from intersystems_iris_haystack.components.retrievers.iris import IRISBm25Retriever
store = IRISDocumentStore()
pipeline = Pipeline()
pipeline.add_component("retriever", IRISBm25Retriever(document_store=store))
result = pipeline.run({"retriever": {"query": "multimodel database", "top_k": 5}})
print(result["retriever"]["documents"])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_store | IRISDocumentStore | An :class: | required |
filters | dict[str, Any] | None | Filters applied before BM25 ranking at initialization time. | None |
top_k | int | Maximum number of documents to retrieve. | 10 |
filter_policy | FilterPolicy | str | Determines how init-time and runtime filters interact ( | REPLACE |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Source code in src/intersystems_iris_haystack/components/retrievers/bm25_retriever.py
run ¶
run(query: str, filters: dict[str, Any] | None = None, top_k: int | None = None) -> dict[str, list[Document]]
Retrieve the most relevant documents for a keyword query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query | str | Natural language search text. | required |
filters | dict[str, Any] | None | Runtime filters merged with init-time filters per | None |
top_k | int | None | Override the default | None |
Returns:
| Type | Description |
|---|---|
dict |
|
Source code in src/intersystems_iris_haystack/components/retrievers/bm25_retriever.py
to_dict ¶
Serializes the component to a dictionary.
Source code in src/intersystems_iris_haystack/components/retrievers/bm25_retriever.py
from_dict classmethod ¶
Deserializes the component from a dictionary.