SparseRetrievalStrategy#
- class langchain_community.vectorstores.elasticsearch.SparseRetrievalStrategy(model_id: str | None = None)[source]#
Deprecated since version 0.0.27: Use
Use class in langchain-elasticsearch package
instead.Sparse retrieval strategy using the text_expansion processor.
Methods
__init__
([model_id])before_index_setup
(client,ย text_field,ย ...)Executes before the index is created.
index
(dims_length,ย vector_query_field,ย ...)Executes when the index is created.
query
(query_vector,ย query,ย k,ย fetch_k,ย ...)Executes when a search is performed on the store.
Returns whether or not the strategy requires inference to be performed on the text before it is added to the index.
- Parameters:
model_id (str | None) โ
- before_index_setup(client: Elasticsearch, text_field: str, vector_query_field: str) None [source]#
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: int | None, vector_query_field: str, similarity: DistanceStrategy | None) Dict [source]#
Executes when the index is created.
- Parameters:
dims_length (int | None) โ Numeric length of the embedding vectors, or None if not using vector-based query.
vector_query_field (str) โ The field containing the vector representations in the index.
similarity (DistanceStrategy | None) โ The similarity strategy to use, or None if not using one.
- Returns:
The Elasticsearch settings and mappings for the strategy.
- Return type:
Dict
- query(query_vector: List[float] | None, query: str | None, k: int, fetch_k: int, vector_query_field: str, text_field: str, filter: List[dict], similarity: DistanceStrategy | None) Dict [source]#
Executes when a search is performed on the store.
- Parameters:
query_vector (List[float] | None) โ The query vector, or None if not using vector-based query.
query (str | None) โ 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 (DistanceStrategy | None) โ The similarity strategy to use, or None if not using one.
- Returns:
The Elasticsearch query body.
- Return type:
Dict