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
IVFFlat Index (Faster Build)
If HNSW is too slow:Practical Scenario
Scenario: Building a Knowledge Base
Youβre building an internal knowledge base with Sonamu. Step 1: Table DesignCautions
Next Steps
pgvector installation is complete. Now itβs time to generate embeddings and implement search.Generating Embeddings
Creating embeddings with Voyage AI in Sonamu
Vector Search
Implementing search API in Sonamu Model