[Python] ModuleNotFoundError: No module named 'llama_index.embeddings.langchain'

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use LangChain embeddings, using the following code in Google colab:

    These are the installations:

    pip install pypdf
    pip install -q transformers einops accelerate langchain bitsandbytes
    pip install install sentence_transformers
    pip3 install llama-index --upgrade
    pip install llama-index-llms-huggingface
    huggingface-cli login
    pip install -U llama-index-core llama-index-llms-openai llama-index-embeddings-openai




    Then I ran this code in the google colab:

    from llama_index.core import VectorStoreIndex,SimpleDirectoryReader,ServiceContext
    from llama_index.llms.huggingface import HuggingFaceLLM
    from llama_index.core.prompts.prompts import SimpleInputPrompt


    # Reading pdf
    documents=SimpleDirectoryReader("/content/sample_data/Data").load_data()

    #Prompt
    query_wrapper_prompt=SimpleInputPrompt("<|USER|>{query_str}<|ASSISTANT|>")

    import torch
    llm = HuggingFaceLLM(
    context_window=4096,
    max_new_tokens=256,
    generate_kwargs={"temperature": 0.0, "do_sample": False},
    system_prompt=system_prompt,
    query_wrapper_prompt=query_wrapper_prompt,
    tokenizer_name="meta-llama/Llama-2-7b-chat-hf",
    model_name="meta-llama/Llama-2-7b-chat-hf",
    device_map="auto",
    # uncomment this if using CUDA to reduce memory usage
    model_kwargs={"torch_dtype": torch.float16 , "load_in_8bit":True}
    )

    # Embeddings
    from langchain.embeddings.huggingface import HuggingFaceEmbeddings
    from llama_index.core import ServiceContext
    from llama_index.embeddings.langchain import LangchainEmbedding

    embed_model=LangchainEmbedding(
    HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2"))




    Then I got this error: ModuleNotFoundError: No module named 'llama_index.embeddings.langchain'

    I am using latest version of llama-index Version: 0.10.26

    Can someone suggest, how to resolve this error.

    Continue reading...

Compartilhe esta Página