mantisdk 0.1.0__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.

Potentially problematic release.


This version of mantisdk might be problematic. Click here for more details.

Files changed (190) hide show
  1. mantisdk/__init__.py +22 -0
  2. mantisdk/adapter/__init__.py +15 -0
  3. mantisdk/adapter/base.py +94 -0
  4. mantisdk/adapter/messages.py +270 -0
  5. mantisdk/adapter/triplet.py +1028 -0
  6. mantisdk/algorithm/__init__.py +39 -0
  7. mantisdk/algorithm/apo/__init__.py +5 -0
  8. mantisdk/algorithm/apo/apo.py +889 -0
  9. mantisdk/algorithm/apo/prompts/apply_edit_variant01.poml +22 -0
  10. mantisdk/algorithm/apo/prompts/apply_edit_variant02.poml +18 -0
  11. mantisdk/algorithm/apo/prompts/text_gradient_variant01.poml +18 -0
  12. mantisdk/algorithm/apo/prompts/text_gradient_variant02.poml +16 -0
  13. mantisdk/algorithm/apo/prompts/text_gradient_variant03.poml +107 -0
  14. mantisdk/algorithm/base.py +162 -0
  15. mantisdk/algorithm/decorator.py +264 -0
  16. mantisdk/algorithm/fast.py +250 -0
  17. mantisdk/algorithm/gepa/__init__.py +59 -0
  18. mantisdk/algorithm/gepa/adapter.py +459 -0
  19. mantisdk/algorithm/gepa/gepa.py +364 -0
  20. mantisdk/algorithm/gepa/lib/__init__.py +18 -0
  21. mantisdk/algorithm/gepa/lib/adapters/README.md +12 -0
  22. mantisdk/algorithm/gepa/lib/adapters/__init__.py +0 -0
  23. mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/README.md +341 -0
  24. mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/__init__.py +1 -0
  25. mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/anymaths_adapter.py +174 -0
  26. mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/requirements.txt +1 -0
  27. mantisdk/algorithm/gepa/lib/adapters/default_adapter/README.md +0 -0
  28. mantisdk/algorithm/gepa/lib/adapters/default_adapter/__init__.py +0 -0
  29. mantisdk/algorithm/gepa/lib/adapters/default_adapter/default_adapter.py +209 -0
  30. mantisdk/algorithm/gepa/lib/adapters/dspy_adapter/README.md +7 -0
  31. mantisdk/algorithm/gepa/lib/adapters/dspy_adapter/__init__.py +0 -0
  32. mantisdk/algorithm/gepa/lib/adapters/dspy_adapter/dspy_adapter.py +307 -0
  33. mantisdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/README.md +99 -0
  34. mantisdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/dspy_program_proposal_signature.py +137 -0
  35. mantisdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/full_program_adapter.py +266 -0
  36. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/GEPA_RAG.md +621 -0
  37. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/__init__.py +56 -0
  38. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/evaluation_metrics.py +226 -0
  39. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/generic_rag_adapter.py +496 -0
  40. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/rag_pipeline.py +238 -0
  41. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_store_interface.py +212 -0
  42. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/__init__.py +2 -0
  43. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/chroma_store.py +196 -0
  44. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/lancedb_store.py +422 -0
  45. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/milvus_store.py +409 -0
  46. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/qdrant_store.py +368 -0
  47. mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/weaviate_store.py +418 -0
  48. mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/README.md +552 -0
  49. mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/__init__.py +37 -0
  50. mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/mcp_adapter.py +705 -0
  51. mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/mcp_client.py +364 -0
  52. mantisdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/README.md +9 -0
  53. mantisdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/__init__.py +0 -0
  54. mantisdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/terminal_bench_adapter.py +217 -0
  55. mantisdk/algorithm/gepa/lib/api.py +375 -0
  56. mantisdk/algorithm/gepa/lib/core/__init__.py +0 -0
  57. mantisdk/algorithm/gepa/lib/core/adapter.py +180 -0
  58. mantisdk/algorithm/gepa/lib/core/data_loader.py +74 -0
  59. mantisdk/algorithm/gepa/lib/core/engine.py +356 -0
  60. mantisdk/algorithm/gepa/lib/core/result.py +233 -0
  61. mantisdk/algorithm/gepa/lib/core/state.py +636 -0
  62. mantisdk/algorithm/gepa/lib/examples/__init__.py +0 -0
  63. mantisdk/algorithm/gepa/lib/examples/aime.py +24 -0
  64. mantisdk/algorithm/gepa/lib/examples/anymaths-bench/eval_default.py +111 -0
  65. mantisdk/algorithm/gepa/lib/examples/anymaths-bench/prompt-templates/instruction_prompt.txt +9 -0
  66. mantisdk/algorithm/gepa/lib/examples/anymaths-bench/prompt-templates/optimal_prompt.txt +24 -0
  67. mantisdk/algorithm/gepa/lib/examples/anymaths-bench/train_anymaths.py +177 -0
  68. mantisdk/algorithm/gepa/lib/examples/dspy_full_program_evolution/arc_agi.ipynb +25705 -0
  69. mantisdk/algorithm/gepa/lib/examples/dspy_full_program_evolution/example.ipynb +348 -0
  70. mantisdk/algorithm/gepa/lib/examples/mcp_adapter/__init__.py +4 -0
  71. mantisdk/algorithm/gepa/lib/examples/mcp_adapter/mcp_optimization_example.py +455 -0
  72. mantisdk/algorithm/gepa/lib/examples/rag_adapter/RAG_GUIDE.md +613 -0
  73. mantisdk/algorithm/gepa/lib/examples/rag_adapter/__init__.py +9 -0
  74. mantisdk/algorithm/gepa/lib/examples/rag_adapter/rag_optimization.py +824 -0
  75. mantisdk/algorithm/gepa/lib/examples/rag_adapter/requirements-rag.txt +29 -0
  76. mantisdk/algorithm/gepa/lib/examples/terminal-bench/prompt-templates/instruction_prompt.txt +16 -0
  77. mantisdk/algorithm/gepa/lib/examples/terminal-bench/prompt-templates/terminus.txt +9 -0
  78. mantisdk/algorithm/gepa/lib/examples/terminal-bench/train_terminus.py +161 -0
  79. mantisdk/algorithm/gepa/lib/gepa_utils.py +117 -0
  80. mantisdk/algorithm/gepa/lib/logging/__init__.py +0 -0
  81. mantisdk/algorithm/gepa/lib/logging/experiment_tracker.py +187 -0
  82. mantisdk/algorithm/gepa/lib/logging/logger.py +75 -0
  83. mantisdk/algorithm/gepa/lib/logging/utils.py +103 -0
  84. mantisdk/algorithm/gepa/lib/proposer/__init__.py +0 -0
  85. mantisdk/algorithm/gepa/lib/proposer/base.py +31 -0
  86. mantisdk/algorithm/gepa/lib/proposer/merge.py +357 -0
  87. mantisdk/algorithm/gepa/lib/proposer/reflective_mutation/__init__.py +0 -0
  88. mantisdk/algorithm/gepa/lib/proposer/reflective_mutation/base.py +49 -0
  89. mantisdk/algorithm/gepa/lib/proposer/reflective_mutation/reflective_mutation.py +176 -0
  90. mantisdk/algorithm/gepa/lib/py.typed +0 -0
  91. mantisdk/algorithm/gepa/lib/strategies/__init__.py +0 -0
  92. mantisdk/algorithm/gepa/lib/strategies/batch_sampler.py +77 -0
  93. mantisdk/algorithm/gepa/lib/strategies/candidate_selector.py +50 -0
  94. mantisdk/algorithm/gepa/lib/strategies/component_selector.py +36 -0
  95. mantisdk/algorithm/gepa/lib/strategies/eval_policy.py +64 -0
  96. mantisdk/algorithm/gepa/lib/strategies/instruction_proposal.py +127 -0
  97. mantisdk/algorithm/gepa/lib/utils/__init__.py +10 -0
  98. mantisdk/algorithm/gepa/lib/utils/stop_condition.py +196 -0
  99. mantisdk/algorithm/gepa/tracing.py +105 -0
  100. mantisdk/algorithm/utils.py +177 -0
  101. mantisdk/algorithm/verl/__init__.py +5 -0
  102. mantisdk/algorithm/verl/interface.py +202 -0
  103. mantisdk/cli/__init__.py +56 -0
  104. mantisdk/cli/prometheus.py +115 -0
  105. mantisdk/cli/store.py +131 -0
  106. mantisdk/cli/vllm.py +29 -0
  107. mantisdk/client.py +408 -0
  108. mantisdk/config.py +348 -0
  109. mantisdk/emitter/__init__.py +43 -0
  110. mantisdk/emitter/annotation.py +370 -0
  111. mantisdk/emitter/exception.py +54 -0
  112. mantisdk/emitter/message.py +61 -0
  113. mantisdk/emitter/object.py +117 -0
  114. mantisdk/emitter/reward.py +320 -0
  115. mantisdk/env_var.py +156 -0
  116. mantisdk/execution/__init__.py +15 -0
  117. mantisdk/execution/base.py +64 -0
  118. mantisdk/execution/client_server.py +443 -0
  119. mantisdk/execution/events.py +69 -0
  120. mantisdk/execution/inter_process.py +16 -0
  121. mantisdk/execution/shared_memory.py +282 -0
  122. mantisdk/instrumentation/__init__.py +119 -0
  123. mantisdk/instrumentation/agentops.py +314 -0
  124. mantisdk/instrumentation/agentops_langchain.py +45 -0
  125. mantisdk/instrumentation/litellm.py +83 -0
  126. mantisdk/instrumentation/vllm.py +81 -0
  127. mantisdk/instrumentation/weave.py +500 -0
  128. mantisdk/litagent/__init__.py +11 -0
  129. mantisdk/litagent/decorator.py +536 -0
  130. mantisdk/litagent/litagent.py +252 -0
  131. mantisdk/llm_proxy.py +1890 -0
  132. mantisdk/logging.py +370 -0
  133. mantisdk/reward.py +7 -0
  134. mantisdk/runner/__init__.py +11 -0
  135. mantisdk/runner/agent.py +845 -0
  136. mantisdk/runner/base.py +182 -0
  137. mantisdk/runner/legacy.py +309 -0
  138. mantisdk/semconv.py +170 -0
  139. mantisdk/server.py +401 -0
  140. mantisdk/store/__init__.py +23 -0
  141. mantisdk/store/base.py +897 -0
  142. mantisdk/store/client_server.py +2092 -0
  143. mantisdk/store/collection/__init__.py +30 -0
  144. mantisdk/store/collection/base.py +587 -0
  145. mantisdk/store/collection/memory.py +970 -0
  146. mantisdk/store/collection/mongo.py +1412 -0
  147. mantisdk/store/collection_based.py +1823 -0
  148. mantisdk/store/insight.py +648 -0
  149. mantisdk/store/listener.py +58 -0
  150. mantisdk/store/memory.py +396 -0
  151. mantisdk/store/mongo.py +165 -0
  152. mantisdk/store/sqlite.py +3 -0
  153. mantisdk/store/threading.py +357 -0
  154. mantisdk/store/utils.py +142 -0
  155. mantisdk/tracer/__init__.py +16 -0
  156. mantisdk/tracer/agentops.py +242 -0
  157. mantisdk/tracer/base.py +287 -0
  158. mantisdk/tracer/dummy.py +106 -0
  159. mantisdk/tracer/otel.py +555 -0
  160. mantisdk/tracer/weave.py +677 -0
  161. mantisdk/trainer/__init__.py +6 -0
  162. mantisdk/trainer/init_utils.py +263 -0
  163. mantisdk/trainer/legacy.py +367 -0
  164. mantisdk/trainer/registry.py +12 -0
  165. mantisdk/trainer/trainer.py +618 -0
  166. mantisdk/types/__init__.py +6 -0
  167. mantisdk/types/core.py +553 -0
  168. mantisdk/types/resources.py +204 -0
  169. mantisdk/types/tracer.py +515 -0
  170. mantisdk/types/tracing.py +218 -0
  171. mantisdk/utils/__init__.py +1 -0
  172. mantisdk/utils/id.py +18 -0
  173. mantisdk/utils/metrics.py +1025 -0
  174. mantisdk/utils/otel.py +578 -0
  175. mantisdk/utils/otlp.py +536 -0
  176. mantisdk/utils/server_launcher.py +1045 -0
  177. mantisdk/utils/system_snapshot.py +81 -0
  178. mantisdk/verl/__init__.py +8 -0
  179. mantisdk/verl/__main__.py +6 -0
  180. mantisdk/verl/async_server.py +46 -0
  181. mantisdk/verl/config.yaml +27 -0
  182. mantisdk/verl/daemon.py +1154 -0
  183. mantisdk/verl/dataset.py +44 -0
  184. mantisdk/verl/entrypoint.py +248 -0
  185. mantisdk/verl/trainer.py +549 -0
  186. mantisdk-0.1.0.dist-info/METADATA +119 -0
  187. mantisdk-0.1.0.dist-info/RECORD +190 -0
  188. mantisdk-0.1.0.dist-info/WHEEL +4 -0
  189. mantisdk-0.1.0.dist-info/entry_points.txt +2 -0
  190. mantisdk-0.1.0.dist-info/licenses/LICENSE +19 -0
@@ -0,0 +1,613 @@
1
+ # GEPA Generic RAG Adapter Guide
2
+
3
+ This guide demonstrates how to use GEPA's Generic RAG Adapter with the new **unified `rag_optimization.py`** script that supports multiple vector stores. This consolidated approach makes it easy to test and compare different vector databases with a single command.
4
+
5
+ ## 🆕 Unified Script: `rag_optimization.py`
6
+
7
+ **One script, multiple vector stores!** We've consolidated all individual optimization scripts into a single, powerful `rag_optimization.py` that supports all vector stores through command-line arguments.
8
+
9
+ ### 📂 Supported Vector Stores
10
+
11
+ | Vector Store | Docker Required | Key Features | Usage |
12
+ |--------------|----------------|--------------|--------|
13
+ | **ChromaDB** (default) | ❌ No | Local storage, simple setup, semantic search | `--vector-store chromadb` |
14
+ | **LanceDB** | ❌ No | Serverless, columnar format, developer-friendly | `--vector-store lancedb` |
15
+ | **Milvus** | ❌ No* | Cloud-native, scalable, Milvus Lite for local dev | `--vector-store milvus` |
16
+ | **Qdrant** | ❌ No* | Advanced filtering, payload search, high performance | `--vector-store qdrant` |
17
+ | **Weaviate** | ✅ Yes | Hybrid search, production-ready, advanced features | `--vector-store weaviate` |
18
+
19
+ *Docker optional for production deployments
20
+
21
+ ### ✨ Benefits of the Unified Approach
22
+
23
+ - **🔄 Easy Switching**: Test different vector stores with just a flag change
24
+ - **🔧 Consistent Interface**: Same commands work across all databases
25
+ - **📊 Fair Comparison**: Identical test conditions for comparing performance
26
+ - **🛠 Less Maintenance**: Single file to maintain instead of 5 separate scripts
27
+
28
+ ## 🚀 Quick Start Guide
29
+
30
+ ### Prerequisites
31
+
32
+ 1. **Install Dependencies:**
33
+
34
+ **Install GEPA Core:**
35
+ ```bash
36
+ pip install gepa
37
+ ```
38
+
39
+ **Install RAG Adapter Dependencies:**
40
+
41
+ You can either install all vector store dependencies or specific ones:
42
+
43
+ ```bash
44
+ # Option A: Install all dependencies (recommended for exploration)
45
+ pip install -r requirements-rag.txt
46
+
47
+ # Option B: Install specific vector store dependencies
48
+ # ChromaDB (easiest to start with)
49
+ pip install litellm chromadb
50
+
51
+ # LanceDB (serverless, no Docker needed)
52
+ pip install litellm lancedb pyarrow
53
+
54
+ # Milvus (local Lite mode)
55
+ pip install litellm pymilvus
56
+
57
+ # Qdrant (in-memory mode)
58
+ pip install litellm qdrant-client
59
+
60
+ # Weaviate (requires Docker)
61
+ pip install litellm weaviate-client
62
+ ```
63
+
64
+ **Note:** Vector store dependencies are now separate from the core GEPA package and must be installed manually based on which vector stores you want to use. For specific version requirements, see `requirements-rag.txt`.
65
+
66
+ 2. **For Local Models (Ollama):**
67
+ ```bash
68
+ # Install Ollama
69
+ curl -fsSL https://ollama.com/install.sh | sh
70
+
71
+ # Pull models used in examples
72
+ ollama pull qwen3:8b
73
+ ollama pull llama3.1:8b
74
+ ollama pull nomic-embed-text:latest
75
+ ```
76
+
77
+ 3. **For Cloud Models:**
78
+ ```bash
79
+ export OPENAI_API_KEY="your-api-key"
80
+ export ANTHROPIC_API_KEY="your-api-key"
81
+ ```
82
+
83
+ 4. **Docker Requirements:**
84
+
85
+ | Database | Docker Required | Notes |
86
+ |----------|----------------|-------|
87
+ | **ChromaDB** | ❌ No | Runs locally, no external services |
88
+ | **LanceDB** | ❌ No | Serverless, creates local files |
89
+ | **Milvus** | ❌ No (default) | Uses Milvus Lite (local SQLite) |
90
+ | **Qdrant** | ❌ No (default) | Uses in-memory mode by default |
91
+ | **Weaviate** | ✅ Yes | Requires Docker or cloud instance |
92
+
93
+ **Docker Setup (only for Weaviate):**
94
+ ```bash
95
+ # Start Weaviate with Docker
96
+ docker run -p 8080:8080 -p 50051:50051 cr.weaviate.io/semitechnologies/weaviate:1.26.1
97
+ ```
98
+
99
+ **Optional Docker Setup:**
100
+ ```bash
101
+ # For production Milvus (optional)
102
+ docker run -d -p 19530:19530 milvusdb/milvus:latest standalone
103
+
104
+ # For production Qdrant (optional)
105
+ docker run -p 6333:6333 qdrant/qdrant
106
+ ```
107
+
108
+ ## 🚀 Using the Unified RAG Optimization Script
109
+
110
+ ### Basic Usage
111
+
112
+ ```bash
113
+ # Navigate to the examples directory
114
+ cd src/gepa/examples/rag_adapter
115
+
116
+ # 🔵 ChromaDB (Default - No Docker Required)
117
+ python rag_optimization.py --vector-store chromadb
118
+
119
+ # 🟢 LanceDB (Serverless - No Docker Required)
120
+ python rag_optimization.py --vector-store lancedb
121
+
122
+ # 🔵 Milvus (Local Lite Mode - No Docker Required)
123
+ python rag_optimization.py --vector-store milvus
124
+
125
+ # 🟡 Qdrant (In-Memory - No Docker Required)
126
+ python rag_optimization.py --vector-store qdrant
127
+
128
+ # 🟠 Weaviate (Requires Docker)
129
+ python rag_optimization.py --vector-store weaviate
130
+ ```
131
+
132
+ ### Quick Test (No Optimization)
133
+
134
+ ```bash
135
+ # Test setup without running full optimization
136
+ python rag_optimization.py --vector-store chromadb --max-iterations 0
137
+ python rag_optimization.py --vector-store lancedb --max-iterations 0
138
+ python rag_optimization.py --vector-store qdrant --max-iterations 0
139
+ ```
140
+
141
+ ### Full Optimization Runs
142
+
143
+ ```bash
144
+ # ChromaDB with 10 iterations
145
+ python rag_optimization.py --vector-store chromadb --max-iterations 10
146
+
147
+ # LanceDB with 20 iterations
148
+ python rag_optimization.py --vector-store lancedb --max-iterations 20
149
+
150
+ # Qdrant with 15 iterations
151
+ python rag_optimization.py --vector-store qdrant --max-iterations 15
152
+ ```
153
+
154
+ ### Different Models
155
+
156
+ ```bash
157
+ # Use different Ollama models
158
+ python rag_optimization.py --vector-store chromadb --model ollama/llama3.1:8b
159
+
160
+ # Use cloud models (requires API key)
161
+ python rag_optimization.py --vector-store lancedb --model gpt-4o-mini --max-iterations 10
162
+
163
+ # Use Anthropic models
164
+ python rag_optimization.py --vector-store qdrant --model claude-3-haiku-20240307
165
+ ```
166
+
167
+
168
+ ## 📋 Vector Store Specific Instructions
169
+
170
+ ### 🔵 ChromaDB (Default & Easiest)
171
+
172
+ ChromaDB is perfect for getting started - lightweight, runs locally, no external services needed.
173
+
174
+ **✅ No Docker Required**
175
+
176
+ ```bash
177
+ # Basic usage (default vector store)
178
+ python rag_optimization.py --vector-store chromadb
179
+
180
+ # Or simply (chromadb is the default)
181
+ python rag_optimization.py
182
+
183
+ # Quick test
184
+ python rag_optimization.py --max-iterations 0
185
+
186
+ # Full optimization run
187
+ python rag_optimization.py --max-iterations 20
188
+ ```
189
+
190
+ **Key Features:**
191
+ - Local persistent storage
192
+ - Simple setup with no configuration
193
+ - Semantic similarity search
194
+ - Built-in embedding functions
195
+
196
+
197
+ ### 🟢 LanceDB (Serverless & Developer-Friendly)
198
+
199
+ LanceDB is a serverless vector database built on the Lance columnar format, perfect for local development.
200
+
201
+ **✅ No Docker Required**
202
+
203
+ ```bash
204
+ # Basic usage
205
+ python rag_optimization.py --vector-store lancedb
206
+
207
+ # With different models
208
+ python rag_optimization.py --vector-store lancedb --model ollama/qwen3:8b
209
+
210
+ # Full optimization run
211
+ python rag_optimization.py --vector-store lancedb --max-iterations 20
212
+ ```
213
+
214
+ **Key Features:**
215
+ - Serverless architecture (no external services)
216
+ - Built on Apache Arrow/Lance for performance
217
+ - Creates local database files (./lancedb_demo)
218
+ - Developer-friendly with simple setup
219
+
220
+
221
+ ### 🔵 Milvus (Cloud-Native & Scalable)
222
+
223
+ Milvus is a cloud-native vector database designed for large-scale AI applications. Uses Milvus Lite for local development.
224
+
225
+ **✅ No Docker Required (uses Milvus Lite locally)**
226
+
227
+ ```bash
228
+ # Basic usage (uses local SQLite-based Milvus Lite)
229
+ python rag_optimization.py --vector-store milvus
230
+
231
+ # With different models
232
+ python rag_optimization.py --vector-store milvus --model gpt-4o-mini --max-iterations 10
233
+
234
+ # Full optimization run
235
+ python rag_optimization.py --vector-store milvus --max-iterations 15
236
+ ```
237
+
238
+ **Key Features:**
239
+ - Milvus Lite (local SQLite, no Docker needed)
240
+ - Creates local ./milvus_demo.db file automatically
241
+ - Cloud-native design for production scaling
242
+ - Advanced indexing and search capabilities
243
+
244
+
245
+ ### 🟡 Qdrant (High-Performance & Advanced Filtering)
246
+
247
+ Qdrant is a high-performance vector database with advanced filtering and payload search capabilities.
248
+
249
+ **✅ No Docker Required (uses in-memory mode by default)**
250
+
251
+ ```bash
252
+ # Basic usage (in-memory mode)
253
+ python rag_optimization.py --vector-store qdrant
254
+
255
+ # With different models
256
+ python rag_optimization.py --vector-store qdrant --model gpt-4o-mini --max-iterations 10
257
+
258
+ # Full optimization run
259
+ python rag_optimization.py --vector-store qdrant --max-iterations 15
260
+ ```
261
+
262
+ **Key Features:**
263
+ - In-memory mode (no external services needed)
264
+ - Advanced metadata filtering capabilities
265
+ - Payload search (vector + metadata combined)
266
+ - High-performance optimized for speed and scale
267
+ - Optional persistent storage or remote server
268
+
269
+
270
+ ### 🟠 Weaviate (Hybrid Search)
271
+
272
+ Weaviate offers advanced features like hybrid search (semantic + keyword) and is production-ready.
273
+
274
+ **⚠️ Docker Required**
275
+
276
+ ```bash
277
+ # Setup: Start Weaviate with Docker (required)
278
+ docker run -p 8080:8080 -p 50051:50051 cr.weaviate.io/semitechnologies/weaviate:1.26.1
279
+
280
+ # Verify Weaviate is running
281
+ curl http://localhost:8080/v1/meta
282
+
283
+ # Basic usage (requires Docker setup above)
284
+ python rag_optimization.py --vector-store weaviate
285
+
286
+ # With cloud models
287
+ python rag_optimization.py --vector-store weaviate --model gpt-4o-mini --max-iterations 10
288
+
289
+ # Full optimization run
290
+ python rag_optimization.py --vector-store weaviate --max-iterations 15
291
+ ```
292
+
293
+ **Key Features:**
294
+ - Hybrid search (semantic + keyword/BM25 combined)
295
+ - Production-ready with clustering support
296
+ - Rich GraphQL and RESTful APIs
297
+ - Advanced schema management
298
+ - Built-in vectorization modules
299
+
300
+
301
+ ## ⚙️ Configuration Options
302
+
303
+ ### Command Line Arguments
304
+
305
+ The unified `rag_optimization.py` script supports these arguments:
306
+
307
+ | Argument | Default | Description |
308
+ |----------|---------|-------------|
309
+ | `--vector-store` | `chromadb` | Choose vector store: `chromadb`, `lancedb`, `milvus`, `qdrant`, `weaviate` |
310
+ | `--model` | `ollama/qwen3:8b` | LLM model to use for generation |
311
+ | `--embedding-model` | `ollama/nomic-embed-text:latest` | Embedding model for vector search |
312
+ | `--max-iterations` | `5` | GEPA optimization iterations (use 0 to skip optimization) |
313
+ | `--verbose` | `False` | Enable detailed logging and debugging |
314
+
315
+ ### Complete Help
316
+
317
+ ```bash
318
+ # See all available options
319
+ python rag_optimization.py --help
320
+ ```
321
+
322
+ ### Vector Store Selection
323
+
324
+ ```bash
325
+ # Available vector stores (choose one)
326
+ --vector-store chromadb # Default: Local, no Docker
327
+ --vector-store lancedb # Serverless, no Docker
328
+ --vector-store milvus # Local Lite mode, no Docker
329
+ --vector-store qdrant # In-memory mode, no Docker
330
+ --vector-store weaviate # Requires Docker
331
+ ```
332
+
333
+ ### Model Recommendations
334
+
335
+ | Model | Size | Speed | Quality | Use Case |
336
+ |-------|------|-------|---------|----------|
337
+ | `ollama/qwen3:8b` | Large | Medium | Excellent | Default for ChromaDB/Weaviate/Qdrant |
338
+ | `ollama/llama3.1:8b` | Large | Medium | Excellent | Default for LanceDB/Milvus |
339
+ | `gpt-4o-mini` | Cloud | Fast | Excellent | Production (cloud) |
340
+ | `claude-3-haiku-20240307` | Cloud | Fast | Excellent | Production (cloud) |
341
+
342
+ ### Embedding Models
343
+
344
+ | Model | Provider | Use Case |
345
+ |-------|----------|----------|
346
+ | `ollama/nomic-embed-text:latest` | Local | Offline, privacy |
347
+ | `text-embedding-3-small` | OpenAI | Fast, cost-effective |
348
+ | `text-embedding-3-large` | OpenAI | High quality |
349
+
350
+ ## 🧪 Testing Your Setup
351
+
352
+ ### Quick Health Check
353
+
354
+ ```bash
355
+ # Test all vector stores (no optimization, just setup verification)
356
+ python rag_optimization.py --vector-store chromadb --max-iterations 0
357
+ python rag_optimization.py --vector-store lancedb --max-iterations 0
358
+ python rag_optimization.py --vector-store milvus --max-iterations 0
359
+ python rag_optimization.py --vector-store qdrant --max-iterations 0
360
+ python rag_optimization.py --vector-store weaviate --max-iterations 0 # Requires Docker
361
+
362
+ # Test external services (if using)
363
+ curl http://localhost:8080/v1/meta # Weaviate (if using Docker)
364
+ ollama list # Check available Ollama models
365
+ ```
366
+
367
+ ### Compare Vector Stores
368
+
369
+ ```bash
370
+ # Run same optimization across all vector stores for comparison
371
+ python rag_optimization.py --vector-store chromadb --max-iterations 5
372
+ python rag_optimization.py --vector-store lancedb --max-iterations 5
373
+ python rag_optimization.py --vector-store milvus --max-iterations 5
374
+ python rag_optimization.py --vector-store qdrant --max-iterations 5
375
+ ```
376
+
377
+ ## 🔧 Troubleshooting
378
+
379
+ ### Common Issues
380
+
381
+ #### Import Errors
382
+ ```bash
383
+ # Make sure you're in the right directory
384
+ cd /path/to/gepa/src/gepa/examples/rag_adapter
385
+ python rag_optimization.py --vector-store chromadb
386
+
387
+ # If you get import errors, install missing dependencies using requirements-rag.txt
388
+ pip install -r requirements-rag.txt
389
+
390
+ # Or install specific vector store dependencies:
391
+ pip install litellm chromadb # For ChromaDB
392
+ pip install litellm lancedb pyarrow # For LanceDB
393
+ pip install litellm pymilvus # For Milvus
394
+ pip install litellm qdrant-client # For Qdrant
395
+ pip install litellm weaviate-client # For Weaviate
396
+ ```
397
+
398
+ #### Ollama Issues
399
+ ```bash
400
+ # Check Ollama is running
401
+ ollama list
402
+
403
+ # Pull required models
404
+ ollama pull qwen3:8b
405
+ ollama pull llama3.1:8b
406
+ ollama pull nomic-embed-text:latest
407
+
408
+ # Test models
409
+ ollama run qwen3:8b "Hello"
410
+ ollama run llama3.1:8b "Hello"
411
+ ```
412
+
413
+ #### Weaviate Issues
414
+ ```bash
415
+ # Check Weaviate is accessible
416
+ curl http://localhost:8080/v1/meta
417
+
418
+ # Start Weaviate with Docker
419
+ docker run -d -p 8080:8080 -p 50051:50051 cr.weaviate.io/semitechnologies/weaviate:1.26.1
420
+
421
+ # Check Docker container
422
+ docker ps
423
+ ```
424
+
425
+ #### LanceDB Issues
426
+ ```bash
427
+ # Check LanceDB installation
428
+ python -c "import lancedb; print('LanceDB installed')"
429
+
430
+ # Check PyArrow installation
431
+ python -c "import pyarrow; print('PyArrow installed')"
432
+
433
+ # Install missing dependencies
434
+ pip install litellm lancedb pyarrow
435
+
436
+ # Check sentence-transformers for embeddings
437
+ python -c "import sentence_transformers; print('sentence-transformers installed')"
438
+ pip install sentence-transformers
439
+ ```
440
+
441
+ #### Milvus Issues
442
+ ```bash
443
+ # Check Milvus Lite installation
444
+ python -c "import pymilvus; print('PyMilvus installed')"
445
+
446
+ # Install missing dependencies
447
+ pip install litellm pymilvus
448
+
449
+ # Check if milvus_demo.db file exists
450
+ ls -la milvus_demo.db
451
+
452
+ # For full Milvus server issues
453
+ docker run -d -p 19530:19530 milvusdb/milvus:latest standalone
454
+ curl http://localhost:19530/health
455
+ ```
456
+
457
+ #### Qdrant Issues
458
+ ```bash
459
+ # Check Qdrant client installation
460
+ python -c "import qdrant_client; print('Qdrant client installed')"
461
+
462
+ # Install missing dependencies
463
+ pip install litellm qdrant-client
464
+
465
+ # Test Qdrant server connection
466
+ curl http://localhost:6333/health
467
+
468
+ # Start Qdrant with Docker
469
+ docker run -p 6333:6333 qdrant/qdrant
470
+
471
+ # Check Qdrant container
472
+ docker ps | grep qdrant
473
+ ```
474
+
475
+
476
+ #### Memory Issues
477
+ ```bash
478
+ # Use cloud model instead of local
479
+ python rag_optimization.py --vector-store chromadb --model gpt-4o-mini
480
+
481
+ # Reduce iterations
482
+ python rag_optimization.py --vector-store chromadb --max-iterations 2
483
+
484
+ # Test without optimization first
485
+ python rag_optimization.py --vector-store chromadb --max-iterations 0
486
+ ```
487
+
488
+ #### Vector Store Specific Issues
489
+
490
+ ```bash
491
+ # ChromaDB - No common issues, very stable
492
+
493
+ # LanceDB - Check PyArrow installation
494
+ python -c "import pyarrow; print('PyArrow OK')"
495
+ pip install litellm lancedb pyarrow
496
+
497
+ # Milvus - Check PyMilvus installation
498
+ python -c "import pymilvus; print('PyMilvus OK')"
499
+ pip install litellm pymilvus
500
+
501
+ # Qdrant - Check client installation
502
+ python -c "import qdrant_client; print('Qdrant client OK')"
503
+ pip install litellm qdrant-client
504
+
505
+ # Weaviate - Ensure Docker is running
506
+ curl http://localhost:8080/v1/meta
507
+ docker run -p 8080:8080 -p 50051:50051 cr.weaviate.io/semitechnologies/weaviate:1.26.1
508
+ ```
509
+
510
+ ### Getting Help
511
+
512
+ If you encounter issues:
513
+
514
+ 1. **Check Prerequisites**: Ensure all dependencies are installed
515
+ 2. **Start Simple**: Use `--max-iterations 0` to test setup without optimization
516
+ 3. **Use Cloud Models**: Try `gpt-4o-mini` for faster testing with less memory
517
+ 4. **Enable Verbose Mode**: Add `--verbose` for detailed error information
518
+ 5. **Check Resources**: Ensure sufficient memory and disk space
519
+
520
+ ## 📈 Understanding Results
521
+
522
+ ### Evaluation Metrics
523
+
524
+ - **Retrieval Quality**: How well relevant documents are retrieved
525
+ - **Generation Quality**: How accurate and helpful the generated answers are
526
+ - **Combined Score**: Weighted combination optimized by GEPA (higher is better)
527
+
528
+ ### Optimization Process
529
+
530
+ GEPA uses evolutionary search to improve prompts:
531
+
532
+ 1. **Baseline**: Test initial prompts
533
+ 2. **Mutation**: Generate variations of prompts
534
+ 3. **Selection**: Keep best performing versions
535
+ 4. **Iteration**: Repeat until convergence or max iterations
536
+
537
+ ### Expected Improvements
538
+
539
+ Typical score improvements with GEPA:
540
+ - **Initial Score**: 0.3-0.5 (basic prompts)
541
+ - **After Optimization**: 0.6-0.8 (optimized prompts)
542
+ - **Improvement Range**: +0.1 to +0.4 points
543
+
544
+ ## 🎯 Next Steps
545
+
546
+ 1. **Scale Up**: Use larger models and more iterations for production
547
+ 2. **Custom Data**: Replace example data with your domain-specific knowledge
548
+ 3. **Advanced Features**: Explore metadata filtering and custom prompts
549
+ 4. **Production Setup**: Configure persistent storage and monitoring
550
+ 5. **Integration**: Incorporate optimized prompts into your applications
551
+
552
+ ---
553
+
554
+ ## 📊 Real Optimization Results
555
+
556
+ ### 🔬 ChromaDB + GEPA Optimization Example
557
+
558
+ **Configuration:**
559
+ - **Vector Database**: ChromaDB (Local, No Docker)
560
+ - **LLM Model**: Ollama Qwen3:8b (Local)
561
+ - **Embedding Model**: Ollama nomic-embed-text:latest
562
+ - **Max Iterations**: 10
563
+ - **Knowledge Base**: 6 AI/ML articles
564
+ - **Training Examples**: 3
565
+ - **Validation Examples**: 2
566
+ - **Search Strategy**: Semantic similarity search
567
+
568
+ **Performance Results:**
569
+
570
+ | Metric | Initial Score | Final Score | Improvement | Total Iterations |
571
+ |--------|---------------|-------------|-------------|-----------------|
572
+ | **Validation Score** | 0.388 | 0.388 | **+0.014** | 14 iterations |
573
+ | **Training Score** | 0.374 | - | **+3.7%** | - |
574
+
575
+ **Setup Commands:**
576
+ ```bash
577
+ # No Docker required for ChromaDB!
578
+ # Run optimization directly with unified script
579
+ PYTHONPATH=src python src/gepa/examples/rag_adapter/rag_optimization.py \
580
+ --vector-store chromadb \
581
+ --max-iterations 10 \
582
+ --model ollama/qwen3:8b \
583
+ --verbose
584
+ ```
585
+
586
+ **Key Observations:**
587
+ - ✅ **Successful improvement**: +0.014 score increase (+3.7% improvement)
588
+ - ChromaDB's simple setup makes it ideal for quick optimization experiments
589
+ - Local Ollama models integrated seamlessly with GEPA
590
+ - Semantic similarity search provided good retrieval quality
591
+ - GEPA's evolutionary optimization found better prompt variants
592
+
593
+ **Sample Output Evolution:**
594
+
595
+ *Initial Answer (0.374 score):*
596
+ ```
597
+ ### Answer:
598
+ Computer vision is a field of artificial intelligence (AI) focused on enabling computers to interpret and understand the visual world. It leverages digital images and videos as input and employs deep learning models—a subset of machine learning—to analyze and classify visual data...
599
+ ```
600
+
601
+ *Optimized Answer (0.388 score):*
602
+ ```
603
+ **Answer:**
604
+ Computer vision is a field of artificial intelligence (AI) focused on enabling computers to interpret and understand the visual world. It leverages **digital images and videos** as input and employs **deep learning models**—a subset of machine learning—to analyze and classify visual data. These models, inspired by biological neural networks, excel at processing **unstructured or unlabeled data**...
605
+ ```
606
+
607
+ **Improvement Analysis:**
608
+ - Better formatting with bold headings and key terms
609
+ - More structured presentation of technical concepts
610
+ - Enhanced readability through strategic emphasis
611
+ - Maintained technical accuracy while improving clarity
612
+
613
+ ---
@@ -0,0 +1,9 @@
1
+ # Copyright (c) 2025 Lakshya A Agrawal and the GEPA contributors
2
+ # https://github.com/gepa-ai/gepa
3
+
4
+ """
5
+ GEPA Generic RAG Adapter Examples
6
+
7
+ This package contains examples demonstrating how to use GEPA's Generic RAG Adapter
8
+ with different vector stores and both local and cloud-based language models.
9
+ """