Skip to content

Instantly share code, notes, and snippets.

@kewang
Last active April 30, 2024 13:42
Show Gist options
  • Save kewang/c920f0c73c1c1b1ca2785dd72fa68535 to your computer and use it in GitHub Desktop.
Save kewang/c920f0c73c1c1b1ca2785dd72fa68535 to your computer and use it in GitHub Desktop.
const searchEsResult = await es.search({
index: 'helloworld',
body: {
from: 0,
size: 10,
min_score: 1.5, // 0~2
query: {
function_score: {
query: {
bool: {
must: [
{
exists: {
field: `vector`
}
},
{
term: {
user_input: false
}
}
]
}
},
functions: [
{
script_score: {
script: {
source: `cosineSimilarity(params.query_vector, doc["vector"])`,
params: {
query_vector: vector
}
}
}
}
],
boost_mode: 'replace'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment