{"id":5991,"library":"llama-index-embeddings-huggingface","title":"HuggingFace Embeddings for LlamaIndex","description":"This library integrates HuggingFace embedding models, including Sentence Transformer models, with LlamaIndex. It allows users to create embeddings for documents and queries for retrieval, supporting models like BGE, Mixedbread, Nomic, Jina, and E5. The current version is 0.7.0, and it's part of the LlamaIndex ecosystem, which maintains a regular release cadence for its integration packages.","status":"active","version":"0.7.0","language":"en","source_language":"en","source_url":"https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/embeddings/llama-index-embeddings-huggingface","tags":["llama-index","embeddings","huggingface","nlp","sentence-transformers"],"install":[{"cmd":"pip install llama-index-embeddings-huggingface","lang":"bash","label":"Primary installation"},{"cmd":"pip install sentence-transformers","lang":"bash","label":"Required dependency"}],"dependencies":[{"reason":"Core LlamaIndex framework for integration, specific version range required.","package":"llama-index-core","optional":false},{"reason":"Underlying library for HuggingFace sentence transformer models.","package":"sentence-transformers","optional":false},{"reason":"Required for interacting with Hugging Face Hub, especially with the 'inference' extra.","package":"huggingface-hub","optional":false}],"imports":[{"note":"The class is located within the specific 'huggingface' submodule of `llama_index.embeddings`.","wrong":"from llama_index.embeddings import HuggingFaceEmbedding","symbol":"HuggingFaceEmbedding","correct":"from llama_index.embeddings.huggingface import HuggingFaceEmbedding"}],"quickstart":{"code":"from llama_index.core import Settings\nfrom llama_index.embeddings.huggingface import HuggingFaceEmbedding\n\n# Initialize the HuggingFaceEmbedding model\n# Loads BAAI/bge-small-en-v1.5 with the default torch backend\nembed_model = HuggingFaceEmbedding(model_name=\"BAAI/bge-small-en-v1.5\")\n\n# Option 1: Set as the global embedding model for LlamaIndex\nSettings.embed_model = embed_model\n\n# Option 2: Generate embeddings for text directly\ntext_to_embed = \"Hello World! This is a test sentence.\"\nembeddings = embed_model.get_text_embedding(text_to_embed)\n\nprint(f\"Embeddings length: {len(embeddings)}\")\nprint(f\"First 5 embedding values: {embeddings[:5]}\")","lang":"python","description":"This example demonstrates how to initialize the `HuggingFaceEmbedding` class with a specified model (e.g., 'BAAI/bge-small-en-v1.5') and use it to either set the global embedding model for LlamaIndex or generate embeddings for a single piece of text directly."},"warnings":[{"fix":"Ensure `pip install sentence-transformers` is run in your environment alongside `llama-index-embeddings-huggingface`.","message":"The `sentence-transformers` package is a required peer dependency and must be installed separately. Failing to install it will lead to runtime errors when attempting to use `HuggingFaceEmbedding`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the latest LlamaIndex documentation for `HuggingFaceEmbedding` to use current parameter names and configurations.","message":"Several parameters for `HuggingFaceEmbedding` such as `tokenizer_name`, `pooling`, `model`, and `tokenizer` are marked as deprecated in recent versions. Relying on them may lead to warnings or future breaking changes.","severity":"deprecated","affected_versions":"0.7.0 and greater"},{"fix":"Upgrade your Python environment to version 3.10 or higher.","message":"Python 3.9 is no longer supported. This library explicitly requires Python 3.10 or newer.","severity":"breaking","affected_versions":"0.7.0 and greater"},{"fix":"Install the necessary `sentence-transformers` extras based on your chosen backend (e.g., `pip install 'sentence-transformers[onnx]'`) to enable optimized inference.","message":"For advanced features like ONNX or OpenVINO model inference, additional 'extra' installations for `sentence-transformers` are required (e.g., `pip install sentence-transformers[onnx]` or `pip install sentence-transformers[openvino]`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check the `pyproject.toml` or `setup.py` of `llama-index-embeddings-huggingface` for the exact `llama-index-core` version compatibility and ensure your `llama-index-core` installation aligns with it.","message":"This library has a specific dependency range on `llama-index-core` (e.g., `>=0.13.0,<0.15` as of version 0.7.0). Using an incompatible `llama-index-core` version can lead to unexpected behavior or errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}