Registry /
llm-agents / llama-index-embeddings-langchain
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.940 runs
installs and imports cleanly · install 0.0s · import 4.738s · 302.8MB
glibcpy 3.10–3.940 runs
installs and imports cleanly · install 16.8s · import 4.383s · 374MB
348MB installed
● package 348MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
LangchainEmbedding
✓ from llama_index.embeddings.langchain import LangchainEmbedding
✗ from llama_index import LangchainEmbedding
The `LangchainEmbedding` wrapper is located in a specific submodule, not directly under `llama_index`.
HuggingFaceEmbeddings
✓ from langchain_community.embeddings import HuggingFaceEmbeddings
✗ from langchain.embeddings import HuggingFaceEmbeddings
With recent LangChain refactorings, many common embedding models moved from `langchain.embeddings` to `langchain_community.embeddings`.
This quickstart demonstrates how to integrate a LangChain embedding model, specifically a HuggingFace one, into LlamaIndex. It involves initializing the LangChain model, wrapping it with `LangchainEmbedding`, and then setting it as the global embedding model for LlamaIndex. This allows any LlamaIndex component (e.g., VectorStoreIndex) to use this embedding model.
import os
from llama_index.embeddings.langchain import LangchainEmbedding
from llama_index.core import Settings
from langchain_community.embeddings import HuggingFaceEmbeddings
# Ensure the necessary LangChain package is installed
# pip install langchain-community
# 1. Initialize a LangChain embedding model
# Using a local model for demonstration, no API key needed
lc_embed_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
# 2. Wrap the LangChain embedding model with LlamaIndex's LangchainEmbedding wrapper
embed_model = LangchainEmbedding(lc_embed_model)
# 3. Set the global embedding model for LlamaIndex
Settings.embed_model = embed_model
# 4. Example usage: get an embedding
text = "This is a test sentence for embedding."
embedding = Settings.embed_model.get_text_embedding(text)
print(f"Embedding length: {len(embedding)}")
print(f"First 10 dimensions of embedding: {embedding[:10]}")
# You can also use it directly without setting global settings
# direct_embedding = embed_model.get_text_embedding("Another sentence.")
# print(f"Direct embedding length: {len(direct_embedding)}")
Debug
Known issues
breakingBoth LlamaIndex and LangChain are rapidly evolving libraries. Import paths and class locations within `langchain` (e.g., moving to `langchain-community`) have changed frequently, leading to `ImportError` or `ModuleNotFoundError` if versions are not compatible or imports are not updated.fixAlways consult the latest official LlamaIndex and LangChain documentation for correct import paths and recommended packages. Pin your library versions carefully in `requirements.txt`.
affects: All versions, especially during major LangChain or LlamaIndex core updates.
gotchaThe `llama-index-embeddings-langchain` package is merely a wrapper. You *must* install the underlying LangChain package that provides the actual embedding model you intend to use (e.g., `langchain-community` for `HuggingFaceEmbeddings`). Not installing this dependency will lead to runtime errors when the wrapped model is initialized.fixEnsure that `langchain` and/or `langchain-community` are installed alongside `llama-index-embeddings-langchain` and any specific dependencies for your chosen LangChain embedding model.
affects: All versions.
gotchaWhen using local HuggingFace embedding models via LangChain, ensure the model weights are downloaded correctly and that there are no network issues if it's the first time using a specific model. Indefinite loading times can indicate a problem with model download.fixCheck network connectivity. For `HuggingFaceEmbeddings`, you might need to pre-download the model or ensure your environment has access to Hugging Face Hub. Increasing verbosity or checking logs for download progress can also help.
affects: All versions using local HuggingFace models.
Errors
Common errors & fixes
ImportError: cannot import name 'LangchainEmbedding' from 'llama_index'
The `LangchainEmbedding` class is not directly available at the top-level `llama_index` package. It resides within the `llama_index.embeddings.langchain` submodule.
fixChange your import statement to `from llama_index.embeddings.langchain import LangchainEmbedding`.
ModuleNotFoundError: No module named 'langchain.embeddings.base'
This error typically means the `langchain` package (or `langchain-community` for newer versions) is not installed or the installed version is incompatible with LlamaIndex's bridge.
fixInstall or update LangChain: `pip install langchain` or `pip install langchain-community`. If the issue persists, try pinning an older, known-compatible version of `langchain` (e.g., `langchain==0.0.153` as seen in older issues) and then gradually upgrade.
AttributeError: 'HuggingFaceEmbeddings' object has no attribute 'aembed_query'
Some underlying LangChain embedding models might not have asynchronous embedding methods implemented, leading to this error when LlamaIndex attempts to use them asynchronously. The `LangchainEmbedding` wrapper handles this by falling back to synchronous calls, but you might see warnings.
fixThis is often handled gracefully by the `LangchainEmbedding` wrapper, falling back to sync. If you strictly require async, ensure your specific LangChain embedding model explicitly supports `aembed_query` and `aembed_documents` methods.
Upgrade
Version history
0.5.0latest on PyPI · released Mar 12, 2026
Audit
Dependencies
llama-index-corerequiredRequired for LlamaIndex's core embedding abstractions.
langchainrequiredProvides the base LangChain embedding models to be wrapped. Often `langchain-community` is specifically needed.
langchain-communityoptionalMany specific LangChain embedding models (e.g., HuggingFaceEmbeddings) are now located in `langchain-community`.