Hi,
i have set up a database containing documents which are having dense vectors for the features and for a binary [1,0] mask.
I would like to use the script query to the database with a feature vector at runtime. For this i'm using cosine-similarity, but till now only between the entire feature vectors. But when querying i want to filter the features with a mask vector to get only a subset of entries. Then I want to calculate the cosine-similarity.
My db mapping looks like:
mapping = {
"mappings": {
"properties": {
"imageid": {
"type": "text"
},
"score": {
"type": "float"
},
'feature': {
"type": "dense_vector",
"dims": dim
}
'maskvec': {
"type": "dense_vector",
"dims": dim
}
}
}
}
The script score query till now looks like this:
"script_score": {
"query": {
"match_all": {}
},
"script": {
"lang":"painless",
"source": """
return cosineSimilarity(params.queryVector, feature) + 1.0
""",
"params": {
"queryVector": list(featurevector)
}
}
}
I would like to do sth like this:
mask = params.querymask and maskvec
queryvec = params.queryVector[mask]
featurevec = feature[mask]
return cosineSimilarity(queryvec, featurevec) + 1.0
Is it possible to implement this with elastic search?
Cheers,
Christian