Skip to main content
Classes and functions that implement the ElasticsearchRetriever.

Classes

CLASS ElasticsearchRetriever

Retriever for documents hosted on an Elasticsearch server. Queries an Elasticsearch index using the ELSER sparse-vector model to retrieve the top-k matching documents for a given natural language query. Attributes:
  • hosts: Full url\:port connection string to the Elasticsearch server; stored from the host constructor argument.
Args:
  • corpus_name: Name of the Elasticsearch index to query.
  • host: Full url\:port connection string to the Elasticsearch server.
  • **kwargs: Additional keyword arguments forwarded to the Elasticsearch client constructor.
Methods:

FUNC create_es_body

create_es_body(self, limit, query)
Create a query body for Elasticsearch. Args:
  • limit: Maximum number of documents to retrieve.
  • query: Natural language query string used for ELSER sparse-vector retrieval.

FUNC retrieve

retrieve(self, query: str, top_k: int = 5) -> list[dict]
Run a query against the Elasticsearch index and return top-k results. Args:
  • query: Natural language query string to search for.
  • top_k: Maximum number of documents to return. Defaults to 5.
Returns:
  • list[dict]: List of matching documents, each with keys doc_id, text, and score.