|
14 | 14 |
|
15 | 15 |
|
16 | 16 | from chromadb.api.collection_configuration import ( |
17 | | - CreateCollectionConfiguration, CreateHNSWConfiguration, UpdateHNSWConfiguration, UpdateCollectionConfiguration |
| 17 | + CreateCollectionConfiguration |
18 | 18 | ) |
19 | 19 | from chromadb.api import EmbeddingFunction |
20 | 20 | from chromadb.utils.embedding_functions import ( |
@@ -80,7 +80,6 @@ def get_chroma_client(args=None): |
80 | 80 |
|
81 | 81 | # Load environment variables from .env file if it exists |
82 | 82 | load_dotenv(dotenv_path=args.dotenv_path) |
83 | | - print(args.dotenv_path) |
84 | 83 | if args.client_type == 'http': |
85 | 84 | if not args.host: |
86 | 85 | raise ValueError("Host must be provided via --host flag or CHROMA_HOST environment variable when using HTTP client") |
@@ -182,57 +181,19 @@ async def chroma_create_collection( |
182 | 181 | collection_name: str, |
183 | 182 | embedding_function_name: str = "default", |
184 | 183 | metadata: Dict | None = None, |
185 | | - space: str | None = None, |
186 | | - ef_construction: int | None = None, |
187 | | - ef_search: int | None = None, |
188 | | - max_neighbors: int | None = None, |
189 | | - num_threads: int | None = None, |
190 | | - batch_size: int | None = None, |
191 | | - sync_threshold: int | None = None, |
192 | | - resize_factor: float | None = None, |
193 | 184 | ) -> str: |
194 | 185 | """Create a new Chroma collection with configurable HNSW parameters. |
195 | 186 | |
196 | 187 | Args: |
197 | 188 | collection_name: Name of the collection to create |
198 | | - space: Distance function used in HNSW index. Options: 'l2', 'ip', 'cosine' |
199 | | - ef_construction: Size of the dynamic candidate list for constructing the HNSW graph |
200 | | - ef_search: Size of the dynamic candidate list for searching the HNSW graph |
201 | | - max_neighbors: Maximum number of neighbors to consider during HNSW graph construction |
202 | | - num_threads: Number of threads to use during HNSW construction |
203 | | - batch_size: Number of elements to batch together during index construction |
204 | | - sync_threshold: Number of elements to process before syncing index to disk |
205 | | - resize_factor: Factor to resize the index by when it's full |
206 | 189 | embedding_function_name: Name of the embedding function to use. Options: 'default', 'cohere', 'openai', 'jina', 'voyageai', 'ollama', 'roboflow' |
207 | 190 | metadata: Optional metadata dict to add to the collection |
208 | 191 | """ |
209 | 192 | client = get_chroma_client() |
210 | | - |
211 | 193 |
|
212 | 194 | embedding_function = mcp_known_embedding_functions[embedding_function_name] |
213 | 195 |
|
214 | | - hnsw_config = CreateHNSWConfiguration() |
215 | | - if space: |
216 | | - hnsw_config["space"] = space |
217 | | - if ef_construction: |
218 | | - hnsw_config["ef_construction"] = ef_construction |
219 | | - if ef_search: |
220 | | - hnsw_config["ef_search"] = ef_search |
221 | | - if max_neighbors: |
222 | | - hnsw_config["max_neighbors"] = max_neighbors |
223 | | - if num_threads: |
224 | | - hnsw_config["num_threads"] = num_threads |
225 | | - if batch_size: |
226 | | - hnsw_config["batch_size"] = batch_size |
227 | | - if sync_threshold: |
228 | | - hnsw_config["sync_threshold"] = sync_threshold |
229 | | - if resize_factor: |
230 | | - hnsw_config["resize_factor"] = resize_factor |
231 | | - |
232 | | - |
233 | | - |
234 | 196 | configuration=CreateCollectionConfiguration( |
235 | | - hnsw=hnsw_config, |
236 | 197 | embedding_function=embedding_function() |
237 | 198 | ) |
238 | 199 |
|
@@ -310,52 +271,24 @@ async def chroma_modify_collection( |
310 | 271 | collection_name: str, |
311 | 272 | new_name: str | None = None, |
312 | 273 | new_metadata: Dict | None = None, |
313 | | - ef_search: int | None = None, |
314 | | - num_threads: int | None = None, |
315 | | - batch_size: int | None = None, |
316 | | - sync_threshold: int | None = None, |
317 | | - resize_factor: float | None = None, |
318 | 274 | ) -> str: |
319 | 275 | """Modify a Chroma collection's name or metadata. |
320 | 276 | |
321 | 277 | Args: |
322 | 278 | collection_name: Name of the collection to modify |
323 | 279 | new_name: Optional new name for the collection |
324 | 280 | new_metadata: Optional new metadata for the collection |
325 | | - ef_search: Size of the dynamic candidate list for searching the HNSW graph |
326 | | - num_threads: Number of threads to use during HNSW construction |
327 | | - batch_size: Number of elements to batch together during index construction |
328 | | - sync_threshold: Number of elements to process before syncing index to disk |
329 | | - resize_factor: Factor to resize the index by when it's full |
330 | 281 | """ |
331 | 282 | client = get_chroma_client() |
332 | 283 | try: |
333 | 284 | collection = client.get_collection(collection_name) |
334 | | - |
335 | | - hnsw_config = UpdateHNSWConfiguration() |
336 | | - if ef_search: |
337 | | - hnsw_config["ef_search"] = ef_search |
338 | | - if num_threads: |
339 | | - hnsw_config["num_threads"] = num_threads |
340 | | - if batch_size: |
341 | | - hnsw_config["batch_size"] = batch_size |
342 | | - if sync_threshold: |
343 | | - hnsw_config["sync_threshold"] = sync_threshold |
344 | | - if resize_factor: |
345 | | - hnsw_config["resize_factor"] = resize_factor |
346 | | - |
347 | | - configuration = UpdateCollectionConfiguration( |
348 | | - hnsw=hnsw_config |
349 | | - ) |
350 | | - collection.modify(name=new_name, configuration=configuration, metadata=new_metadata) |
| 285 | + collection.modify(name=new_name, metadata=new_metadata) |
351 | 286 |
|
352 | 287 | modified_aspects = [] |
353 | 288 | if new_name: |
354 | 289 | modified_aspects.append("name") |
355 | 290 | if new_metadata: |
356 | 291 | modified_aspects.append("metadata") |
357 | | - if ef_search or num_threads or batch_size or sync_threshold or resize_factor: |
358 | | - modified_aspects.append("hnsw") |
359 | 292 |
|
360 | 293 | return f"Successfully modified collection {collection_name}: updated {' and '.join(modified_aspects)}" |
361 | 294 | except Exception as e: |
@@ -662,30 +595,6 @@ def validate_thought_data(input_data: Dict) -> Dict: |
662 | 595 | "branchId": input_data.get("branchId"), |
663 | 596 | "needsMoreThoughts": input_data.get("needsMoreThoughts"), |
664 | 597 | } |
665 | | - |
666 | | -def process_thought(input_data: Dict) -> Dict: |
667 | | - """Process a new thought.""" |
668 | | - try: |
669 | | - # Validate input data |
670 | | - validated_input = validate_thought_data(input_data) |
671 | | - |
672 | | - # Adjust total thoughts if needed |
673 | | - if validated_input["thoughtNumber"] > validated_input["totalThoughts"]: |
674 | | - validated_input["totalThoughts"] = validated_input["thoughtNumber"] |
675 | | - |
676 | | - # Return response |
677 | | - return { |
678 | | - "sessionId": validated_input["sessionId"], |
679 | | - "thoughtNumber": validated_input["thoughtNumber"], |
680 | | - "totalThoughts": validated_input["totalThoughts"], |
681 | | - "nextThoughtNeeded": validated_input["nextThoughtNeeded"], |
682 | | - } |
683 | | - |
684 | | - except Exception as e: |
685 | | - return { |
686 | | - "error": str(e), |
687 | | - "status": "failed" |
688 | | - } |
689 | 598 |
|
690 | 599 | def main(): |
691 | 600 | """Entry point for the Chroma MCP server.""" |
|
0 commit comments