What are Text Embeddings?
Text embeddings are dense vector representations of text where semantically similar texts have similar vector representations. Unlike simple keyword matching, embeddings understand context and meaning:- “The weather is lovely today” and “It’s so sunny outside!” have high similarity
- “He drove to the stadium” has low similarity to weather-related sentences
Key Features
- On-device Processing: Generate embeddings locally without network requests
- Real-time Performance: Fast inference optimized for mobile devices
- Multiple Models: Support for various embedding models including MiniLM and CLIP
- React Integration: Easy-to-use hook API with loading states
Common Use Cases
Semantic Search
Find relevant content based on meaning, not just keywords
Content Recommendation
Recommend similar items based on embedding similarity
Duplicate Detection
Identify duplicate or near-duplicate content
Content Clustering
Group similar content together automatically
Supported Models
ALL_MINILM_L6_V2
A compact and efficient sentence transformer model ideal for general-purpose text embeddings.- Size: Optimized for mobile deployment
- Use Case: General semantic search and similarity tasks
- Output: 384-dimensional embeddings
CLIP_VIT_BASE_PATCH32_TEXT
Text encoder from the CLIP model, designed for multimodal image-text matching.- Use Case: Image-text matching, cross-modal retrieval
- Output: 512-dimensional embeddings
- Compatible: Works with CLIP image embeddings
How It Works
- Load Model: The hook downloads and loads the model and tokenizer
- Generate Embeddings: Call
forward()with your text - Compare Vectors: Use dot product or cosine similarity to compare embeddings
- Find Matches: Rank results by similarity score
Next Steps
Usage Guide
Learn how to use the useTextEmbeddings hook
Semantic Search
Build a semantic search feature