Overview
The embeddings module consists of two main components:- embeddings-base: Core interfaces and data structures
- embeddings-llm: LLM-based embedding generation (OpenAI, Anthropic, etc.)
- Semantic Search: Find documents by meaning, not just keywords
- Code Similarity: Compare code snippets across different languages
- Document Clustering: Group similar documents together
- Question Answering: Match questions to relevant context
- Recommendation: Find related content based on semantic similarity
Installation
Add the embeddings dependencies:gradle
Quick Start
Generate embeddings and calculate similarity:Core Interfaces
Embedder
The main interface for embedding operations:embeddings/README.md:154
Vector
Represents a vector of floating-point values:embeddings/README.md:173
LLM-based Embeddings
Use LLM providers for embedding generation:Use Cases
Code-to-Text Comparison
Compare code snippets with natural language descriptions:embeddings/README.md:57
Code-to-Code Comparison
Compare code across different languages:embeddings/README.md:95
Semantic Search
Find the most relevant documents:Document Clustering
Group similar documents:Similarity Metrics
Cosine Similarity
Measures the cosine of the angle between vectors:Euclidean Distance
Measures the straight-line distance between vectors:Supported Embedding Models
OpenAI
Anthropic
Use Anthropic’s embedding models through the LLM provider.Custom Models
Implement custom embedding providers:Performance Considerations
-
Batch Processing: Process multiple documents in parallel
-
Caching: Cache embeddings to avoid recomputation
-
Dimension Reduction: Use smaller models for faster processing
Best Practices
-
Normalize Text: Clean and normalize text before embedding
-
Choose Right Model: Balance quality vs performance
- Small models: Faster, less accurate
- Large models: Slower, more accurate
-
Store Embeddings: Cache embeddings in a database
-
Handle Errors: Gracefully handle API failures
Integration with RAG
Use embeddings with RAG for document retrieval:Platform Support
- JVM: Full support
- JS: Full support
- Native: Planned
Common Use Cases
- Semantic Search: Find documents by meaning
- Code Search: Find similar code snippets
- Question Answering: Match questions to answers
- Content Recommendation: Suggest related content
- Duplicate Detection: Find duplicate or near-duplicate content
- Document Classification: Classify documents by similarity
Next Steps
- Learn about RAG capabilities for document retrieval
- Explore vector storage options
- See embedding examples in action
- Check out semantic search patterns