Find Similar Sentences Using Embeddings and a Vector Database
I'm building Second Memory—a personal memory app where users save entries and ask natural-language questions later. They often remember meaning, not the exact words they wrote. For example, they might have saved:
- "I forgot my umbrella and got soaked in the rain."
- "I lifted weights at the gym after work."
- "I caught up with John over coffee yesterday."
- "I stayed up late debugging my application."
Later they ask "Who did I meet recently?" The best match is I caught up with John over coffee yesterday.—but keyword search can miss it when "meet" and "caught up" differ. Below: semantic search with a local embedding model (no API key), cosine distance, ranking memories in Python, then storing and querying vectors with pgvector.
