haive.core.engine.retriever.providers.EnsembleRetrieverConfigΒΆ

Ensemble Retriever implementation for the Haive framework.

This module provides a configuration class for the Ensemble retriever, which combines multiple retrieval strategies using weighted combination to improve overall retrieval performance and coverage.

The EnsembleRetriever works by: 1. Running multiple retrievers in parallel on the same query 2. Combining results using configurable weights for each retriever 3. Re-ranking and deduplicating the combined results 4. Returning the most relevant documents from the ensemble

This retriever is particularly useful when: - You want to combine different retrieval strategies (sparse + dense) - Need to balance precision and recall across different approaches - Building robust systems that work across diverse query types - Implementing hybrid search with customizable weights

The implementation integrates with LangChain’s EnsembleRetriever while providing a consistent Haive configuration interface.

ClassesΒΆ

EnsembleRetrieverConfig

Configuration for Ensemble retriever in the Haive framework.

Module ContentsΒΆ

class haive.core.engine.retriever.providers.EnsembleRetrieverConfig.EnsembleRetrieverConfig[source]ΒΆ

Bases: haive.core.engine.retriever.retriever.BaseRetrieverConfig

Configuration for Ensemble retriever in the Haive framework.

This retriever combines multiple retrieval strategies using weighted combination to improve overall performance and coverage across different query types.

retriever_typeΒΆ

The type of retriever (always ENSEMBLE).

Type:

RetrieverType

retrieversΒΆ

List of retriever configurations to ensemble.

Type:

List[BaseRetrieverConfig]

weightsΒΆ

Weights for each retriever (must sum to 1.0).

Type:

List[float]

kΒΆ

Number of documents to return from the ensemble.

Type:

int

normalize_scoresΒΆ

Whether to normalize scores before combining.

Type:

bool

Examples

>>> from haive.core.engine.retriever import EnsembleRetrieverConfig
>>> from haive.core.engine.retriever.providers.BM25RetrieverConfig import BM25RetrieverConfig
>>> from haive.core.engine.retriever.providers.VectorStoreRetrieverConfig import VectorStoreRetrieverConfig
>>>
>>> # Create individual retrievers
>>> bm25_config = BM25RetrieverConfig(name="bm25", documents=docs, k=10)
>>> vector_config = VectorStoreRetrieverConfig(name="vector", vectorstore_config=vs_config, k=10)
>>>
>>> # Create ensemble retriever
>>> config = EnsembleRetrieverConfig(
...     name="hybrid_ensemble",
...     retrievers=[bm25_config, vector_config],
...     weights=[0.3, 0.7],  # 30% BM25, 70% vector
...     k=5
... )
>>>
>>> # Instantiate and use the retriever
>>> retriever = config.instantiate()
>>> docs = retriever.get_relevant_documents("machine learning algorithms")
get_input_fields()[source]ΒΆ

Return input field definitions for Ensemble retriever.

Return type:

dict[str, tuple[type, Any]]

get_output_fields()[source]ΒΆ

Return output field definitions for Ensemble retriever.

Return type:

dict[str, tuple[type, Any]]

instantiate()[source]ΒΆ

Create an Ensemble retriever from this configuration.

Returns:

Instantiated retriever ready for ensemble retrieval.

Return type:

EnsembleRetriever

Raises:
  • ImportError – If required packages are not available.

  • ValueError – If configuration is invalid.

classmethod validate_weight_values(v)[source]ΒΆ

Validate that each weight is between 0 and 1.

classmethod validate_weights(v)[source]ΒΆ

Validate that weights sum to 1.0.