mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +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(
|
||||
space_type: str, query_vector: List[float], vector_field: str = "vector_field"
|
||||
space_type: str, vector_field: str = "vector_field"
|
||||
) -> str:
|
||||
"""For Painless Scripting, it returns the script source based on space type."""
|
||||
source_value = (
|
||||
"(1.0 + "
|
||||
+ space_type
|
||||
+ "("
|
||||
+ str(query_vector)
|
||||
+ ", doc['"
|
||||
+ vector_field
|
||||
+ "']))"
|
||||
"(1.0 + " + space_type + "(params.query_value, doc['" + vector_field + "']))"
|
||||
)
|
||||
if space_type == "cosineSimilarity":
|
||||
return source_value
|
||||
@ -295,9 +289,7 @@ def _default_painless_scripting_query(
|
||||
if not pre_filter:
|
||||
pre_filter = MATCH_ALL_QUERY
|
||||
|
||||
source = __get_painless_scripting_source(
|
||||
space_type, query_vector, vector_field=vector_field
|
||||
)
|
||||
source = __get_painless_scripting_source(space_type, vector_field=vector_field)
|
||||
return {
|
||||
"size": k,
|
||||
"query": {
|
||||
|
Loading…
Reference in New Issue
Block a user