Generate Embeddings
Generates vector embeddings for text using a local Ollama embedding model. Embeddings are numerical representations of text that capture semantic meaning, enabling advanced features like semantic search, text similarity comparison, and document clustering.
Use specialized embedding models like nomic-embed-text or mxbai-embed-large for best results. General chat models are not optimized for embeddings.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Client ID - The Client ID from the Connect node. Optional if Host URL is provided.
- Model - The name of the embedding model to use (e.g.,
nomic-embed-text,mxbai-embed-large,all-minilm). - Prompt - The text to generate embeddings for. This can be a sentence, paragraph, or document.
Output
- Embeddings - An array of floating-point numbers representing the text embedding. Typical dimensions range from 384 to 1024 depending on the model.
Options
- Host URL - Ollama server URL (optional). Use this instead of Client ID for direct connection. Example:
http://localhost:11434
How It Works
The Generate Embeddings node:
- Connects to the Ollama server (via Client ID or Host URL)
- Sends your text to the specified embedding model
- The model processes the text and generates a vector representation
- Returns the embedding as an array of numbers
- These numbers can be used for similarity calculations and search
Understanding Embeddings
Embeddings convert text into vectors (arrays of numbers) where:
- Similar texts have similar vectors (close in vector space)
- The distance between vectors indicates semantic similarity
- You can perform mathematical operations on embeddings
- Typical embedding dimensions: 384, 768, or 1024 numbers
Usage Examples
Example 1: Generate Basic Embedding
Inputs:
- Model: "nomic-embed-text"
- Prompt: "Robotic process automation streamlines business workflows"
Output:
- Embeddings: [0.123, -0.456, 0.789, ..., 0.234]
(Array of 768 floating-point numbers)
Example 2: Semantic Search Setup
// Step 1: Generate embeddings for your knowledge base
const documents = [
"RPA automates repetitive tasks",
"Machine learning enables predictive analytics",
"Cloud computing provides scalable infrastructure"
];
const documentEmbeddings = [];
for (const doc of documents) {
msg.textToEmbed = doc;
// Generate Embeddings node executes here
// Store result
documentEmbeddings.push({
text: doc,
embedding: msg.embeddings
});
}
msg.knowledgeBase = documentEmbeddings;
Example 3: Calculate Text Similarity
// After generating embeddings for two texts
const embedding1 = msg.embedding1; // From first Generate Embeddings node
const embedding2 = msg.embedding2; // From second Generate Embeddings node
// Calculate cosine similarity
function cosineSimilarity(vec1, vec2) {
const dotProduct = vec1.reduce((sum, val, i) => sum + val * vec2[i], 0);
const mag1 = Math.sqrt(vec1.reduce((sum, val) => sum + val * val, 0));
const mag2 = Math.sqrt(vec2.reduce((sum, val) => sum + val * val, 0));
return dotProduct / (mag1 * mag2);
}
const similarity = cosineSimilarity(embedding1, embedding2);
console.log(`Similarity score: ${similarity}`); // 0.0 to 1.0
if (similarity > 0.8) {
console.log("Texts are very similar");
} else if (similarity > 0.5) {
console.log("Texts are somewhat similar");
} else {
console.log("Texts are different");
}
Example 4: Document Clustering
// Generate embeddings for multiple documents
const documents = msg.documents; // Array of text documents
const embeddings = [];
for (const doc of documents) {
msg.textToEmbed = doc;
// Generate Embeddings node
embeddings.push({
text: doc,
embedding: msg.embeddings
});
}
// Simple clustering: find documents similar to first one
const referenceEmbedding = embeddings[0].embedding;
const clusters = {
similar: [],
different: []
};
for (let i = 1; i < embeddings.length; i++) {
const similarity = cosineSimilarity(referenceEmbedding, embeddings[i].embedding);
if (similarity > 0.7) {
clusters.similar.push(embeddings[i].text);
} else {
clusters.different.push(embeddings[i].text);
}
}
msg.clusters = clusters;
Example 5: Semantic Search Implementation
// Search query
const query = "How to automate Excel tasks?";
msg.textToEmbed = query;
// Generate Embeddings node for query
const queryEmbedding = msg.embeddings;
// Compare with knowledge base (from Example 2)
const knowledgeBase = msg.knowledgeBase; // Pre-computed embeddings
const results = [];
for (const doc of knowledgeBase) {
const similarity = cosineSimilarity(queryEmbedding, doc.embedding);
results.push({
text: doc.text,
similarity: similarity
});
}
// Sort by similarity (highest first)
results.sort((a, b) => b.similarity - a.similarity);
// Get top 3 results
const topResults = results.slice(0, 3);
console.log("Most relevant documents:");
topResults.forEach((result, i) => {
console.log(`${i + 1}. ${result.text} (${(result.similarity * 100).toFixed(1)}%)`);
});
msg.searchResults = topResults;
Example 6: Duplicate Detection
// Detect duplicate or near-duplicate content
const newDocument = "RPA helps automate repetitive business tasks";
msg.textToEmbed = newDocument;
// Generate Embeddings node
const newEmbedding = msg.embeddings;
// Compare with existing documents
const existingEmbeddings = msg.existingEmbeddings;
let isDuplicate = false;
for (const existing of existingEmbeddings) {
const similarity = cosineSimilarity(newEmbedding, existing.embedding);
if (similarity > 0.95) {
isDuplicate = true;
console.log(`Duplicate found: "${existing.text}"`);
console.log(`Similarity: ${(similarity * 100).toFixed(2)}%`);
break;
}
}
msg.isDuplicate = isDuplicate;
Recommended Embedding Models
For General Use
-
nomic-embed-text (274 MB, 768 dimensions)
- Good balance of quality and speed
- Works well for most text types
- Optimized for search and retrieval
-
mxbai-embed-large (669 MB, 1024 dimensions)
- Higher quality embeddings
- Better for complex semantic tasks
- Slightly slower but more accurate
-
all-minilm (23 MB, 384 dimensions)
- Very lightweight and fast
- Good for simple similarity tasks
- Lower memory requirements
Pulling Embedding Models
Before using, pull the model:
Pull Model node:
- Model: "nomic-embed-text"
Requirements
- Ollama service must be running
- An embedding model must be pulled locally
- Valid Client ID from Connect node OR Host URL provided
- Sufficient memory for the embedding model
Common Use Cases
- Semantic search in document repositories
- Finding similar customer support tickets
- Detecting duplicate content
- Clustering related documents
- Building recommendation systems
- Question-answering systems
- Content categorization
- Plagiarism detection
- Multi-language text comparison
Tips
Choosing Embedding Dimension
- 384 dimensions - Fast, lower accuracy, less storage
- 768 dimensions - Good balance (recommended)
- 1024 dimensions - Best accuracy, more storage/computation
Storing Embeddings
// Store embeddings in a database or file
const embeddingRecord = {
id: msg.documentId,
text: msg.originalText,
embedding: msg.embeddings,
timestamp: new Date().toISOString(),
metadata: {
source: msg.source,
category: msg.category
}
};
// Save to database or JSON file
msg.embeddingToStore = embeddingRecord;
Batch Processing
Process multiple texts efficiently:
const texts = msg.textArray;
const batchEmbeddings = [];
for (let i = 0; i < texts.length; i++) {
msg.textToEmbed = texts[i];
// Generate Embeddings node
batchEmbeddings.push(msg.embeddings);
// Show progress
if ((i + 1) % 10 === 0) {
console.log(`Processed ${i + 1}/${texts.length} documents`);
}
}
msg.allEmbeddings = batchEmbeddings;
Normalizing Embeddings
Some applications benefit from normalized vectors:
// After Generate Embeddings node
const embedding = msg.embeddings;
// Normalize to unit length
const magnitude = Math.sqrt(
embedding.reduce((sum, val) => sum + val * val, 0)
);
const normalizedEmbedding = embedding.map(val => val / magnitude);
msg.normalizedEmbedding = normalizedEmbedding;
Optimizing Search Performance
For large-scale search:
- Pre-compute embeddings for all documents
- Store embeddings in a vector database (e.g., Qdrant, Weaviate)
- Use approximate nearest neighbor algorithms for fast search
- Cache frequently accessed embeddings
Error Handling
Common errors you might encounter:
- "Model not found" - Pull the embedding model first
- "Prompt cannot be empty" - Provide text to embed
- Invalid model type - Ensure you're using an embedding model, not a chat model
- Out of memory - Use a smaller embedding model
Best Practices
- Use dedicated embedding models - Don't use chat models for embeddings
- Normalize text - Clean and preprocess text before embedding
- Batch similar texts - Process documents in logical groups
- Cache embeddings - Don't regenerate for the same text
- Use consistent models - Don't mix embeddings from different models
- Monitor dimensions - Track embedding size for storage planning
- Validate similarity scores - Test thresholds for your use case
Performance Considerations
- Embedding generation is fast (< 100ms for short texts)
- Longer texts take proportionally more time
- Batch processing is efficient for multiple documents
- Storage: 768-dim embedding = ~3KB per document
- Consider caching for frequently accessed content
Integration with Vector Databases
For production semantic search:
// After generating embedding
const embedding = msg.embeddings;
// Store in vector database (pseudo-code)
const vectorDB = {
id: msg.documentId,
vector: embedding,
metadata: {
text: msg.originalText,
category: msg.category,
timestamp: new Date()
}
};
// In search workflow:
// 1. Generate query embedding
// 2. Query vector database for nearest neighbors
// 3. Return top K most similar documents
Related Nodes
- Generate Completion - For text generation
- Pull Model - Download embedding models
- List Models - See available embedding models
- Connect - Establish connection