A user types "How do I cancel my plan?" Your help page says "To unsubscribe, open Billing and click End subscription."
Same meaning, zero shared words , so keyword search finds nothing. In this post we fix that with embeddings, the idea behind semantic search and RAG. It takes about 30 lines of plain Python (no libraries) and a free model running locally with Ollama.
Video version:
Keyword search compares spelling
def keyword_search ( query ) : words = set ( query . lower ( ) . replace ( "?" , "" ) . split ( ) ) return max ( DOCS , key = lambda d : len ( words & set ( d . lower ( ) . replace ( "." , "" ) . replace ( "," , "" ) . split ( ) ) ) )
Enter fullscreen mode
Exit fullscreen mode
For each of my four test questions below, the correct help article shared no words at all with the query. Keyword search has nothing to go on.
What's an embedding?
An embedding model turns text into a list of numbers (a vector). nomic-embed-text returns 768 of them.…