langchain-ai / langchain

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

from langchain_community.embeddings import HuggingFaceBgeEmbeddings - results warning - pydantic/_internal/_fields.py:132: UserWarning: Field "model_name" in HuggingFaceInferenceAPIEmbeddings has conflict with protected namespace "model_". #26861

Open sam-bercovici opened 6 days ago

sam-bercovici commented 6 days ago

Checked other resources

Example Code

'''from langchain_community.embeddings import HuggingFaceBgeEmbeddings''' generates: pydantic/_internal/_fields.py:132: UserWarning: Field "modelname" in HuggingFaceInferenceAPIEmbeddings has conflict with protected namespace "model".

You may be able to resolve this warning by setting model_config['protected_namespaces'] = (). warnings.warn(

looking at https://github.com/pydantic/pydantic/discussions/7121 and https://github.com/langchain-ai/langchain/blob/a0010063e8534217663fe546e105c69312c8be7a/libs/community/langchain_community/cross_encoders/huggingface.py#L48

similar is missing in HuggingFaceBgeEmbeddings

Error Message and Stack Trace (if applicable)

warning: pydantic/_internal/_fields.py:132: UserWarning: Field "modelname" in HuggingFaceInferenceAPIEmbeddings has conflict with protected namespace "model".

You may be able to resolve this warning by setting model_config['protected_namespaces'] = (). warnings.warn(

Description

System Info

python -m langchain_core.sys_info

System Information

OS: Linux OS Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024 Python Version: 3.12.6 | packaged by conda-forge | (main, Sep 22 2024, 14:16:49) [GCC 13.3.0]

Package Information

langchain_core: 0.3.5 langchain: 0.3.0 langchain_community: 0.3.0 langsmith: 0.1.125 langchain_anthropic: 0.2.1 langchain_chroma: 0.1.4 langchain_experimental: 0.3.0 langchain_groq: 0.2.0 langchain_huggingface: 0.1.0 langchain_openai: 0.2.0 langchain_text_splitters: 0.3.0

Optional packages not installed

langgraph langserve

Other Dependencies

aiohttp: 3.10.5 anthropic: 0.34.2 async-timeout: Installed. No version info available. chromadb: 0.5.7 dataclasses-json: 0.6.7 defusedxml: 0.7.1 fastapi: 0.115.0 groq: 0.11.0 httpx: 0.27.2 huggingface-hub: 0.25.1 jsonpatch: 1.33 numpy: 1.26.4 openai: 1.47.1 orjson: 3.10.7 packaging: 24.1 pydantic: 2.9.2 pydantic-settings: 2.5.2 PyYAML: 6.0.2 requests: 2.32.3 sentence-transformers: 3.1.1 SQLAlchemy: 2.0.35 tenacity: 8.5.0 tiktoken: 0.7.0 tokenizers: 0.19.1 transformers: 4.44.2 typing-extensions: 4.12.2

nehaejaz commented 5 days ago

Having the same warning

etiennemillerioux commented 5 days ago

Face the same warning too, very annoying it's dispaly it upon every single startup

tibor-reiss commented 4 days ago

Fixed in langchain-community 0.3.1 in #26744

MaxRuenz commented 8 hours ago

Is that something that should also be ported to other Embeddings and Chats? I am getting the same warnings when working with Bedrock and langchain-community 0.3.1

sam-bercovici commented 8 hours ago

Why not have a langchain Base Model doing this instead of inheriting from Pydantic and doing this stuff repeatedly?