Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

SolrBM25Retriever

Retrieve documents from a SolrDocumentStore using Solr's BM25 similarity for keyword-based search.

Key Features​

  • Performs keyword search using Solr's BM25 ranking algorithm.
  • Supports fuzzy matching with configurable per-term edit distance.
  • Optionally scales BM25 scores into the (0, 1) range.
  • Supports requiring all query terms to match for stricter retrieval.
  • Configurable filter policy to merge or replace filters at query time.

Configuration​

  1. Drag the SolrBM25Retriever component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. Configure the nested SolrDocumentStore with your Solr connection details:
    • Set url to your Solr base URL (defaults to http://localhost:8983/solr).
    • Set core to the name of your Solr core or SolrCloud collection.
    • Set auth credentials as secrets called SOLR_USERNAME and SOLR_PASSWORD. For instructions, see Add Secrets.
  4. Set top_k, fuzziness, and other retrieval parameters on the Advanced tab.

Connections​

SolrBM25Retriever receives a query string at runtime. It outputs a list of Document objects that you can connect to a PromptBuilder or other downstream components.

Source Code​

To check this component's source code, open bm25_retriever.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

SolrBM25Retriever:
type: haystack_integrations.components.retrievers.solr.bm25_retriever.SolrBM25Retriever
init_parameters:
document_store:
type: haystack_integrations.document_stores.solr.document_store.SolrDocumentStore
init_parameters:
url: http://localhost:8983/solr
core: haystack
top_k: 10
fuzziness: 0

Using the Component in a Pipeline​

# haystack-pipeline
components:
document_store:
type: haystack_integrations.document_stores.solr.document_store.SolrDocumentStore
init_parameters:
url: http://localhost:8983/solr
core: haystack
auth:
- type: env_var
env_vars:
- SOLR_USERNAME
strict: false
- type: env_var
env_vars:
- SOLR_PASSWORD
strict: false

retriever:
type: haystack_integrations.components.retrievers.solr.bm25_retriever.SolrBM25Retriever
init_parameters:
document_store: document_store
top_k: 10
fuzziness: 0
scale_score: false
all_terms_must_match: false

connections: []

inputs:
query:
- retriever.query

outputs:
documents: retriever.documents

Parameters​

Inputs​

ParameterTypeDescription
querystrThe query string to search for.
filtersOptional[Dict[str, Any]]Filters to apply at query time.
top_kOptional[int]Maximum number of documents to retrieve. Overrides the init-time value.
fuzzinessOptional[int]Per-term edit distance for fuzzy matching.
scale_scoreOptional[bool]Whether to scale BM25 scores into the (0, 1) range.
all_terms_must_matchOptional[bool]Whether every query term must match.

Outputs​

ParameterTypeDescription
documentsList[Document]A list of matching documents, most relevant first.

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
document_storeSolrDocumentStoreThe Solr document store to search.
filtersOptional[Dict[str, Any]]NoneDefault filters applied to all searches.
fuzzinessint0Per-term edit distance. 0 disables fuzzy matching.
top_kint10Maximum number of documents to return.
scale_scoreboolFalseWhether to scale scores into the (0, 1) range.
all_terms_must_matchboolFalseWhether every query term must match.
filter_policyFilterPolicyFilterPolicy.REPLACEHow to handle filters passed at query time. REPLACE replaces init-time filters; MERGE combines them.
raise_on_failureboolTrueWhether a failing search raises an exception or logs and returns no documents.

Run Method Parameters​

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
querystrThe search query string.
filtersOptional[Dict[str, Any]]NoneRuntime filters to apply.
top_kOptional[int]NoneMaximum number of documents to retrieve. Overrides the init-time value.
fuzzinessOptional[int]NonePer-term edit distance. Overrides the init-time value.
scale_scoreOptional[bool]NoneWhether to scale scores. Overrides the init-time value.
all_terms_must_matchOptional[bool]NoneWhether every term must match. Overrides the init-time value.