pythongoogle-colaboratoryembeddinglangchainllama-index

cannot import name 'LangchainEmbedding' from 'llama_index'


I'm trying to build a simple RAG, and I'm stuck at this code:

from langchain.embeddings.huggingface import HuggingFaceEmbeddings
from llama_index import LangchainEmbedding, ServiceContext

embed_model = LangchainEmbedding(
  HuggingFaceEmbeddings(model_name="thenlper/gte-large")
)
service_context = ServiceContext.from_defaults(
    chunk_size=256,
    llm=llm,
    embed_model=embed_model
)
index = VectorStoreIndex.from_documents(documents, service_context=service_context)

where I get ImportError: cannot import name 'LangchainEmbedding' from 'llama_index' How can I solve? Is it related to the fact that I'm working on Colab?


Solution

  • INFO 2024:

    This answer worked in 2023 when question was asked
    but it seems they moved all code and now you have to use other answers.


    Not

    from llama_index import LangchainEmbedding
    

    but

    from llama_index.embeddings import LangchainEmbedding
    

    (See source code for llama_index/embeddings/__ init__.py)