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

Elasticsearch Retriever implementation for the Haive framework.

from typing import Any This module provides a configuration class for the Elasticsearch retriever, which performs full-text search and retrieval using Elasticsearch. Elasticsearch is a distributed, RESTful search and analytics engine capable of solving complex search problems and providing real-time search capabilities.

The ElasticsearchRetriever works by: 1. Connecting to an Elasticsearch cluster 2. Executing search queries with various scoring methods 3. Supporting both keyword and vector-based search 4. Returning ranked search results as documents

This retriever is particularly useful when: - Working with large-scale document collections - Need advanced search capabilities (faceting, aggregations, etc.) - Require real-time search and indexing - Building enterprise search applications - Need scalable and distributed search infrastructure

The implementation integrates with LangChain’s ElasticsearchRetriever while providing a consistent Haive configuration interface with secure connection management.

ClassesΒΆ

ElasticsearchRetrieverConfig

Configuration for Elasticsearch retriever in the Haive framework.

Module ContentsΒΆ

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

Bases: haive.core.common.mixins.secure_config.SecureConfigMixin, haive.core.engine.retriever.retriever.BaseRetrieverConfig

Configuration for Elasticsearch retriever in the Haive framework.

This retriever performs full-text search using Elasticsearch with support for various search types including keyword, vector, and hybrid search.

retriever_typeΒΆ

The type of retriever (always ELASTICSEARCH).

Type:

RetrieverType

elasticsearch_urlΒΆ

Elasticsearch cluster URL.

Type:

str

index_nameΒΆ

Name of the Elasticsearch index to search.

Type:

str

usernameΒΆ

Username for Elasticsearch authentication.

Type:

Optional[str]

passwordΒΆ

Password for authentication (auto-resolved).

Type:

Optional[SecretStr]

kΒΆ

Number of documents to retrieve.

Type:

int

search_typeΒΆ

Type of search to perform.

Type:

str

custom_queryΒΆ

Custom Elasticsearch query DSL.

Type:

Optional[Dict]

Examples

>>> from haive.core.engine.retriever import ElasticsearchRetrieverConfig
>>>
>>> # Create the Elasticsearch retriever config
>>> config = ElasticsearchRetrieverConfig(
...     name="elasticsearch_retriever",
...     elasticsearch_url="https://localhost:9200",
...     index_name="documents",
...     username="elastic",
...     k=10,
...     search_type="match"
... )
>>>
>>> # Instantiate and use the retriever
>>> retriever = config.instantiate()
>>> docs = retriever.get_relevant_documents("machine learning algorithms")
>>>
>>> # Example with custom query
>>> custom_config = ElasticsearchRetrieverConfig(
...     name="custom_elasticsearch_retriever",
...     elasticsearch_url="https://localhost:9200",
...     index_name="documents",
...     custom_query={
...         "bool": {
...             "must": [{"match": {"content": "{query}"}}],
...             "filter": [{"range": {"date": {"gte": "2023-01-01"}}}]
...         }
...     }
... )
get_input_fields()[source]ΒΆ

Return input field definitions for Elasticsearch retriever.

Return type:

dict[str, tuple[type, Any]]

get_output_fields()[source]ΒΆ

Return output field definitions for Elasticsearch retriever.

Return type:

dict[str, tuple[type, Any]]

instantiate()[source]ΒΆ

Create an Elasticsearch retriever from this configuration.

Returns:

Instantiated retriever ready for search.

Return type:

ElasticsearchRetriever

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

  • ValueError – If connection configuration is invalid.