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
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