Created
February 28, 2023 13:51
-
-
Save nathancday/aa3815982b2ec6f843df804e5f1e0483 to your computer and use it in GitHub Desktop.
Hybrid vigor: a winning way to use hybrid search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT trec | |
{ | |
"mappings": { | |
"properties": { | |
"title" : {"type": "text"}, | |
"episode": {"type": "text"}, | |
"text": {"type": "text"}, | |
"embed": {"type": "dense_vector", "dims": 3} | |
} | |
} | |
} | |
POST trec/_doc | |
{ | |
"title": "Great Steaks", | |
"episode": "T-bones FTW", | |
"text": "When it comes down to it, in my option, the best cut of steak in the cow is the T-Bone! You can't beat the juicy tenderness", | |
"embed": [3.0, 2.1, 0.2] | |
} | |
POST trec/_doc | |
{ | |
"title": "Beef Eater Anonymos", | |
"episode": "Why red meat is actually good for you", | |
"text": "Sure a steak tasts great, but is it also great for you? I think it is and my guess Teddy Steaks here on the show today say YES!", | |
"embed": [2.0, 2.9, 0.1] | |
} | |
GET trec/_search // first we gotta get the maxScore | |
{ | |
"size": 1, | |
"query": { | |
"multi_match": { | |
"fields": [ | |
"title", | |
"episode", | |
"text^3" | |
], | |
"query": "tasty steaks" | |
} | |
} | |
} | |
GET trec/_search | |
{ | |
"query": { | |
"script_score": { | |
"query": { | |
"multi_match": { | |
"fields": [ | |
"title", | |
"episode", | |
"text^3" | |
], | |
"query": "tasty steaks" | |
} | |
}, | |
"script": { | |
"params": { | |
"maxScore": 2.064089, | |
"queryVector": [3.1, 2.5, 0.1] | |
}, | |
"source": """ | |
double myScore = _score / params.maxScore; | |
double sbertScore = cosineSimilarity(params.queryVector, 'embed'); | |
return myScore + sbertScore; | |
""" | |
} | |
} | |
} | |
} | |
DELETE trec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment