Find answers from the community

Updated 3 months ago

Import

ImportError: cannot import name 'LangchainEmbedding' from 'llama_index.core.base.embeddings'
Is this due to the way imports have been changed?
This is how I'm importing;

Plain Text
py 
from llama_index.core.base.embeddings import LangchainEmbedding

Also tried
Plain Text
py from llama_index.core.embeddings import LangchainEmbedding

But both/all seem to give same issue, so wondering if the LangchainEmbeddings got moved somewhere? I was looking at the doc and couldn't find it.

  1. from llama_index.llms.langchain import LangChainLLM
Is this mainly used for OpenAI/GPT models rather than using anthropic? I noticed that anthropic has their own;
: from llama_index.llms.anthropic import Anthropic
Also has the standard been changed to use llama_index.core. (...) for versions of llama_index .11 and higher?
L
p
22 comments
Oh that's an old import

You need
pip install llama-index-embeddings-langchain

from llama_index.embeddings.langchain import LangChainEmbedding
This change happened in v0.10.x
I'm not sure what you mean by your second point tbh

We have llms and emebddings for nearly everything, I'd be surprised if you needed langchain actually
ah yeah so I'm using anthropic wasn't sure if the langchainLLM if that's it's own LLM? Basically if I wanted to use anthropic as the llm, I'd probably just use llama_index.llms.anthropic import Anthropic and get rid of the LangChainLLM? (Also part of it is because I'm integrating LangChain with llama-index (different uses).
For my purpose I wanted to utilize Langgraph, which I suppose wouldn't actually require langChain, and could be used independenly alongside llama-index?
Basically I was trying to wrap anthropic using the langChainLLM but I suppose that's not even necessary at all.

However, still facing this import issue suprisingly; I can always delete the env and redo the installs to test if that's the issue;

ImportError: cannot import name 'LangChainEmbedding' from 'llama_index.embeddings.langchain'
Did you run the pip install? If so, might need a fresh venv
I did run pip install, also I ran a fresh venv too
tho I'm using poetry for most of the package side of things
Basically doing >> Use conda >> Run venv (for poetry)
Are you in a notebook? You'll have to restart it if so
ah I'm not using a notebook
It seems to work for me πŸ€”
Updating from v0.9.x can be a little annoying. But normally a fresh venv solves it. Unless you have some global install outside a venv
Fair, tho I deleted everything from global install.
so everything should be isolated in side conda and venv, (conda only installs) poetry
langchain-huggingface
flake8
black
but otherwise poetry handles rest of installs
wonder if it's because it's not getting installed properly, maybe that's why. (nvm it isn't, poetry shows it's installed tho separately, not as part of llama-index).

command: poetry show llama-index-embeddings-langchain


name : llama-index-embeddings-langchain
version : 0.2.1
description : llama-index embeddings langchain integration

dependencies
  • llama-index-core >=0.11.0,<0.12.0

command: poetry show llama-index

name : llama-index
version : 0.11.6
description : Interface between LLMs and your data

dependencies
  • llama-index-agent-openai >=0.3.0,<0.4.0
  • llama-index-cli >=0.3.0,<0.4.0
  • llama-index-core >=0.11.6,<0.12.0
  • llama-index-embeddings-openai >=0.2.4,<0.3.0
  • llama-index-indices-managed-llama-cloud >=0.3.0
  • llama-index-legacy >=0.9.48,<0.10.0
  • llama-index-llms-openai >=0.2.2,<0.3.0
  • llama-index-multi-modal-llms-openai >=0.2.0,<0.3.0
  • llama-index-program-openai >=0.2.0,<0.3.0
  • llama-index-question-gen-openai >=0.2.0,<0.3.0
  • llama-index-readers-file >=0.2.0,<0.3.0
  • llama-index-readers-llama-parse >=0.3.0
  • nltk >3.8.1
ended up just getting rid of using the llama-embeddings for now, I think huggingfaceembeddings willwork for now for my test purposes.
that seems correct to me πŸ˜… Just as a sanity check, langchain embeddings and huggingface embeddings both work on google colab
https://colab.research.google.com/drive/11Grso7t3h7oKQjE8TRsyQRolF1mah-o7?usp=sharing

I thiink I lead astray though, its from llama_index.embeddings.langchain import LangchainEmbedding
casing is hard
Awesome, will take a look. Thanks a lot Logan!
Add a reply
Sign up and join the conversation on Discord