Embeddings Pattern
Generate and manage vector embeddings for semantic search, similarity matching, and retrieval-augmented generation using OpenAI and pgvector.
What's Included#
- OpenAI embedding generation for single texts and batches
- PostgreSQL vector storage with pgvector extension and Prisma integration
- Semantic similarity search using cosine distance queries
- Text chunking strategies with configurable size and overlap
- Database schema with IVFFlat indexing for fast similarity lookups
- Document ingestion pipeline with chunked embedding storage
Usage#
Via CLI#
Loading code block...
Via AI Assistant#
Ask your AI assistant:
- "Use the embeddings pattern from Bootspring"
- "Apply the Bootspring embeddings pattern to my project"
Key Considerations#
- Choose the right model: text-embedding-3-small for cost efficiency, text-embedding-3-large for quality
- Keep text chunks between 500-1500 characters with 10-20% overlap to preserve context
- Batch embedding requests to reduce API latency and cost per text
- Cache embeddings for unchanged content to avoid redundant API calls
- Create IVFFlat or HNSW indexes on vector columns for fast similarity queries