mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 06:39:52 +00:00
community[patch]: ElasticsearchStore enable max inner product (#16393)
Enable max inner product for approximate retrieval strategy. For exact strategy we lack the necessary `maxInnerProduct` function in the Painless scripting language, this is why we do not add it there. Similarity docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/dense-vector.html#dense-vector-params --------- Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Joe McElroy <joseph.mcelroy@elastic.co>
This commit is contained in:
parent
fc196cab12
commit
8569b8f680
@ -214,6 +214,8 @@ class ApproxRetrievalStrategy(BaseRetrievalStrategy):
|
|||||||
similarityAlgo = "l2_norm"
|
similarityAlgo = "l2_norm"
|
||||||
elif similarity is DistanceStrategy.DOT_PRODUCT:
|
elif similarity is DistanceStrategy.DOT_PRODUCT:
|
||||||
similarityAlgo = "dot_product"
|
similarityAlgo = "dot_product"
|
||||||
|
elif similarity is DistanceStrategy.MAX_INNER_PRODUCT:
|
||||||
|
similarityAlgo = "max_inner_product"
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Similarity {similarity} not supported.")
|
raise ValueError(f"Similarity {similarity} not supported.")
|
||||||
|
|
||||||
@ -412,7 +414,7 @@ class ElasticsearchStore(VectorStore):
|
|||||||
distance_strategy: Optional. Distance strategy to use when
|
distance_strategy: Optional. Distance strategy to use when
|
||||||
searching the index.
|
searching the index.
|
||||||
Defaults to COSINE. Can be one of COSINE,
|
Defaults to COSINE. Can be one of COSINE,
|
||||||
EUCLIDEAN_DISTANCE, or DOT_PRODUCT.
|
EUCLIDEAN_DISTANCE, MAX_INNER_PRODUCT or DOT_PRODUCT.
|
||||||
|
|
||||||
If you want to use a cloud hosted Elasticsearch instance, you can pass in the
|
If you want to use a cloud hosted Elasticsearch instance, you can pass in the
|
||||||
cloud_id argument instead of the es_url argument.
|
cloud_id argument instead of the es_url argument.
|
||||||
@ -508,6 +510,7 @@ class ElasticsearchStore(VectorStore):
|
|||||||
DistanceStrategy.COSINE,
|
DistanceStrategy.COSINE,
|
||||||
DistanceStrategy.DOT_PRODUCT,
|
DistanceStrategy.DOT_PRODUCT,
|
||||||
DistanceStrategy.EUCLIDEAN_DISTANCE,
|
DistanceStrategy.EUCLIDEAN_DISTANCE,
|
||||||
|
DistanceStrategy.MAX_INNER_PRODUCT,
|
||||||
]
|
]
|
||||||
] = None,
|
] = None,
|
||||||
strategy: BaseRetrievalStrategy = ApproxRetrievalStrategy(),
|
strategy: BaseRetrievalStrategy = ApproxRetrievalStrategy(),
|
||||||
@ -1128,7 +1131,8 @@ class ElasticsearchStore(VectorStore):
|
|||||||
distance_strategy: Optional. Name of the distance
|
distance_strategy: Optional. Name of the distance
|
||||||
strategy to use. Defaults to "COSINE".
|
strategy to use. Defaults to "COSINE".
|
||||||
can be one of "COSINE",
|
can be one of "COSINE",
|
||||||
"EUCLIDEAN_DISTANCE", "DOT_PRODUCT".
|
"EUCLIDEAN_DISTANCE", "DOT_PRODUCT",
|
||||||
|
"MAX_INNER_PRODUCT".
|
||||||
bulk_kwargs: Optional. Additional arguments to pass to
|
bulk_kwargs: Optional. Additional arguments to pass to
|
||||||
Elasticsearch bulk.
|
Elasticsearch bulk.
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user