{"id":8498,"library":"pymilvus-model","title":"PyMilvus Model Components","description":"PyMilvus Model is a Python library that provides model components, primarily for generating dense and sparse embeddings, intended for use with Milvus. It leverages popular deep learning frameworks like Hugging Face Transformers and Sentence-Transformers to offer a unified interface for various pre-trained models. The current version is 0.3.2, and it typically releases updates as new features or model integrations become available, often in sync with PyMilvus SDK developments.","status":"active","version":"0.3.2","language":"en","source_language":"en","source_url":"https://github.com/milvus-io/pymilvus-model","tags":["vector-database","milvus","embedding","model","nlp","ai"],"install":[{"cmd":"pip install pymilvus-model","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for loading and using embedding models.","package":"sentence-transformers"},{"reason":"Underlying deep learning framework for model execution.","package":"torch"}],"imports":[{"symbol":"DenseEncoder","correct":"from pymilvus_model.dense.encoder import DenseEncoder"},{"symbol":"SparseEncoder","correct":"from pymilvus_model.sparse.encoder import SparseEncoder"},{"symbol":"MultiModalEncoder","correct":"from pymilvus_model.multi_modal.encoder import MultiModalEncoder"}],"quickstart":{"code":"from pymilvus_model.dense.encoder import DenseEncoder\n\n# Initialize a DenseEncoder with a common embedding model\n# Ensure the model name is valid and accessible (e.g., from Hugging Face Model Hub)\nencoder = DenseEncoder(model_name='BAAI/bge-small-en-v1.5', device='cpu') # Change to 'cuda' if GPU available and configured\n\ntexts = [\n    'The quick brown fox jumps over the lazy dog.',\n    'Artificial intelligence is rapidly advancing.',\n    'Milvus is an open-source vector database.'\n]\n\n# Encode documents to get dense embeddings\nembeddings = encoder.encode_documents(texts)\n\nprint(f\"Encoded {len(texts)} texts.\")\nprint(f\"Shape of embeddings: {embeddings.shape}\")\nprint(f\"First embedding (truncated): {embeddings[0][:5]}...\")\n","lang":"python","description":"This quickstart demonstrates how to initialize a `DenseEncoder` and use it to generate embeddings for a list of texts. It uses a popular sentence transformer model. Remember to specify `device='cuda'` if you have a GPU for faster encoding and have PyTorch installed with CUDA support."},"warnings":[{"fix":"Always verify model names on the Hugging Face Model Hub (e.g., `huggingface.co/models`) and ensure they are compatible with `sentence-transformers` or `transformers`' auto-loading mechanisms.","message":"Model names provided to `DenseEncoder` or `SparseEncoder` must correspond to models supported by the underlying `sentence-transformers` or `transformers` library, and be accessible on the Hugging Face Model Hub. Misspelled or unsupported model names will lead to loading errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Initialize encoders with `device='cuda'` if a compatible GPU is available (e.g., `DenseEncoder(model_name='...', device='cuda')`). Ensure `torch` is installed with CUDA support (`pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118` or similar for your CUDA version).","message":"Using large embedding models or encoding many texts can be computationally intensive. By default, `torch` might use the CPU, leading to slow performance. GPU acceleration (CUDA) is highly recommended for production use cases.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pin `pymilvus-model` to a specific version in `requirements.txt` to ensure stability. Review the official GitHub repository for release notes before upgrading to new minor versions.","message":"The `pymilvus_model` library is relatively new (0.x.x) and its API might evolve in future minor versions. While no specific breaking changes are noted yet, expect potential adjustments in argument names or class structures as it matures towards a 1.0 release.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Double-check the model name for typos. Verify network connectivity. Ensure the model exists and is publicly accessible on Hugging Face. Try a simpler, well-known model first like 'sentence-transformers/all-MiniLM-L6-v2' to rule out network/access issues.","cause":"The specified model name is incorrect, inaccessible, or the network connection to Hugging Face Model Hub is unstable.","error":"OSError: BAAI/bge-small-en-v1.5 does not appear to have a file named pytorch_model.bin or tf_model.h5 or flax_model.msgpack. Make sure 'BAAI/bge-small-en-v1.5' is a valid model identifier listed on 'https://huggingface.co/models'."},{"fix":"Ensure `torch` is installed. Run `pip install torch` or, for GPU support, follow specific instructions on `pytorch.org` (e.g., `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118` for CUDA 11.8).","cause":"The underlying `torch` library, a dependency of `sentence-transformers` (which `pymilvus-model` uses), was not installed correctly or is missing from your environment.","error":"ModuleNotFoundError: No module named 'torch'"},{"fix":"If no GPU is available, explicitly use `device='cpu'` when initializing the encoder. If a GPU is available, ensure PyTorch is installed with CUDA support by following the instructions on `pytorch.org/get-started/locally/` carefully for your specific OS and CUDA version.","cause":"Attempting to use `device='cuda'` without a CUDA-enabled GPU or without PyTorch installed with CUDA support (you might have installed the CPU-only version).","error":"RuntimeError: 'cuda' is not available. Make sure you have a CUDA enabled GPU and install the CUDA version of PyTorch."}]}