langchain_community.vectorstores.elasticsearch.ApproxRetrievalStrategy¶

class langchain_community.vectorstores.elasticsearch.ApproxRetrievalStrategy(query_model_id: Optional[str] = None, hybrid: Optional[bool] = False, rrf: Optional[Union[dict, bool]] = True)[source]¶

[Deprecated] Approximate retrieval strategy using the HNSW algorithm.

Notes

Deprecated since version langchain-community==0.0.27: Use Use class in langchain-elasticsearch package instead.

Methods

__init__([query_model_id, hybrid, rrf])

before_index_setup(client, text_field, ...)

Executes before the index is created.

index(dims_length, vector_query_field, ...)

Create the mapping for the Elasticsearch index.

query(query_vector, query, k, fetch_k, ...)

Executes when a search is performed on the store.

require_inference()

Returns whether or not the strategy requires inference to be performed on the text before it is added to the index.

Parameters
  • query_model_id (Optional[str]) –

  • hybrid (Optional[bool]) –

  • rrf (Optional[Union[dict, bool]]) –

__init__(query_model_id: Optional[str] = None, hybrid: Optional[bool] = False, rrf: Optional[Union[dict, bool]] = True)[source]¶
Parameters
  • query_model_id (Optional[str]) –

  • hybrid (Optional[bool]) –

  • rrf (Optional[Union[dict, bool]]) –

before_index_setup(client: Elasticsearch, text_field: str, vector_query_field: str) None¶

Executes before the index is created. Used for setting up any required Elasticsearch resources like a pipeline.

Parameters
  • client (Elasticsearch) – The Elasticsearch client.

  • text_field (str) – The field containing the text data in the index.

  • vector_query_field (str) – The field containing the vector representations in the index.

Return type

None

index(dims_length: Optional[int], vector_query_field: str, similarity: Optional[DistanceStrategy]) Dict[source]¶

Create the mapping for the Elasticsearch index.

Parameters
  • dims_length (Optional[int]) –

  • vector_query_field (str) –

  • similarity (Optional[DistanceStrategy]) –

Return type

Dict

query(query_vector: Optional[List[float]], query: Optional[str], k: int, fetch_k: int, vector_query_field: str, text_field: str, filter: List[dict], similarity: Optional[DistanceStrategy]) Dict[source]¶

Executes when a search is performed on the store.

Parameters
  • query_vector (Optional[List[float]]) – The query vector, or None if not using vector-based query.

  • query (Optional[str]) – The text query, or None if not using text-based query.

  • k (int) – The total number of results to retrieve.

  • fetch_k (int) – The number of results to fetch initially.

  • vector_query_field (str) – The field containing the vector representations in the index.

  • text_field (str) – The field containing the text data in the index.

  • filter (List[dict]) – List of filter clauses to apply to the query.

  • similarity (Optional[DistanceStrategy]) – The similarity strategy to use, or None if not using one.

Returns

The Elasticsearch query body.

Return type

Dict

require_inference() bool¶

Returns whether or not the strategy requires inference to be performed on the text before it is added to the index.

Returns

Whether or not the strategy requires inference to be performed on the text before it is added to the index.

Return type

bool