error: psycopg2.errors.UndefinedFunction: function similarity(text, text) does not exist
While tryig to create a similiarity search with postgres, bump into this error with this simple query
cur.execute("""
SELECT id, name, category, subcategory,
(1 - (embedding <=> %s::vector)) AS semantic_score,
similarity(name, CAST(%s AS text)) AS keyword_score,
(0.7 * (1 - (embedding <=> %s::vector)) +
0.3 * similarity(name, CAST(%s AS text))) AS final_score
FROM items
WHERE category = %s
ORDER BY final_score DESC
LIMIT 5;
""", (query_emb, query, query_emb, query, category))
To resolve this you need to activate pg_trgm extension. For some reason, I have to do it everytime and need to ensure that the extension is activated before my query can be successful.
Comments