Skip to main content

Embeddings

Embeddings are numerical representations of text that capture semantic meaning. They enable semantic search, similarity comparison, and are essential for vector databases and RAG applications.

What are Embeddings?

Embeddings convert text into high-dimensional vectors (arrays of numbers) where:
  • Similar meanings → Similar vectors
  • Different meanings → Distant vectors
  • Semantic relationships are preserved
For example, “king” and “queen” will have similar embeddings because they’re semantically related, even though they share no letters.

Why Use Embeddings?

Semantic Search

Find content by meaning, not just keywords

Similarity Comparison

Compare documents for similarity

RAG Applications

Provide relevant context to LLMs

Classification

Categorize content by semantic similarity

Available Embedding Models

n8n supports embeddings from multiple providers:

OpenAI Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsOpenAi Source Reference: /home/daytona/workspace/source/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts:78 Models:
  • text-embedding-3-small (1536 dimensions) - Default, best value
  • text-embedding-3-large (3072 dimensions) - Highest quality
  • text-embedding-ada-002 (1536 dimensions) - Legacy model
Configuration:
Options: From the source code:
text-embedding-3-small offers the best balance of quality, speed, and cost for most use cases.

Cohere Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsCohere Source Reference: /home/daytona/workspace/source/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts:13 Models:
  • embed-english-v3.0 (1024 dimensions)
  • embed-english-v2.0 (4096 dimensions)
  • embed-english-light-v3.0 (384 dimensions)
  • embed-english-light-v2.0 (1024 dimensions)
  • embed-multilingual-v3.0 (1024 dimensions)
  • embed-multilingual-v2.0 (768 dimensions)
  • embed-multilingual-light-v3.0 (384 dimensions)
Configuration:
Each Cohere model uses different dimensional density. Make sure your vector store matches the model’s dimensions.

Google Embeddings

Google Gemini Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsGoogleGemini Models:
  • text-embedding-004
  • embedding-001

Google Vertex AI Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsGoogleVertex Use when: You need Google Cloud integration

Azure OpenAI Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsAzureOpenAi Use when: You’re using Azure OpenAI Service Configuration:

AWS Bedrock Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsAwsBedrock Models:
  • Amazon Titan Embeddings
  • Cohere Embed models via Bedrock

Ollama Embeddings (Local)

Node: @n8n/n8n-nodes-langchain.embeddingsOllama Use when: You need local/private embeddings Models:
  • nomic-embed-text
  • all-minilm
  • mxbai-embed-large
  • Any Ollama-compatible model
Configuration:
Ollama is perfect for development or when you need to keep data private. No API costs!

Hugging Face Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsHuggingFaceInference Use when: You want open-source models via API Popular Models:
  • sentence-transformers/all-MiniLM-L6-v2 (384 dimensions)
  • sentence-transformers/all-mpnet-base-v2 (768 dimensions)
  • BAAI/bge-base-en-v1.5 (768 dimensions)

Mistral Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsMistralCloud Model: mistral-embed

Lemonade AI Embeddings

Node: @n8n/n8n-nodes-langchain.embeddingsLemonade Use when: Using Lemonade AI platform

Choosing an Embedding Model

Decision Matrix

Considerations

1

Quality Requirements

Higher dimensions generally mean better quality but higher costs
2

Language Support

Use multilingual models if you need non-English support
3

Cost

Consider API costs, especially at scale
4

Latency

Smaller models are faster to compute
5

Privacy

Use local models (Ollama) if data privacy is critical

Using Embeddings in Workflows

Basic RAG Pipeline

Agent with Knowledge Base

Embedding Configuration

Batch Size

From the OpenAI embeddings source code:
Larger batch sizes improve throughput but may hit rate limits. Start with 512 and adjust based on your usage.

Dimensions (OpenAI only)

OpenAI’s text-embedding-3 models support configurable dimensions:
Lower dimensions:
  • ✅ Faster processing
  • ✅ Lower storage costs
  • ✅ Faster similarity search
  • ❌ Lower quality
Higher dimensions:
  • ✅ Better quality
  • ✅ More accurate results
  • ❌ Slower
  • ❌ Higher costs

Strip New Lines

Stripping new lines can improve embedding quality by normalizing text format.

Best Practices

Always Use the Same Model

Critical: Always use the same embedding model for both inserting and querying. Mixing models will produce incorrect results.

Match Vector Store Dimensions

Ensure your vector store is configured with the correct dimensions:

Optimize Chunk Size

Chunk your text before embedding:
Guidelines:
  • Too small (< 200 chars): Lacks context
  • Too large (> 2000 chars): Dilutes specific information
  • Optimal: 500-1000 characters
  • Overlap: 10-20% of chunk size

Handle Rate Limits

Monitor Costs

OpenAI Pricing (as of 2024):
  • text-embedding-3-small: $0.02 / 1M tokens
  • text-embedding-3-large: $0.13 / 1M tokens
  • text-embedding-ada-002: $0.10 / 1M tokens
Cost Optimization:
  • Use smaller models when appropriate
  • Cache embeddings when possible
  • Use lower dimensions for text-embedding-3
  • Consider Ollama for development

Cache Embeddings

Avoid re-embedding the same content:

Advanced Features

Custom Base URL

For OpenAI-compatible APIs:

Custom Headers

Add custom HTTP headers:

Timeout Configuration

Troubleshooting

Dimension Mismatch Error

Error: “Expected vector of size X, got Y” Solution: Ensure vector store dimensions match embedding model:

Rate Limit Errors

Error: “Rate limit exceeded” Solutions:
  1. Reduce batch size
  2. Add delays between batches
  3. Implement exponential backoff
  4. Upgrade API tier

Poor Search Quality

Possible Causes:
  1. Wrong embedding model for query
  2. Poor chunk size
  3. Missing context
  4. Low-quality source data
Solutions:
  1. Verify same model for insert and query
  2. Adjust chunk size and overlap
  3. Include surrounding context in chunks
  4. Clean and preprocess source data

High Latency

Solutions:
  1. Use faster models (smaller dimensions)
  2. Increase batch size
  3. Consider local models (Ollama)
  4. Use edge locations
  5. Implement caching

Comparison Table

Next Steps

Vector Stores

Store your embeddings in vector databases

RAG Tutorial

Build a complete RAG application

Text Splitters

Learn about chunking strategies

Semantic Search

Implement semantic search