langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
95.74k stars 15.55k forks source link

embeddings:AttributeError: 'tuple' object has no attribute 'embed_documents' #27499

Open Hikizzz opened 1 month ago

Hikizzz commented 1 month ago

Checked other resources

Example Code

embeddings=HuggingFaceBgeEmbeddings(model_name="BAAI/bge-m3"),
vector_a,vector_b = embeddings.embed_documents([text1, text2])

Error Message and Stack Trace (if applicable)

Traceback (most recent call last): File "/home/HwHiAiUser/aircasLLM/src/langchain/toolkit.py", line 126, in print(textSimChain.invoke({ File "/usr/local/miniconda3/envs/dg/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 4713, in invoke return self._call_with_config( File "/usr/local/miniconda3/envs/dg/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1927, in _call_with_config context.run( File "/usr/local/miniconda3/envs/dg/lib/python3.10/site-packages/langchain_core/runnables/config.py", line 396, in call_func_withvariable return func(input, kwargs) # type: ignore[call-arg] File "/usr/local/miniconda3/envs/dg/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 4567, in _invoke output = call_func_with_variable_args( File "/usr/local/miniconda3/envs/dg/lib/python3.10/site-packages/langchain_core/runnables/config.py", line 396, in call_func_withvariable return func(input, kwargs) # type: ignore[call-arg] File "/home/HwHiAiUser/aircasLLM/src/langchain/toolkit.py", line 73, in textSimChain vector_a,vector_b = embeddings.embed_documents([text1, text2]) AttributeError: 'tuple' object has no attribute 'embed_documents'

Description

System Info

System Information

OS: Linux OS Version: #1 SMP Sun Jun 28 14:27:40 CST 2020 Python Version: 3.10.15 (main, Oct 3 2024, 07:21:53) [GCC 11.2.0]

Package Information

langchain_core: 0.3.12 langchain: 0.3.4 langchain_community: 0.3.3 langsmith: 0.1.136 langchain_chroma: 0.1.2 langchain_huggingface: 0.0.3 langchain_ollama: 0.1.1 langchain_openai: 0.1.19 langchain_text_splitters: 0.3.0 langserve: 0.2.2

Optional packages not installed

langgraph

Other Dependencies

aiohttp: 3.10.10 async-timeout: 4.0.3 chromadb: 0.5.15 dataclasses-json: 0.6.7 fastapi: 0.115.2 httpx: 0.27.2 huggingface-hub: 0.26.0 jsonpatch: 1.33 numpy: 1.26.4 ollama: 0.3.3 openai: 1.52.0 orjson: 3.10.9 packaging: 24.1 pydantic: 2.7.4 pydantic-settings: 2.6.0 pyproject-toml: 0.0.10 PyYAML: 6.0.2 requests: 2.32.3 requests-toolbelt: 1.0.0 sentence-transformers: 2.7.0 SQLAlchemy: 2.0.36 sse-starlette: 1.8.2 tenacity: 8.5.0 tiktoken: 0.8.0 tokenizers: 0.20.1 transformers: 4.45.2 typing-extensions: 4.12.2

isLenk commented 1 month ago

Hello, it appears you have a comma on the first line: embeddings=HuggingFaceBgeEmbeddings(model_name="BAAI/bge-m3"),

class A:
    def embed_documents(self, texts):
        return texts

V=A(),
a,b = V.embed_documents([1,2])

AttributeError: 'tuple' object has no attribute 'embed_documents'

Does the issue persist without it?