How to Add Semantic Search to Your App with pgvector
Blog post from Nhost
Semantic search retrieves content based on meaning rather than exact keyword overlap by converting documents and user queries into numerical embeddings and ranking nearby vectors, allowing queries such as “how do I cancel” to match subscription-ending content. The guide explains how pgvector extends PostgreSQL with vector storage and similarity operators, using a vector dimension that matches the selected embedding model and typically cosine distance for ranking results. It compares HNSW, the recommended default for strong recall and immediate querying at higher memory cost, with IVFFlat, which uses less memory but requires representative existing data before index creation. Embeddings must be generated with the same model for both stored content and queries, updated when source rows change, and backfilled in batches for existing datasets. Searches use an ordered cosine-distance query with a result limit, can combine normal SQL filters such as tenant or publication status, and should apply empirically tested distance thresholds to avoid returning irrelevant results. Nhost can automate embedding generation, synchronization, and permission-aware GraphQL search while retaining data in PostgreSQL through pgvector, although it currently supports OpenAI embeddings and updates results on a near-real-time rather than immediate schedule.
| Trend | Post Mentions | Total Month Mentions | Posts | Companies | MoM |
|---|---|---|---|---|---|
| Vector Search | 37 | 1,725 | 270 | 100 | -18% |
| Real-time | 2 | 2,940 | 753 | 191 | -50% |
| Serverless | 1 | 551 | 144 | 73 | -28% |
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.