AsyncDenseVectorScriptScoreStrategy#
- class langchain_elasticsearch.vectorstores.AsyncDenseVectorScriptScoreStrategy(distance: DistanceMetric = DistanceMetric.COSINE)[source]#
Methods
__init__
([distance])before_index_creation
(*, client, text_field, ...)Executes before the index is created.
es_mappings_settings
(*, text_field, ...)Create the required index and do necessary preliminary work, like creating inference pipelines or checking if a required model was deployed.
es_query
(*, query, query_vector, text_field, ...)Returns the Elasticsearch query body for the given parameters.
Some retrieval strategies index embedding vectors and allow search by embedding vector, for example the DenseVectorStrategy strategy.
- Parameters:
distance (DistanceMetric)
- __init__(distance: DistanceMetric = DistanceMetric.COSINE) None [source]#
- Parameters:
distance (DistanceMetric)
- Return type:
None
- async before_index_creation(*, client: AsyncElasticsearch, text_field: str, vector_field: str) None #
Executes before the index is created. Used for setting up any required Elasticsearch resources like a pipeline. Defaults to a no-op.
- Parameters:
client (AsyncElasticsearch) – The Elasticsearch client.
text_field (str) – The field containing the text data in the index.
vector_field (str) – The field containing the vector representations in the index.
- Return type:
None
- es_mappings_settings(*, text_field: str, vector_field: str, num_dimensions: int | None) Tuple[Dict[str, Any], Dict[str, Any]] [source]#
Create the required index and do necessary preliminary work, like creating inference pipelines or checking if a required model was deployed.
- Parameters:
client – Elasticsearch client connection.
text_field (str) – The field containing the text data in the index.
vector_field (str) – The field containing the vector representations in the index.
num_dimensions (int | None) – If vectors are indexed, how many dimensions do they have.
- Returns:
Dictionary with field and field type pairs that describe the schema.
- Return type:
Tuple[Dict[str, Any], Dict[str, Any]]
- es_query(*, query: str | None, query_vector: List[float] | None, text_field: str, vector_field: str, k: int, num_candidates: int, filter: List[Dict[str, Any]] = []) Dict[str, Any] [source]#
Returns the Elasticsearch query body for the given parameters. The store will execute the query.
- Parameters:
query (str | None) – The text query. Can be None if query_vector is given.
k (int) – The total number of results to retrieve.
num_candidates (int) – The number of results to fetch initially in knn search.
filter (List[Dict[str, Any]]) – List of filter clauses to apply to the query.
query_vector (List[float] | None) – The query vector. Can be None if a query string is given.
text_field (str)
vector_field (str)
- Returns:
The Elasticsearch query body.
- Return type:
Dict[str, Any]
- needs_inference() bool [source]#
Some retrieval strategies index embedding vectors and allow search by embedding vector, for example the DenseVectorStrategy strategy. Mapping a user input query string to an embedding vector is called inference. Inference can be applied in Elasticsearch (using a model_id) or outside of Elasticsearch (using an EmbeddingService defined on the VectorStore). In the latter case, this method has to return True.
- Return type:
bool