mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-15 23:57:21 +00:00
This is a minor improvement that replaces the full query_vector with the reference string `params.query_value` used in the painless scripting docs. I have tested it manually and it works on an example. This makes the query about half the size and much easier to read. https://opensearch.org/docs/latest/search-plugins/knn/painless-functions/#get-started-with-k-nns-painless-scripting-functions @babbldev #8089 --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
parent
0ead8ea708
commit
0f68054401
@ -265,17 +265,11 @@ def _default_script_query(
|
|||||||
|
|
||||||
|
|
||||||
def __get_painless_scripting_source(
|
def __get_painless_scripting_source(
|
||||||
space_type: str, query_vector: List[float], vector_field: str = "vector_field"
|
space_type: str, vector_field: str = "vector_field"
|
||||||
) -> str:
|
) -> str:
|
||||||
"""For Painless Scripting, it returns the script source based on space type."""
|
"""For Painless Scripting, it returns the script source based on space type."""
|
||||||
source_value = (
|
source_value = (
|
||||||
"(1.0 + "
|
"(1.0 + " + space_type + "(params.query_value, doc['" + vector_field + "']))"
|
||||||
+ space_type
|
|
||||||
+ "("
|
|
||||||
+ str(query_vector)
|
|
||||||
+ ", doc['"
|
|
||||||
+ vector_field
|
|
||||||
+ "']))"
|
|
||||||
)
|
)
|
||||||
if space_type == "cosineSimilarity":
|
if space_type == "cosineSimilarity":
|
||||||
return source_value
|
return source_value
|
||||||
@ -295,9 +289,7 @@ def _default_painless_scripting_query(
|
|||||||
if not pre_filter:
|
if not pre_filter:
|
||||||
pre_filter = MATCH_ALL_QUERY
|
pre_filter = MATCH_ALL_QUERY
|
||||||
|
|
||||||
source = __get_painless_scripting_source(
|
source = __get_painless_scripting_source(space_type, vector_field=vector_field)
|
||||||
space_type, query_vector, vector_field=vector_field
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"size": k,
|
"size": k,
|
||||||
"query": {
|
"query": {
|
||||||
|
Loading…
Reference in New Issue
Block a user