Embeddings & Vector Search in Rails — Semantic Search with pgvector
Streaming AI responses looks cool. But here's the problem: the AI doesn't know anything about your business. Ask it about your users, orders, or documents and it hallucinates. Embeddings fix this. ...

Source: DEV Community
Streaming AI responses looks cool. But here's the problem: the AI doesn't know anything about your business. Ask it about your users, orders, or documents and it hallucinates. Embeddings fix this. They turn text into vectors — mathematical fingerprints that capture meaning. Similar ideas cluster together in vector space. Search stops being keyword matching and starts being concept matching. This post adds semantic search to your Rails app using pgvector and the neighbor gem. By the end, you'll search your content by meaning, not keywords. What We're Building A document search where "cloud computing" finds articles about AWS, Azure, and deployment — even if they never use the words "cloud" or "computing". Setup First, get pgvector running. If you're on a VPS (which you should be): # Ubuntu/Debian sudo apt install postgresql-16-pgvector # Or use the Docker image # postgres:16 with pgvector extension Enable the extension in your database: CREATE EXTENSION IF NOT EXISTS vector; Add the gem