"reimburse my cash" shares no words with "we refund your money", yet means the same. Combine keyword and meaning scores.
AI · intermediate · 6 min · 15 steps · free
SAME_MEANING = {'cash': 'money', 'reimburse': 'refund', 'return': 'refund'}
def keyword_score(query, doc):
return len(set(query.split()) & set(doc.split()))
def meaning_score(query, doc):
q = {SAME_MEANING.get(w, w) for w in query.split()}
d = {SAME_MEANING.get(w, w) for w in doc.split()}
return len(q & d)
doc = 'we refund your money'
query = 'reimburse my cash'
keyword = keyword_score(query, doc)
meaning = meaning_score(query, doc)
hybrid = 0.3 * keyword + 0.7 * meaning
print(keyword, meaning, hybrid)SAME_MEANING is created and points to a new dict: {cash: 'money', reimburse: 'refund', return: 'refund'}.keyword_score(). Its body does not run yet: it runs each time the function is called.meaning_score(). Its body does not run yet: it runs each time the function is called.doc is created with the value 'we refund your money'.query is created with the value 'reimburse my cash'.keyword_score(), with query = 'reimburse my cash' and doc = 'we refund your money'. It gets its own names.len(set(query.split()) & set(doc.split())).meaning_score(), with query = 'reimburse my cash' and doc = 'we refund your money'. It gets its own names.d is created and points to a new set: ['money', 'refund', 'we', 'your'].len(q & d).0 2 1.4.Answer: Keyword search. Exact codes have no "meaning" to embed.
Answer: Meaning search
← A Tiny Vector Store · Building the Prompt Within a Budget →