kailash 0.1.2__py3-none-any.whl → 0.1.4__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.
Files changed (48) hide show
  1. kailash/__init__.py +1 -1
  2. kailash/api/__init__.py +17 -0
  3. kailash/api/gateway.py +394 -0
  4. kailash/api/mcp_integration.py +478 -0
  5. kailash/api/workflow_api.py +399 -0
  6. kailash/nodes/ai/__init__.py +4 -4
  7. kailash/nodes/ai/agents.py +4 -4
  8. kailash/nodes/ai/ai_providers.py +18 -22
  9. kailash/nodes/ai/embedding_generator.py +34 -38
  10. kailash/nodes/ai/llm_agent.py +351 -356
  11. kailash/nodes/api/http.py +0 -4
  12. kailash/nodes/api/rest.py +1 -1
  13. kailash/nodes/base.py +60 -64
  14. kailash/nodes/code/python.py +61 -42
  15. kailash/nodes/data/__init__.py +10 -10
  16. kailash/nodes/data/readers.py +27 -29
  17. kailash/nodes/data/retrieval.py +1 -1
  18. kailash/nodes/data/sharepoint_graph.py +23 -25
  19. kailash/nodes/data/sql.py +27 -29
  20. kailash/nodes/data/vector_db.py +2 -2
  21. kailash/nodes/data/writers.py +41 -44
  22. kailash/nodes/logic/__init__.py +10 -3
  23. kailash/nodes/logic/async_operations.py +14 -14
  24. kailash/nodes/logic/operations.py +18 -22
  25. kailash/nodes/logic/workflow.py +439 -0
  26. kailash/nodes/mcp/client.py +29 -33
  27. kailash/nodes/mcp/resource.py +1 -1
  28. kailash/nodes/mcp/server.py +10 -4
  29. kailash/nodes/transform/formatters.py +1 -1
  30. kailash/nodes/transform/processors.py +5 -3
  31. kailash/runtime/docker.py +2 -0
  32. kailash/tracking/metrics_collector.py +6 -7
  33. kailash/tracking/models.py +0 -20
  34. kailash/tracking/storage/database.py +4 -4
  35. kailash/tracking/storage/filesystem.py +0 -1
  36. kailash/utils/export.py +2 -2
  37. kailash/utils/templates.py +16 -16
  38. kailash/visualization/performance.py +7 -7
  39. kailash/visualization/reports.py +1 -1
  40. kailash/workflow/graph.py +4 -4
  41. kailash/workflow/mock_registry.py +1 -1
  42. {kailash-0.1.2.dist-info → kailash-0.1.4.dist-info}/METADATA +198 -27
  43. kailash-0.1.4.dist-info/RECORD +85 -0
  44. kailash-0.1.2.dist-info/RECORD +0 -80
  45. {kailash-0.1.2.dist-info → kailash-0.1.4.dist-info}/WHEEL +0 -0
  46. {kailash-0.1.2.dist-info → kailash-0.1.4.dist-info}/entry_points.txt +0 -0
  47. {kailash-0.1.2.dist-info → kailash-0.1.4.dist-info}/licenses/LICENSE +0 -0
  48. {kailash-0.1.2.dist-info → kailash-0.1.4.dist-info}/top_level.txt +0 -0
@@ -7,7 +7,7 @@ from kailash.nodes.base import Node, NodeParameter, register_node
7
7
 
8
8
 
9
9
  @register_node()
10
- class LLMAgent(Node):
10
+ class LLMAgentNode(Node):
11
11
  """
12
12
  Advanced Large Language Model agent with LangChain integration and MCP
13
13
  support.
@@ -64,63 +64,59 @@ class LLMAgent(Node):
64
64
  - Logs agent interactions and performance metrics
65
65
 
66
66
  Examples:
67
-
68
- Basic Q&A agent with OpenAI::
69
-
70
- agent = LLMAgent()
71
- result = agent.run(
72
- provider="openai",
73
- model="gpt-4",
74
- messages=[
75
- {"role": "user", "content": "Analyze the customer data and provide insights"}
76
- ],
77
- system_prompt="You are a data analyst expert.",
78
- mcp_context=["data://customer_reports/*"]
79
- )
80
-
81
- Tool-calling agent::
82
-
83
- tool_agent = LLMAgent()
84
- result = tool_agent.run(
85
- provider="anthropic",
86
- model="claude-3-sonnet",
87
- messages=[{"role": "user", "content": "Create a report and email it"}],
88
- tools=[
89
- {
90
- "name": "create_report",
91
- "description": "Generate a data report",
92
- "parameters": {"type": "object", "properties": {"format": {"type": "string"}}}
93
- },
94
- {
95
- "name": "send_email",
96
- "description": "Send email with attachment",
97
- "parameters": {"type": "object", "properties": {"recipient": {"type": "string"}}}
98
- }
99
- ],
100
- conversation_id="report_session_123"
101
- )
102
-
103
- RAG agent with MCP integration::
104
-
105
- rag_agent = LLMAgent()
106
- result = rag_agent.run(
107
- provider="azure",
108
- model="gpt-4-turbo",
109
- messages=[{"role": "user", "content": "What are the compliance requirements?"}],
110
- rag_config={
111
- "enabled": True,
112
- "top_k": 5,
113
- "similarity_threshold": 0.8
114
- },
115
- mcp_servers=[
116
- {
117
- "name": "compliance-server",
118
- "transport": "stdio",
119
- "command": "python",
120
- "args": ["-m", "compliance_mcp"]
121
- }
122
- ]
123
- )
67
+ >>> # Basic Q&A agent with OpenAI
68
+ >>> agent = LLMAgentNode()
69
+ >>> result = agent.run(
70
+ ... provider="openai",
71
+ ... model="gpt-4",
72
+ ... messages=[
73
+ ... {"role": "user", "content": "Analyze the customer data and provide insights"}
74
+ ... ],
75
+ ... system_prompt="You are a data analyst expert.",
76
+ ... mcp_context=["data://customer_reports/*"]
77
+ ... )
78
+
79
+ >>> # Tool-calling agent
80
+ >>> tool_agent = LLMAgentNode()
81
+ >>> result = tool_agent.run(
82
+ ... provider="anthropic",
83
+ ... model="claude-3-sonnet",
84
+ ... messages=[{"role": "user", "content": "Create a report and email it"}],
85
+ ... tools=[
86
+ ... {
87
+ ... "name": "create_report",
88
+ ... "description": "Generate a data report",
89
+ ... "parameters": {"type": "object", "properties": {"format": {"type": "string"}}}
90
+ ... },
91
+ ... {
92
+ ... "name": "send_email",
93
+ ... "description": "Send email with attachment",
94
+ ... "parameters": {"type": "object", "properties": {"recipient": {"type": "string"}}}
95
+ ... }
96
+ ... ],
97
+ ... conversation_id="report_session_123"
98
+ ... )
99
+
100
+ >>> # RAG agent with MCP integration
101
+ >>> rag_agent = LLMAgentNode()
102
+ >>> result = rag_agent.run(
103
+ ... provider="azure",
104
+ ... model="gpt-4-turbo",
105
+ ... messages=[{"role": "user", "content": "What are the compliance requirements?"}],
106
+ ... rag_config={
107
+ ... "enabled": True,
108
+ ... "top_k": 5,
109
+ ... "similarity_threshold": 0.8
110
+ ... },
111
+ ... mcp_servers=[
112
+ ... {
113
+ ... "name": "compliance-server",
114
+ ... "transport": "stdio",
115
+ ... "command": "python",
116
+ ... "args": ["-m", "compliance_mcp"]
117
+ ... }
118
+ ... ]
119
+ ... )
124
120
  """
125
121
 
126
122
  def get_parameters(self) -> Dict[str, NodeParameter]:
@@ -262,190 +258,189 @@ class LLMAgent(Node):
262
258
 
263
259
  Examples:
264
260
 
265
- Basic usage with OpenAI::
266
-
267
- agent = LLMAgent()
268
- result = agent.run(
269
- provider="openai",
270
- model="gpt-4",
271
- messages=[
272
- {"role": "user", "content": "Explain quantum computing"}
273
- ],
274
- generation_config={
275
- "temperature": 0.7,
276
- "max_tokens": 500,
277
- "top_p": 0.9,
278
- "frequency_penalty": 0.0,
279
- "presence_penalty": 0.0
280
- }
281
- )
282
- print(result["response"]["content"])
283
-
284
- Using Ollama with custom model::
285
-
286
- result = agent.run(
287
- provider="ollama",
288
- model="llama3.1:8b-instruct-q8_0",
289
- messages=[
290
- {"role": "user", "content": "Write a Python function"}
291
- ],
292
- generation_config={
293
- "temperature": 0.5,
294
- "max_tokens": 1000,
295
- "top_p": 0.95,
296
- "seed": 42 # For reproducible outputs
297
- }
298
- )
299
-
300
- With system prompt and conversation memory::
301
-
302
- result = agent.run(
303
- provider="anthropic",
304
- model="claude-3-sonnet-20240229",
305
- system_prompt="You are a helpful coding assistant.",
306
- messages=[
307
- {"role": "user", "content": "Help me optimize this code"}
308
- ],
309
- conversation_id="coding-session-123",
310
- memory_config={
311
- "type": "buffer", # or "summary", "buffer_window"
312
- "max_tokens": 4000,
313
- "persistence": "memory" # or "disk", "database"
314
- }
315
- )
316
-
317
- With tool calling::
318
-
319
- result = agent.run(
320
- provider="openai",
321
- model="gpt-4-turbo",
322
- messages=[
323
- {"role": "user", "content": "Get the weather in NYC"}
324
- ],
325
- tools=[
326
- {
327
- "type": "function",
328
- "function": {
329
- "name": "get_weather",
330
- "description": "Get weather for a location",
331
- "parameters": {
332
- "type": "object",
333
- "properties": {
334
- "location": {"type": "string"},
335
- "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
336
- },
337
- "required": ["location"]
338
- }
339
- }
340
- }
341
- ],
342
- generation_config={
343
- "temperature": 0, # Use 0 for tool calling
344
- "tool_choice": "auto" # or "none", {"type": "function", "function": {"name": "get_weather"}}
345
- }
346
- )
347
-
348
- With RAG (Retrieval Augmented Generation)::
349
-
350
- result = agent.run(
351
- provider="openai",
352
- model="gpt-4",
353
- messages=[
354
- {"role": "user", "content": "What is our refund policy?"}
355
- ],
356
- rag_config={
357
- "enabled": True,
358
- "top_k": 5, # Number of documents to retrieve
359
- "similarity_threshold": 0.7, # Minimum similarity score
360
- "embeddings": {
361
- "model": "text-embedding-ada-002",
362
- "dimension": 1536
363
- },
364
- "reranking": {
365
- "enabled": True,
366
- "model": "cross-encoder/ms-marco-MiniLM-L-12-v2"
367
- }
368
- }
369
- )
370
-
371
- With MCP (Model Context Protocol) integration::
372
-
373
- result = agent.run(
374
- provider="anthropic",
375
- model="claude-3-opus-20240229",
376
- messages=[
377
- {"role": "user", "content": "Analyze the sales data"}
378
- ],
379
- mcp_servers=[
380
- {
381
- "name": "data-server",
382
- "transport": "stdio",
383
- "command": "python",
384
- "args": ["-m", "mcp_data_server"],
385
- "env": {"API_KEY": "secret"}
386
- }
387
- ],
388
- mcp_context=[
389
- "data://sales/2024/q4",
390
- "data://customers/segments",
391
- "resource://templates/analysis"
392
- ]
393
- )
394
-
395
- Advanced configuration with all features::
396
-
397
- result = agent.run(
398
- provider="openai",
399
- model="gpt-4-turbo",
400
- messages=[
401
- {"role": "user", "content": "Complex analysis request"}
402
- ],
403
- system_prompt="You are an expert data analyst.",
404
- conversation_id="analysis-session-456",
405
- memory_config={
406
- "type": "buffer_window",
407
- "max_tokens": 3000,
408
- "window_size": 10 # Keep last 10 exchanges
409
- },
410
- tools=[...], # Tool definitions
411
- rag_config={
412
- "enabled": True,
413
- "top_k": 3,
414
- "similarity_threshold": 0.8
415
- },
416
- mcp_servers=[...], # MCP server configs
417
- mcp_context=["data://reports/*"],
418
- generation_config={
419
- "temperature": 0.7,
420
- "max_tokens": 2000,
421
- "top_p": 0.9,
422
- "frequency_penalty": 0.1,
423
- "presence_penalty": 0.1,
424
- "stop": ["\\n\\n", "END"], # Stop sequences
425
- "logit_bias": {123: -100} # Token biases
426
- },
427
- streaming=False,
428
- timeout=120,
429
- max_retries=3
430
- )
431
-
432
- Error handling::
433
-
434
- result = agent.run(
435
- provider="openai",
436
- model="gpt-4",
437
- messages=[{"role": "user", "content": "Hello"}]
438
- )
439
-
440
- if result["success"]:
441
- print(f"Response: {result['response']['content']}")
442
- print(f"Tokens used: {result['usage']['total_tokens']}")
443
- print(f"Estimated cost: ${result['usage']['estimated_cost_usd']}")
444
- else:
445
- print(f"Error: {result['error']}")
446
- print(f"Type: {result['error_type']}")
447
- for suggestion in result['recovery_suggestions']:
448
- print(f"- {suggestion}")
261
+ Basic usage with OpenAI:
262
+
263
+ >>> agent = LLMAgentNode()
264
+ >>> result = agent.run(
265
+ ... provider="openai",
266
+ ... model="gpt-4",
267
+ ... messages=[
268
+ ... {"role": "user", "content": "Explain quantum computing"}
269
+ ... ],
270
+ ... generation_config={
271
+ ... "temperature": 0.7,
272
+ ... "max_tokens": 500,
273
+ ... "top_p": 0.9,
274
+ ... "frequency_penalty": 0.0,
275
+ ... "presence_penalty": 0.0
276
+ ... }
277
+ ... )
278
+ >>> print(result["response"]["content"]) # doctest: +SKIP
279
+
280
+ Using Ollama with custom model:
281
+
282
+ >>> result = agent.run(
283
+ ... provider="ollama",
284
+ ... model="llama3.1:8b-instruct-q8_0",
285
+ ... messages=[
286
+ ... {"role": "user", "content": "Write a Python function"}
287
+ ... ],
288
+ ... generation_config={
289
+ ... "temperature": 0.5,
290
+ ... "max_tokens": 1000,
291
+ ... "top_p": 0.95,
292
+ ... "seed": 42 # For reproducible outputs
293
+ ... }
294
+ ... ) # doctest: +SKIP
295
+
296
+ With system prompt and conversation memory:
297
+
298
+ >>> result = agent.run(
299
+ ... provider="anthropic",
300
+ ... model="claude-3-sonnet-20240229",
301
+ ... system_prompt="You are a helpful coding assistant.",
302
+ ... messages=[
303
+ ... {"role": "user", "content": "Help me optimize this code"}
304
+ ... ],
305
+ ... conversation_id="coding-session-123",
306
+ ... memory_config={
307
+ ... "type": "buffer", # or "summary", "buffer_window"
308
+ ... "max_tokens": 4000,
309
+ ... "persistence": "memory" # or "disk", "database"
310
+ ... }
311
+ ... ) # doctest: +SKIP
312
+
313
+ With tool calling:
314
+
315
+ >>> result = agent.run(
316
+ ... provider="openai",
317
+ ... model="gpt-4-turbo",
318
+ ... messages=[
319
+ ... {"role": "user", "content": "Get the weather in NYC"}
320
+ ... ],
321
+ ... tools=[
322
+ ... {
323
+ ... "type": "function",
324
+ ... "function": {
325
+ ... "name": "get_weather",
326
+ ... "description": "Get weather for a location",
327
+ ... "parameters": {
328
+ ... "type": "object",
329
+ ... "properties": {
330
+ ... "location": {"type": "string"},
331
+ ... "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
332
+ ... },
333
+ ... "required": ["location"]
334
+ ... }
335
+ ... }
336
+ ... }
337
+ ... ],
338
+ ... generation_config={
339
+ ... "temperature": 0, # Use 0 for tool calling
340
+ ... "tool_choice": "auto" # or "none", {"type": "function", "function": {"name": "get_weather"}}
341
+ ... }
342
+ ... ) # doctest: +SKIP
343
+
344
+ With RAG (Retrieval Augmented Generation):
345
+
346
+ >>> result = agent.run(
347
+ ... provider="openai",
348
+ ... model="gpt-4",
349
+ ... messages=[
350
+ ... {"role": "user", "content": "What is our refund policy?"}
351
+ ... ],
352
+ ... rag_config={
353
+ ... "enabled": True,
354
+ ... "top_k": 5, # Number of documents to retrieve
355
+ ... "similarity_threshold": 0.7, # Minimum similarity score
356
+ ... "embeddings": {
357
+ ... "model": "text-embedding-ada-002",
358
+ ... "dimension": 1536
359
+ ... },
360
+ ... "reranking": {
361
+ ... "enabled": True,
362
+ ... "model": "cross-encoder/ms-marco-MiniLM-L-12-v2"
363
+ ... }
364
+ ... }
365
+ ... ) # doctest: +SKIP
366
+
367
+ With MCP (Model Context Protocol) integration:
368
+
369
+ >>> result = agent.run(
370
+ ... provider="anthropic",
371
+ ... model="claude-3-opus-20240229",
372
+ ... messages=[
373
+ ... {"role": "user", "content": "Analyze the sales data"}
374
+ ... ],
375
+ ... mcp_servers=[
376
+ ... {
377
+ ... "name": "data-server",
378
+ ... "transport": "stdio",
379
+ ... "command": "python",
380
+ ... "args": ["-m", "mcp_data_server"],
381
+ ... "env": {"API_KEY": "secret"}
382
+ ... }
383
+ ... ],
384
+ ... mcp_context=[
385
+ ... "data://sales/2024/q4",
386
+ ... "data://customers/segments",
387
+ ... "resource://templates/analysis"
388
+ ... ]
389
+ ... ) # doctest: +SKIP
390
+
391
+ Advanced configuration with all features:
392
+
393
+ >>> result = agent.run(
394
+ ... provider="openai",
395
+ ... model="gpt-4-turbo",
396
+ ... messages=[
397
+ ... {"role": "user", "content": "Complex analysis request"}
398
+ ... ],
399
+ ... system_prompt="You are an expert data analyst.",
400
+ ... conversation_id="analysis-session-456",
401
+ ... memory_config={
402
+ ... "type": "buffer_window",
403
+ ... "max_tokens": 3000,
404
+ ... "window_size": 10 # Keep last 10 exchanges
405
+ ... },
406
+ ... tools=[], # Tool definitions would go here
407
+ ... rag_config={
408
+ ... "enabled": True,
409
+ ... "top_k": 3,
410
+ ... "similarity_threshold": 0.8
411
+ ... },
412
+ ... mcp_servers=[], # MCP server configs would go here
413
+ ... mcp_context=["data://reports/*"],
414
+ ... generation_config={
415
+ ... "temperature": 0.7,
416
+ ... "max_tokens": 2000,
417
+ ... "top_p": 0.9,
418
+ ... "frequency_penalty": 0.1,
419
+ ... "presence_penalty": 0.1,
420
+ ... "stop": ["\\n\\n", "END"], # Stop sequences
421
+ ... "logit_bias": {123: -100} # Token biases
422
+ ... },
423
+ ... streaming=False,
424
+ ... timeout=120,
425
+ ... max_retries=3
426
+ ... ) # doctest: +SKIP
427
+
428
+ Error handling:
429
+
430
+ >>> result = agent.run(
431
+ ... provider="openai",
432
+ ... model="gpt-4",
433
+ ... messages=[{"role": "user", "content": "Hello"}]
434
+ ... )
435
+ >>> if result["success"]:
436
+ ... print(f"Response: {result['response']['content']}")
437
+ ... print(f"Tokens used: {result['usage']['total_tokens']}")
438
+ ... print(f"Estimated cost: ${result['usage']['estimated_cost_usd']}")
439
+ ... else:
440
+ ... print(f"Error: {result['error']}")
441
+ ... print(f"Type: {result['error_type']}")
442
+ ... for suggestion in result['recovery_suggestions']:
443
+ ... print(f"- {suggestion}") # doctest: +SKIP
449
444
  """
450
445
  provider = kwargs["provider"]
451
446
  model = kwargs["model"]
@@ -606,34 +601,34 @@ class LLMAgent(Node):
606
601
  loaded_from (str): Source of the memory data
607
602
 
608
603
  Examples:
609
- Buffer memory (keep everything)::
610
-
611
- memory = self._load_conversation_memory(
612
- "chat-123",
613
- {"type": "buffer", "max_tokens": 4000}
614
- )
615
-
616
- Window memory (keep last 5 exchanges)::
617
-
618
- memory = self._load_conversation_memory(
619
- "chat-456",
620
- {
621
- "type": "buffer_window",
622
- "window_size": 5,
623
- "max_tokens": 2000
624
- }
625
- )
626
-
627
- Summary memory (summarize old content)::
628
-
629
- memory = self._load_conversation_memory(
630
- "chat-789",
631
- {
632
- "type": "summary",
633
- "max_tokens": 1000,
634
- "summary_method": "abstractive"
635
- }
636
- )
604
+ Buffer memory (keep everything):
605
+
606
+ >>> memory = self._load_conversation_memory(
607
+ ... "chat-123",
608
+ ... {"type": "buffer", "max_tokens": 4000}
609
+ ... ) # doctest: +SKIP
610
+
611
+ Window memory (keep last 5 exchanges):
612
+
613
+ >>> memory = self._load_conversation_memory(
614
+ ... "chat-456",
615
+ ... {
616
+ ... "type": "buffer_window",
617
+ ... "window_size": 5,
618
+ ... "max_tokens": 2000
619
+ ... }
620
+ ... ) # doctest: +SKIP
621
+
622
+ Summary memory (summarize old content):
623
+
624
+ >>> memory = self._load_conversation_memory(
625
+ ... "chat-789",
626
+ ... {
627
+ ... "type": "summary",
628
+ ... "max_tokens": 1000,
629
+ ... "summary_method": "abstractive"
630
+ ... }
631
+ ... ) # doctest: +SKIP
637
632
  """
638
633
  if not conversation_id:
639
634
  return {"messages": [], "token_count": 0}
@@ -699,33 +694,33 @@ class LLMAgent(Node):
699
694
  metadata (Dict): Additional resource metadata
700
695
 
701
696
  Examples:
702
- Connect to stdio MCP server::
703
-
704
- context = self._retrieve_mcp_context(
705
- mcp_servers=[{
706
- "name": "data-server",
707
- "transport": "stdio",
708
- "command": "python",
709
- "args": ["-m", "mcp_data_server"],
710
- "env": {"API_KEY": "secret"}
711
- }],
712
- mcp_context=["data://sales/2024/q4"]
713
- )
714
-
715
- Connect to HTTP MCP server::
716
-
717
- context = self._retrieve_mcp_context(
718
- mcp_servers=[{
719
- "name": "api-server",
720
- "transport": "http",
721
- "url": "https://mcp.example.com",
722
- "headers": {"Authorization": "Bearer token"}
723
- }],
724
- mcp_context=[
725
- "resource://customers/segments",
726
- "prompt://analysis/financial"
727
- ]
728
- )
697
+ Connect to stdio MCP server:
698
+
699
+ >>> context = self._retrieve_mcp_context(
700
+ ... mcp_servers=[{
701
+ ... "name": "data-server",
702
+ ... "transport": "stdio",
703
+ ... "command": "python",
704
+ ... "args": ["-m", "mcp_data_server"],
705
+ ... "env": {"API_KEY": "secret"}
706
+ ... }],
707
+ ... mcp_context=["data://sales/2024/q4"]
708
+ ... ) # doctest: +SKIP
709
+
710
+ Connect to HTTP MCP server:
711
+
712
+ >>> context = self._retrieve_mcp_context(
713
+ ... mcp_servers=[{
714
+ ... "name": "api-server",
715
+ ... "transport": "http",
716
+ ... "url": "https://mcp.example.com",
717
+ ... "headers": {"Authorization": "Bearer token"}
718
+ ... }],
719
+ ... mcp_context=[
720
+ ... "resource://customers/segments",
721
+ ... "prompt://analysis/financial"
722
+ ... ]
723
+ ... ) # doctest: +SKIP
729
724
  """
730
725
  if not (mcp_servers or mcp_context):
731
726
  return []
@@ -807,65 +802,65 @@ class LLMAgent(Node):
807
802
  search_time_ms (float): Search duration
808
803
 
809
804
  Examples:
810
- Basic RAG retrieval::
811
-
812
- rag_result = self._perform_rag_retrieval(
813
- messages=[{"role": "user", "content": "What is the refund policy?"}],
814
- rag_config={
815
- "enabled": True,
816
- "top_k": 5,
817
- "similarity_threshold": 0.7
818
- },
819
- mcp_context=[]
820
- )
821
-
822
- Advanced RAG with reranking::
823
-
824
- rag_result = self._perform_rag_retrieval(
825
- messages=[{"role": "user", "content": "Technical specifications"}],
826
- rag_config={
827
- "enabled": True,
828
- "top_k": 10,
829
- "similarity_threshold": 0.6,
830
- "embeddings": {
831
- "model": "text-embedding-ada-002",
832
- "dimension": 1536,
833
- "provider": "openai"
834
- },
835
- "reranking": {
836
- "enabled": True,
837
- "model": "cross-encoder/ms-marco-MiniLM-L-12-v2",
838
- "top_n": 3
839
- },
840
- "vector_store": {
841
- "type": "pinecone",
842
- "index_name": "products",
843
- "namespace": "technical-docs"
844
- }
845
- },
846
- mcp_context=[]
847
- )
848
-
849
- Hybrid search with filters::
850
-
851
- rag_result = self._perform_rag_retrieval(
852
- messages=[{"role": "user", "content": "Python tutorials"}],
853
- rag_config={
854
- "enabled": True,
855
- "top_k": 5,
856
- "similarity_threshold": 0.7,
857
- "filters": {
858
- "category": "tutorial",
859
- "language": "python",
860
- "level": ["beginner", "intermediate"]
861
- },
862
- "hybrid_search": {
863
- "enabled": True,
864
- "alpha": 0.7 # 70% vector, 30% keyword
865
- }
866
- },
867
- mcp_context=[]
868
- )
805
+ Basic RAG retrieval:
806
+
807
+ >>> rag_result = self._perform_rag_retrieval(
808
+ ... messages=[{"role": "user", "content": "What is the refund policy?"}],
809
+ ... rag_config={
810
+ ... "enabled": True,
811
+ ... "top_k": 5,
812
+ ... "similarity_threshold": 0.7
813
+ ... },
814
+ ... mcp_context=[]
815
+ ... ) # doctest: +SKIP
816
+
817
+ Advanced RAG with reranking:
818
+
819
+ >>> rag_result = self._perform_rag_retrieval(
820
+ ... messages=[{"role": "user", "content": "Technical specifications"}],
821
+ ... rag_config={
822
+ ... "enabled": True,
823
+ ... "top_k": 10,
824
+ ... "similarity_threshold": 0.6,
825
+ ... "embeddings": {
826
+ ... "model": "text-embedding-ada-002",
827
+ ... "dimension": 1536,
828
+ ... "provider": "openai"
829
+ ... },
830
+ ... "reranking": {
831
+ ... "enabled": True,
832
+ ... "model": "cross-encoder/ms-marco-MiniLM-L-12-v2",
833
+ ... "top_n": 3
834
+ ... },
835
+ ... "vector_store": {
836
+ ... "type": "pinecone",
837
+ ... "index_name": "products",
838
+ ... "namespace": "technical-docs"
839
+ ... }
840
+ ... },
841
+ ... mcp_context=[]
842
+ ... ) # doctest: +SKIP
843
+
844
+ Hybrid search with filters:
845
+
846
+ >>> rag_result = self._perform_rag_retrieval(
847
+ ... messages=[{"role": "user", "content": "Python tutorials"}],
848
+ ... rag_config={
849
+ ... "enabled": True,
850
+ ... "top_k": 5,
851
+ ... "similarity_threshold": 0.7,
852
+ ... "filters": {
853
+ ... "category": "tutorial",
854
+ ... "language": "python",
855
+ ... "level": ["beginner", "intermediate"]
856
+ ... },
857
+ ... "hybrid_search": {
858
+ ... "enabled": True,
859
+ ... "alpha": 0.7 # 70% vector, 30% keyword
860
+ ... }
861
+ ... },
862
+ ... mcp_context=[]
863
+ ... ) # doctest: +SKIP
869
864
  """
870
865
  if not rag_config.get("enabled", False):
871
866
  return {"documents": [], "scores": []}