AI / LangChain4j interview questions
What is the EmbeddingModel in LangChain4j and which providers are supported?
An EmbeddingModel in LangChain4j converts text into dense numerical vectors (embeddings) that capture semantic meaning. Texts with similar meanings produce vectors that are geometrically close, enabling similarity search. EmbeddingModels are used during RAG ingestion (to vectorize document chunks) and at query time (to vectorize the user's question so it can be matched against stored chunks).
The core interface is minimal by design:
public interface EmbeddingModel { Response<Embedding> embed(String text); Response<List<Embedding>> embedAll(List<TextSegment> textSegments); }
Supported embedding model providers include:
| Provider | Example Model | Notes |
|---|---|---|
| OpenAI | text-embedding-3-small / ada-002 | Most commonly used; cloud API |
| Azure OpenAI | text-embedding-ada-002 | Enterprise Azure deployments |
| Google Vertex AI | textembedding-gecko | GCP-based workloads |
| Ollama | nomic-embed-text, mxbai-embed | Local/on-premise, no API costs |
| HuggingFace | sentence-transformers models | Open-source models via HF Inference API |
| In-process (Onnx) | all-MiniLM-L6-v2 | Embedded in the JVM — no external calls, fastest |
The in-process ONNX option (langchain4j-embeddings module) is particularly useful for offline environments or when minimizing API costs: the model runs entirely within the JVM with no network calls, at the cost of slightly lower embedding quality compared to frontier models.
More Related questions...