kailash 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kailash/__init__.py +1 -1
- kailash/api/__init__.py +11 -1
- kailash/api/gateway.py +394 -0
- kailash/api/mcp_integration.py +478 -0
- kailash/api/workflow_api.py +29 -13
- kailash/nodes/ai/__init__.py +40 -4
- kailash/nodes/ai/a2a.py +1143 -0
- kailash/nodes/ai/agents.py +120 -6
- kailash/nodes/ai/ai_providers.py +224 -30
- kailash/nodes/ai/embedding_generator.py +34 -38
- kailash/nodes/ai/intelligent_agent_orchestrator.py +2114 -0
- kailash/nodes/ai/llm_agent.py +351 -356
- kailash/nodes/ai/self_organizing.py +1624 -0
- kailash/nodes/api/http.py +106 -25
- kailash/nodes/api/rest.py +116 -21
- kailash/nodes/base.py +60 -64
- kailash/nodes/code/python.py +61 -42
- kailash/nodes/data/__init__.py +10 -10
- kailash/nodes/data/readers.py +117 -66
- kailash/nodes/data/retrieval.py +1 -1
- kailash/nodes/data/sharepoint_graph.py +23 -25
- kailash/nodes/data/sql.py +24 -26
- kailash/nodes/data/writers.py +41 -44
- kailash/nodes/logic/__init__.py +9 -3
- kailash/nodes/logic/async_operations.py +60 -21
- kailash/nodes/logic/operations.py +43 -22
- kailash/nodes/logic/workflow.py +26 -18
- kailash/nodes/mcp/client.py +29 -33
- kailash/nodes/transform/__init__.py +8 -1
- kailash/nodes/transform/formatters.py +1 -1
- kailash/nodes/transform/processors.py +119 -4
- kailash/tracking/metrics_collector.py +6 -7
- kailash/utils/export.py +2 -2
- kailash/utils/templates.py +16 -16
- {kailash-0.1.3.dist-info → kailash-0.1.5.dist-info}/METADATA +293 -29
- {kailash-0.1.3.dist-info → kailash-0.1.5.dist-info}/RECORD +40 -35
- {kailash-0.1.3.dist-info → kailash-0.1.5.dist-info}/WHEEL +0 -0
- {kailash-0.1.3.dist-info → kailash-0.1.5.dist-info}/entry_points.txt +0 -0
- {kailash-0.1.3.dist-info → kailash-0.1.5.dist-info}/licenses/LICENSE +0 -0
- {kailash-0.1.3.dist-info → kailash-0.1.5.dist-info}/top_level.txt +0 -0
kailash/nodes/ai/agents.py
CHANGED
@@ -7,7 +7,64 @@ from kailash.nodes.base import Node, NodeParameter, register_node
|
|
7
7
|
|
8
8
|
@register_node()
|
9
9
|
class ChatAgent(Node):
|
10
|
-
"""
|
10
|
+
"""
|
11
|
+
Chat-based AI agent node for conversational interactions.
|
12
|
+
|
13
|
+
This node provides a conversational AI interface that maintains context across
|
14
|
+
multiple message exchanges. It supports various LLM configurations and can be
|
15
|
+
customized with system prompts to create specialized conversational agents for
|
16
|
+
different domains and use cases.
|
17
|
+
|
18
|
+
Design Philosophy:
|
19
|
+
The ChatAgent embodies the principle of contextual conversation, maintaining
|
20
|
+
the full dialogue history to provide coherent and relevant responses. It
|
21
|
+
abstracts away the complexities of LLM APIs while providing a consistent
|
22
|
+
interface for chat-based interactions across different providers.
|
23
|
+
|
24
|
+
Upstream Dependencies:
|
25
|
+
- User interfaces or APIs providing conversation messages
|
26
|
+
- Context injection systems adding relevant information
|
27
|
+
- Authentication systems for user-specific interactions
|
28
|
+
- Workflow orchestrators managing conversation flow
|
29
|
+
|
30
|
+
Downstream Consumers:
|
31
|
+
- Response formatting nodes processing agent outputs
|
32
|
+
- Logging systems recording conversations
|
33
|
+
- Analytics nodes analyzing interaction patterns
|
34
|
+
- UI components displaying chat responses
|
35
|
+
|
36
|
+
Configuration:
|
37
|
+
The agent can be configured with different models, temperature settings,
|
38
|
+
and token limits. System prompts allow specialization for specific domains
|
39
|
+
or behaviors without code changes.
|
40
|
+
|
41
|
+
Implementation Details:
|
42
|
+
- Maintains conversation history with role-based messages
|
43
|
+
- Prepends system prompt to establish agent behavior
|
44
|
+
- Currently uses mock responses for testing (production would use LLM APIs)
|
45
|
+
- Supports streaming responses (when integrated with real LLMs)
|
46
|
+
- Implements token counting for cost management
|
47
|
+
- Thread-safe for concurrent conversations
|
48
|
+
|
49
|
+
Error Handling:
|
50
|
+
- Validates message format and required fields
|
51
|
+
- Handles empty or malformed conversations gracefully
|
52
|
+
- Returns appropriate responses for API failures
|
53
|
+
- Implements retry logic for transient errors
|
54
|
+
|
55
|
+
Side Effects:
|
56
|
+
- May log conversations for debugging (configurable)
|
57
|
+
- Updates internal conversation state
|
58
|
+
- May trigger external LLM API calls (in production)
|
59
|
+
|
60
|
+
Examples:
|
61
|
+
>>> # Test parameter structure without constructor validation
|
62
|
+
>>> agent = ChatAgent.__new__(ChatAgent)
|
63
|
+
>>> params = agent.get_parameters()
|
64
|
+
>>> assert "messages" in params
|
65
|
+
>>> assert "model" in params
|
66
|
+
>>> assert "temperature" in params
|
67
|
+
"""
|
11
68
|
|
12
69
|
def get_parameters(self) -> Dict[str, NodeParameter]:
|
13
70
|
return {
|
@@ -97,7 +154,64 @@ class ChatAgent(Node):
|
|
97
154
|
|
98
155
|
@register_node()
|
99
156
|
class RetrievalAgent(Node):
|
100
|
-
"""
|
157
|
+
"""
|
158
|
+
Retrieval-augmented generation (RAG) agent for knowledge-based responses.
|
159
|
+
|
160
|
+
This node implements a RAG pipeline that retrieves relevant documents based on
|
161
|
+
a query and optionally generates answers using the retrieved context. It combines
|
162
|
+
information retrieval techniques with language generation to provide accurate,
|
163
|
+
grounded responses based on provided documents.
|
164
|
+
|
165
|
+
Design Philosophy:
|
166
|
+
The RetrievalAgent addresses the hallucination problem in LLMs by grounding
|
167
|
+
responses in retrieved documents. It implements a two-stage process: first
|
168
|
+
finding relevant information, then synthesizing an answer based only on that
|
169
|
+
information. This ensures factual accuracy and traceability.
|
170
|
+
|
171
|
+
Upstream Dependencies:
|
172
|
+
- Document ingestion nodes providing indexed content
|
173
|
+
- Query processing nodes enhancing user queries
|
174
|
+
- Embedding generation nodes (in production implementations)
|
175
|
+
- Vector databases or search indices
|
176
|
+
|
177
|
+
Downstream Consumers:
|
178
|
+
- Response formatting nodes presenting answers
|
179
|
+
- Citation generation nodes adding references
|
180
|
+
- Quality assessment nodes evaluating retrieval accuracy
|
181
|
+
- UI components displaying results with sources
|
182
|
+
|
183
|
+
Configuration:
|
184
|
+
The agent can be configured with retrieval parameters like top_k results
|
185
|
+
and similarity thresholds. Answer generation can be toggled based on use
|
186
|
+
case requirements.
|
187
|
+
|
188
|
+
Implementation Details:
|
189
|
+
- Currently uses keyword-based similarity (production would use embeddings)
|
190
|
+
- Supports various document formats (dict with content, or strings)
|
191
|
+
- Implements relevance scoring and ranking
|
192
|
+
- Filters results by similarity threshold
|
193
|
+
- Generates contextual answers from retrieved documents
|
194
|
+
- Maintains retrieval provenance for transparency
|
195
|
+
|
196
|
+
Error Handling:
|
197
|
+
- Handles empty document sets gracefully
|
198
|
+
- Validates query format and parameters
|
199
|
+
- Returns empty results for no matches
|
200
|
+
- Provides meaningful responses even with limited retrieval
|
201
|
+
|
202
|
+
Side Effects:
|
203
|
+
- No persistent side effects
|
204
|
+
- May trigger embedding generation (in production)
|
205
|
+
- May access external vector databases
|
206
|
+
|
207
|
+
Examples:
|
208
|
+
>>> # Test parameter structure without constructor validation
|
209
|
+
>>> agent = RetrievalAgent.__new__(RetrievalAgent)
|
210
|
+
>>> params = agent.get_parameters()
|
211
|
+
>>> assert "query" in params
|
212
|
+
>>> assert "documents" in params
|
213
|
+
>>> assert "top_k" in params
|
214
|
+
"""
|
101
215
|
|
102
216
|
def get_parameters(self) -> Dict[str, NodeParameter]:
|
103
217
|
return {
|
@@ -333,7 +447,7 @@ class PlanningAgent(Node):
|
|
333
447
|
# Data processing workflow
|
334
448
|
potential_steps = [
|
335
449
|
{
|
336
|
-
"tool": "
|
450
|
+
"tool": "CSVReaderNode",
|
337
451
|
"description": "Read input data",
|
338
452
|
"parameters": {"file_path": "input.csv"},
|
339
453
|
},
|
@@ -348,7 +462,7 @@ class PlanningAgent(Node):
|
|
348
462
|
"parameters": {"group_by": "category", "operation": "sum"},
|
349
463
|
},
|
350
464
|
{
|
351
|
-
"tool": "
|
465
|
+
"tool": "CSVWriterNode",
|
352
466
|
"description": "Write results",
|
353
467
|
"parameters": {"file_path": "output.csv"},
|
354
468
|
},
|
@@ -357,7 +471,7 @@ class PlanningAgent(Node):
|
|
357
471
|
# Text analysis workflow
|
358
472
|
potential_steps = [
|
359
473
|
{
|
360
|
-
"tool": "
|
474
|
+
"tool": "TextReaderNode",
|
361
475
|
"description": "Read text data",
|
362
476
|
"parameters": {"file_path": "text.txt"},
|
363
477
|
},
|
@@ -372,7 +486,7 @@ class PlanningAgent(Node):
|
|
372
486
|
"parameters": {"max_length": 200},
|
373
487
|
},
|
374
488
|
{
|
375
|
-
"tool": "
|
489
|
+
"tool": "JSONWriterNode",
|
376
490
|
"description": "Save analysis results",
|
377
491
|
"parameters": {"file_path": "analysis.json"},
|
378
492
|
},
|
kailash/nodes/ai/ai_providers.py
CHANGED
@@ -17,12 +17,69 @@ class BaseAIProvider(ABC):
|
|
17
17
|
|
18
18
|
This abstract class defines the common interface and shared functionality
|
19
19
|
for providers that may support LLM operations, embedding operations, or both.
|
20
|
+
It establishes a unified pattern for provider initialization, capability
|
21
|
+
detection, and error handling across different AI services.
|
20
22
|
|
21
23
|
Design Philosophy:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
The BaseAIProvider follows the principle of "capability-based architecture"
|
25
|
+
where providers declare their capabilities explicitly. This allows for
|
26
|
+
flexible provider implementations that may support chat, embeddings, or
|
27
|
+
both, while maintaining a consistent interface. The design promotes:
|
28
|
+
- Single source of truth for provider availability
|
29
|
+
- Shared client management and initialization
|
30
|
+
- Common error handling patterns
|
31
|
+
- Flexible support for providers with different capabilities
|
32
|
+
|
33
|
+
Upstream Dependencies:
|
34
|
+
- Configuration systems providing API keys and credentials
|
35
|
+
- Environment variable loaders for secure credential management
|
36
|
+
- Package managers ensuring required dependencies
|
37
|
+
- Network infrastructure for API access
|
38
|
+
|
39
|
+
Downstream Consumers:
|
40
|
+
- LLMAgentNode: Uses chat capabilities for conversational AI
|
41
|
+
- EmbeddingGeneratorNode: Uses embedding capabilities for vector generation
|
42
|
+
- Provider selection logic choosing appropriate implementations
|
43
|
+
- Error handling systems catching provider-specific exceptions
|
44
|
+
|
45
|
+
Configuration:
|
46
|
+
Each provider implementation handles its own configuration needs,
|
47
|
+
typically through environment variables or explicit parameters.
|
48
|
+
Common patterns include API keys, endpoints, and model selections.
|
49
|
+
|
50
|
+
Implementation Details:
|
51
|
+
- Lazy initialization of clients to avoid unnecessary connections
|
52
|
+
- Cached availability checks to reduce repeated validation
|
53
|
+
- Capability dictionary for runtime feature detection
|
54
|
+
- Abstract methods enforce implementation of core functionality
|
55
|
+
- Thread-safe design for concurrent usage
|
56
|
+
|
57
|
+
Error Handling:
|
58
|
+
- Provider availability checked before operations
|
59
|
+
- Graceful degradation when providers are unavailable
|
60
|
+
- Standardized error responses across different providers
|
61
|
+
- Detailed error messages for debugging
|
62
|
+
|
63
|
+
Side Effects:
|
64
|
+
- May establish network connections to AI services
|
65
|
+
- May consume API quotas during availability checks
|
66
|
+
- Caches client instances for performance
|
67
|
+
|
68
|
+
Examples:
|
69
|
+
>>> # Provider implementation
|
70
|
+
>>> class MyProvider(BaseAIProvider):
|
71
|
+
... def __init__(self):
|
72
|
+
... super().__init__()
|
73
|
+
... self._capabilities = {"chat": True, "embeddings": False}
|
74
|
+
...
|
75
|
+
... def is_available(self) -> bool:
|
76
|
+
... # Check API key, dependencies, etc.
|
77
|
+
... return True
|
78
|
+
>>>
|
79
|
+
>>> provider = MyProvider()
|
80
|
+
>>> assert provider.supports_chat() == True
|
81
|
+
>>> assert provider.supports_embeddings() == False
|
82
|
+
>>> assert provider.is_available() == True
|
26
83
|
"""
|
27
84
|
|
28
85
|
def __init__(self):
|
@@ -70,8 +127,78 @@ class LLMProvider(BaseAIProvider):
|
|
70
127
|
"""
|
71
128
|
Abstract base class for providers that support LLM chat operations.
|
72
129
|
|
73
|
-
|
74
|
-
|
130
|
+
This class extends BaseAIProvider to define the interface for language model
|
131
|
+
providers. It ensures consistent chat operation interfaces across different
|
132
|
+
LLM services while allowing provider-specific optimizations and features.
|
133
|
+
|
134
|
+
Design Philosophy:
|
135
|
+
LLMProvider standardizes the chat interface while preserving flexibility
|
136
|
+
for provider-specific features. It follows the OpenAI message format as
|
137
|
+
the de facto standard, enabling easy switching between providers. The
|
138
|
+
design supports both simple completions and advanced features like
|
139
|
+
streaming, function calling, and custom parameters.
|
140
|
+
|
141
|
+
Upstream Dependencies:
|
142
|
+
- BaseAIProvider: Inherits core provider functionality
|
143
|
+
- Message formatting systems preparing chat inputs
|
144
|
+
- Token counting utilities for cost management
|
145
|
+
- Rate limiting systems managing API quotas
|
146
|
+
|
147
|
+
Downstream Consumers:
|
148
|
+
- LLMAgentNode: Primary consumer for chat operations
|
149
|
+
- ChatAgent: Uses for conversational interactions
|
150
|
+
- A2AAgentNode: Leverages for agent communication
|
151
|
+
- Response processing nodes handling outputs
|
152
|
+
|
153
|
+
Configuration:
|
154
|
+
Provider-specific parameters are passed through kwargs, allowing:
|
155
|
+
- Model selection (model parameter)
|
156
|
+
- Temperature and sampling parameters
|
157
|
+
- Token limits and stop sequences
|
158
|
+
- Provider-specific features (tools, functions, etc.)
|
159
|
+
|
160
|
+
Implementation Details:
|
161
|
+
- Standardized message format: List[Dict[str, str]]
|
162
|
+
- Messages contain 'role' and 'content' fields minimum
|
163
|
+
- Supports system, user, and assistant roles
|
164
|
+
- Response format standardized across providers
|
165
|
+
- Streaming support through callbacks (implementation-specific)
|
166
|
+
|
167
|
+
Error Handling:
|
168
|
+
- Invalid message format validation
|
169
|
+
- API error standardization
|
170
|
+
- Rate limit handling with retry guidance
|
171
|
+
- Token limit exceeded handling
|
172
|
+
- Network error recovery strategies
|
173
|
+
|
174
|
+
Side Effects:
|
175
|
+
- API calls consume tokens/credits
|
176
|
+
- May log conversations for debugging
|
177
|
+
- Updates internal usage metrics
|
178
|
+
- May trigger rate limiting
|
179
|
+
|
180
|
+
Examples:
|
181
|
+
>>> class MyLLMProvider(LLMProvider):
|
182
|
+
... def is_available(self) -> bool:
|
183
|
+
... return True # Check actual availability
|
184
|
+
...
|
185
|
+
... def chat(self, messages, **kwargs):
|
186
|
+
... # Simulate LLM response
|
187
|
+
... return {
|
188
|
+
... "success": True,
|
189
|
+
... "content": "Response to: " + messages[-1]["content"],
|
190
|
+
... "model": kwargs.get("model", "default"),
|
191
|
+
... "usage": {"prompt_tokens": 10, "completion_tokens": 5}
|
192
|
+
... }
|
193
|
+
>>>
|
194
|
+
>>> provider = MyLLMProvider()
|
195
|
+
>>> messages = [
|
196
|
+
... {"role": "system", "content": "You are helpful."},
|
197
|
+
... {"role": "user", "content": "Hello!"}
|
198
|
+
... ]
|
199
|
+
>>> response = provider.chat(messages, model="gpt-4")
|
200
|
+
>>> assert response["success"] == True
|
201
|
+
>>> assert "content" in response
|
75
202
|
"""
|
76
203
|
|
77
204
|
def __init__(self):
|
@@ -97,8 +224,79 @@ class EmbeddingProvider(BaseAIProvider):
|
|
97
224
|
"""
|
98
225
|
Abstract base class for providers that support embedding generation.
|
99
226
|
|
100
|
-
|
101
|
-
|
227
|
+
This class extends BaseAIProvider to define the interface for embedding
|
228
|
+
providers. It standardizes how text is converted to vector representations
|
229
|
+
across different embedding services while supporting provider-specific
|
230
|
+
optimizations and model configurations.
|
231
|
+
|
232
|
+
Design Philosophy:
|
233
|
+
EmbeddingProvider abstracts the complexity of different embedding models
|
234
|
+
and services behind a simple, consistent interface. It handles batching,
|
235
|
+
dimension management, and normalization while allowing providers to
|
236
|
+
optimize for their specific architectures. The design supports both
|
237
|
+
sentence and document embeddings with appropriate chunking strategies.
|
238
|
+
|
239
|
+
Upstream Dependencies:
|
240
|
+
- BaseAIProvider: Inherits core provider functionality
|
241
|
+
- Text preprocessing nodes preparing embedding inputs
|
242
|
+
- Chunking strategies for long documents
|
243
|
+
- Tokenization utilities for size management
|
244
|
+
|
245
|
+
Downstream Consumers:
|
246
|
+
- EmbeddingGeneratorNode: Primary consumer for vector generation
|
247
|
+
- Vector databases storing embeddings
|
248
|
+
- Similarity search implementations
|
249
|
+
- Clustering and classification systems
|
250
|
+
|
251
|
+
Configuration:
|
252
|
+
Provider-specific parameters include:
|
253
|
+
- Model selection for different embedding sizes/qualities
|
254
|
+
- Batch size limits for efficiency
|
255
|
+
- Normalization preferences
|
256
|
+
- Dimension specifications
|
257
|
+
|
258
|
+
Implementation Details:
|
259
|
+
- Batch processing for efficiency
|
260
|
+
- Automatic text truncation/chunking for model limits
|
261
|
+
- Vector normalization options
|
262
|
+
- Dimension validation and consistency
|
263
|
+
- Cache-friendly operations for repeated texts
|
264
|
+
|
265
|
+
Error Handling:
|
266
|
+
- Empty text handling
|
267
|
+
- Text length validation
|
268
|
+
- Batch size limit enforcement
|
269
|
+
- Model availability checking
|
270
|
+
- Dimension mismatch detection
|
271
|
+
|
272
|
+
Side Effects:
|
273
|
+
- API calls consume embedding quotas
|
274
|
+
- May cache embeddings for efficiency
|
275
|
+
- Updates usage metrics
|
276
|
+
- May trigger rate limiting
|
277
|
+
|
278
|
+
Examples:
|
279
|
+
>>> class MyEmbeddingProvider(EmbeddingProvider):
|
280
|
+
... def is_available(self) -> bool:
|
281
|
+
... return True
|
282
|
+
...
|
283
|
+
... def embed(self, texts, **kwargs):
|
284
|
+
... # Simulate embedding generation
|
285
|
+
... return [[0.1, 0.2, 0.3] for _ in texts]
|
286
|
+
...
|
287
|
+
... def get_model_info(self):
|
288
|
+
... return {
|
289
|
+
... "name": "my-embedding-model",
|
290
|
+
... "dimensions": 3,
|
291
|
+
... "max_tokens": 512
|
292
|
+
... }
|
293
|
+
>>>
|
294
|
+
>>> provider = MyEmbeddingProvider()
|
295
|
+
>>> embeddings = provider.embed(["Hello", "World"])
|
296
|
+
>>> assert len(embeddings) == 2
|
297
|
+
>>> assert len(embeddings[0]) == 3
|
298
|
+
>>> info = provider.get_model_info()
|
299
|
+
>>> assert info["dimensions"] == 3
|
102
300
|
"""
|
103
301
|
|
104
302
|
def __init__(self):
|
@@ -1159,18 +1357,17 @@ def get_provider(
|
|
1159
1357
|
ValueError: If the provider name is not recognized or doesn't support the requested type.
|
1160
1358
|
|
1161
1359
|
Examples:
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
Get chat-only provider
|
1172
|
-
|
1173
|
-
chat_provider = get_provider("anthropic", "chat")
|
1360
|
+
>>> # Get any provider
|
1361
|
+
>>> provider = get_provider("openai")
|
1362
|
+
>>> if provider.supports_chat():
|
1363
|
+
... # Use for chat
|
1364
|
+
... pass
|
1365
|
+
>>> if provider.supports_embeddings():
|
1366
|
+
... # Use for embeddings
|
1367
|
+
... pass
|
1368
|
+
|
1369
|
+
>>> # Get chat-only provider
|
1370
|
+
>>> chat_provider = get_provider("anthropic", "chat")
|
1174
1371
|
response = chat_provider.chat(messages, model="claude-3-sonnet")
|
1175
1372
|
|
1176
1373
|
Get embedding-only provider:
|
@@ -1223,18 +1420,15 @@ def get_available_providers(
|
|
1223
1420
|
Dict mapping provider names to their availability and capabilities.
|
1224
1421
|
|
1225
1422
|
Examples:
|
1423
|
+
>>> # Get all providers
|
1424
|
+
>>> all_providers = get_available_providers()
|
1425
|
+
>>> for name, info in all_providers.items():
|
1426
|
+
... print(f"{name}: Available={info['available']}, Chat={info['chat']}, Embeddings={info['embeddings']}")
|
1226
1427
|
|
1227
|
-
Get
|
1228
|
-
|
1229
|
-
all_providers = get_available_providers()
|
1230
|
-
for name, info in all_providers.items():
|
1231
|
-
print(f"{name}: Available={info['available']}, Chat={info['chat']}, Embeddings={info['embeddings']}")
|
1232
|
-
|
1233
|
-
Get only chat providers:
|
1234
|
-
|
1235
|
-
chat_providers = get_available_providers("chat")
|
1428
|
+
>>> # Get only chat providers
|
1429
|
+
>>> chat_providers = get_available_providers("chat")
|
1236
1430
|
|
1237
|
-
Get only embedding providers
|
1431
|
+
>>> # Get only embedding providers
|
1238
1432
|
|
1239
1433
|
embed_providers = get_available_providers("embeddings")
|
1240
1434
|
"""
|
@@ -7,7 +7,7 @@ from kailash.nodes.base import Node, NodeParameter, register_node
|
|
7
7
|
|
8
8
|
|
9
9
|
@register_node()
|
10
|
-
class
|
10
|
+
class EmbeddingGeneratorNode(Node):
|
11
11
|
"""
|
12
12
|
Vector embedding generator for RAG systems and semantic similarity operations.
|
13
13
|
|
@@ -61,46 +61,42 @@ class EmbeddingGenerator(Node):
|
|
61
61
|
- Updates usage statistics and cost tracking
|
62
62
|
|
63
63
|
Examples:
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
embedding_1=[0.1, 0.2, 0.3, ...],
|
97
|
-
embedding_2=[0.15, 0.25, 0.35, ...],
|
98
|
-
similarity_metric="cosine"
|
99
|
-
)
|
64
|
+
>>> # Single text embedding
|
65
|
+
>>> embedder = EmbeddingGeneratorNode()
|
66
|
+
>>> result = embedder.run(
|
67
|
+
... provider="openai",
|
68
|
+
... model="text-embedding-3-large",
|
69
|
+
... input_text="This is a sample document to embed",
|
70
|
+
... operation="embed_text"
|
71
|
+
... )
|
72
|
+
|
73
|
+
>>> # Batch document embedding
|
74
|
+
>>> batch_embedder = EmbeddingGeneratorNode()
|
75
|
+
>>> result = batch_embedder.run(
|
76
|
+
... provider="huggingface",
|
77
|
+
... model="sentence-transformers/all-MiniLM-L6-v2",
|
78
|
+
... input_texts=[
|
79
|
+
... "First document content...",
|
80
|
+
... "Second document content...",
|
81
|
+
... "Third document content..."
|
82
|
+
... ],
|
83
|
+
... operation="embed_batch",
|
84
|
+
... batch_size=32,
|
85
|
+
... cache_enabled=True
|
86
|
+
... )
|
87
|
+
|
88
|
+
>>> # Similarity calculation
|
89
|
+
>>> similarity = EmbeddingGeneratorNode()
|
90
|
+
>>> result = similarity.run(
|
91
|
+
... operation="calculate_similarity",
|
92
|
+
... embedding_1=[0.1, 0.2, 0.3], # ... removed for doctest
|
93
|
+
... embedding_2=[0.15, 0.25, 0.35], # ... removed for doctest
|
94
|
+
... similarity_metric="cosine"
|
95
|
+
... )
|
100
96
|
|
101
97
|
Cached embedding with MCP integration:
|
102
98
|
|
103
|
-
mcp_embedder =
|
99
|
+
mcp_embedder = EmbeddingGeneratorNode()
|
104
100
|
result = mcp_embedder.run(
|
105
101
|
provider="azure",
|
106
102
|
model="text-embedding-3-small",
|