Why Sonamu Needs Vector Search
When building web apps with Sonamu, you’ll implement features like these:- Knowledge base: “Find similar documents”
- E-commerce: “Products similar to this one”
- Content: “Related articles recommendation”
- Customer support: “Find similar questions”
LIKE '%keyword%') has limitations:
- Searching “TypeScript framework” won’t find “Node.js API library”
- Vulnerable to typos (“typescript” vs “tyepscript”)
- Doesn’t handle synonyms (“framework” vs “library”)
Why pgvector?
To implement vector search, you need a database that can store and search vectors.Options
| Method | Pros | Cons | Sonamu Recommendation |
|---|---|---|---|
| pgvector | Use existing PostgreSQL, no additional infrastructure, JOIN with existing data | Lower performance than dedicated vector DBs | Highly recommended |
| Pinecone | Optimized for vector search, managed service | Additional cost, separate sync needed | Low |
| Elasticsearch | Powerful search features | Heavy, complex setup | Medium |
| Weaviate/Milvus | Dedicated vector DB | Separate infrastructure, learning curve | Low |
Why pgvector is Recommended for Sonamu Projects
1. You’re already using PostgreSQL- Pinecone: Separate API, cost, sync
- pgvector: Just install extension, no additional cost
What is pgvector?
pgvector is an extension that allows PostgreSQL to store and search vector (embedding) data. Key features:vector(N)data type (N-dimensional vector)- Similarity operators (
<=>,<->,<#>) - Indexes (IVFFlat, HNSW)
Required Package Installation
pgvector: PostgreSQL pgvector type support (use with Knex)voyageai: Voyage AI embeddings (recommended for Korean)@ai-sdk/openai: OpenAI embeddings (optional)
PostgreSQL Extension Installation
Installation by Environment
- Ubuntu/Debian
- macOS (Homebrew)
- Docker
- Cloud (Supabase/Neon)
Enable Extension
Connect to PostgreSQL and enable the extension:Applying to Sonamu Project
1. Environment Variables
2. Verify Sonamu Config
3. Create Table with Knex Migration
Create a vector table using Sonamu’s Migration:4. Creating a Vector Table from Scratch
If creating a new table:Understanding Vector Dimensions
Different embedding models have different vector dimensions:Index - Create Later
Important: Create the index after sufficient data has accumulated.Why Later?
HNSW Index (Recommended)
After 100+ data entries:m = 16: Number of connections (default, usually OK)ef_construction = 64: Search size during construction