Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OllamaEmbeddings Fails with 404 Error After Migration to langchain_ollama #29571

Open
5 tasks done
weitsung50110 opened this issue Feb 4, 2025 · 0 comments
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@weitsung50110
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain.chains import create_retrieval_chain, create_history_aware_retriever
from langchain_core.prompts import ChatPromptTemplate
from langchain_ollama import OllamaLLM, OllamaEmbeddings
from langchain_community.vectorstores import FAISS
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

# Initialize Ollama LLM with streaming callback
llm = OllamaLLM(
    model='llama3',
    callback_manager=CallbackManager([StreamingStdOutCallbackHandler()])
)

# Initialize Ollama Embeddings
embeddings = OllamaEmbeddings(
    model='llama3'
)

# Create FAISS vector store and retriever
vector = FAISS.from_texts(["You are an AI assistant named Weibert's Angel."], embeddings)
retriever = vector.as_retriever()

# Prompt templates
prompt_search_query = ChatPromptTemplate.from_messages([
    ("user", "{input}"),
    ("user", "Generate a search query based on the previous conversation.")
])

prompt_get_answer = ChatPromptTemplate.from_messages([
    ("system", "Answer the user's question based on the following context:\n\n{context}"),
    ("user", "{input}")
])

# Create retriever and document processing chains
retriever_chain = create_history_aware_retriever(llm, retriever, prompt_search_query)
document_chain = create_stuff_documents_chain(llm, prompt_get_answer)

# Combine into a retrieval chain
retrieval_chain_combine = create_retrieval_chain(retriever_chain, document_chain)

def main():
    """Main function to handle user input and generate responses."""
    print("Welcome to Weibert's Angel Chatbot! Type 'bye' to exit.")

    while True:
        try:
            user_input = input(">>> ").strip()

            if user_input.lower() == "bye":
                print("Goodbye! See you next time!")
                break

            if user_input:
                response = retrieval_chain_combine.invoke({'input': user_input})

                # Store conversation in FAISS
                vector.add_texts([
                    f"User Input: {user_input}",
                    f"AI Response: {response['answer']}"
                ])

                # Output response
                print("--------------------------")
                print(response)
        except Exception as e:
            print(f"Error occurred: {e}")

if __name__ == "__main__":
    main()

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
File "/app/langchain_Conversation_Retrieval_Faiss.py", line 21, in
vector = FAISS.from_texts(["You are an AI assistant named Weibert's Angel."], embeddings)
File "/usr/local/lib/python3.10/dist-packages/langchain_community/vectorstores/faiss.py", line 1041, in from_texts
embeddings = embedding.embed_documents(texts)
File "/usr/local/lib/python3.10/dist-packages/langchain_ollama/embeddings.py", line 237, in embed_documents
embedded_docs = self._client.embed(
File "/usr/local/lib/python3.10/dist-packages/ollama/_client.py", line 356, in embed
return self._request(
File "/usr/local/lib/python3.10/dist-packages/ollama/_client.py", line 177, in _request
return cls(**self._request_raw(*args, **kwargs).json())
File "/usr/local/lib/python3.10/dist-packages/ollama/_client.py", line 122, in _request_raw
raise ResponseError(e.response.text, e.response.status_code) from None
ollama._types.ResponseError: 404 page not found

Description

Previously, I was using OllamaEmbeddings from langchain_community.embeddings, and everything worked fine. However, after migrating to langchain_ollama, I started encountering a 404 page not found error.

It seems that after migrating OllamaEmbeddings from langchain_community.embeddings to langchain_ollama, something broke. Could you confirm if this is a bug or if additional configuration is required?

Thanks!

System Info

System Information

OS: Linux
OS Version: #1 SMP Thu Jan 11 04:09:03 UTC 2024
Python Version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

Package Information

langchain_core: 0.3.33
langchain: 0.3.13
langchain_community: 0.3.8
langsmith: 0.1.147
langchain_Conversation_Retrieval: Installed. No version info available.
langchain_Conversation_Retrieval_Faiss: Installed. No version info available.
langchain_Conversation_Retrieval_chroma: Installed. No version info available.
langchain_agents_STRUCTURED_CHAT: Installed. No version info available.
langchain_agents_STRUCTURED_CHAT2: Installed. No version info available.
langchain_agents_STRUCTURED_CHAT_demo: Installed. No version info available.
langchain_agents_STRUCTURED_CHAT_demo2: Installed. No version info available.
langchain_agents_ZERO_SHOT: Installed. No version info available.
langchain_agents_ZERO_SHOT_langsmith: Installed. No version info available.
langchain_agents_ZERO_SHOT_wiki: Installed. No version info available.
langchain_agents_conversational-react_memory: Installed. No version info available.
langchain_agents_conversational-react_memory-Summary: Installed. No version info available.
langchain_agents_conversational-react_memory-Vector: Installed. No version info available.
langchain_agents_conversational-react_memory2: Installed. No version info available.
langchain_agents_conversational-react_memory3: Installed. No version info available.
langchain_agents_conversational-react_memory3_langsmith: Installed. No version info available.
langchain_json_test: Installed. No version info available.
langchain_ollama: 0.2.3
langchain_pdf_test: Installed. No version info available.
langchain_rag_doc_Faiss: Installed. No version info available.
langchain_rag_doc_chroma: Installed. No version info available.
langchain_rag_json_Faiss: Installed. No version info available.
langchain_rag_pdf_Faiss: Installed. No version info available.
langchain_rag_pdf_chroma: Installed. No version info available.
langchain_rag_textloader_Faiss: Installed. No version info available.
langchain_sqlite: Installed. No version info available.
langchain_sqlite_langsmith: Installed. No version info available.
langchain_sys_SEOtitle_article_generate: Installed. No version info available.
langchain_sys_SEOtitle_article_love: Installed. No version info available.
langchain_sys_SEOtitle_article_post: Installed. No version info available.
langchain_sys_article_loveletter: Installed. No version info available.
langchain_sys_article_novel: Installed. No version info available.
langchain_sys_article_poetry: Installed. No version info available.
langchain_text_splitters: 0.3.4
langchain_tools_YouTube: Installed. No version info available.
langchain_web_Conversation_Faiss: Installed. No version info available.
langchain_web_Conversation_Faiss_langsmith: Installed. No version info available.
langchain_web_Conversation_chroma: Installed. No version info available.
langchain_web_test: Installed. No version info available.
langgraph_sdk: 0.1.48

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.9.5
async-timeout: 4.0.3
dataclasses-json: 0.6.5
httpx: 0.27.0
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
ollama: 0.4.5
orjson: 3.10.1
packaging: 23.2
pydantic: 2.10.4
pydantic-settings: 2.7.1
PyYAML: 6.0.1
requests: 2.31.0
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.29
tenacity: 8.2.3
typing-extensions: 4.12.2

@langcarl langcarl bot added the investigate Flagged for investigation. label Feb 4, 2025
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.
Projects
None yet
Development

No branches or pull requests

1 participant