langchain-ai / langchain

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

FastEmbedEmbeddings failing using v0.3.0 #26759

Closed chetanph closed 1 month ago

chetanph commented 1 month ago

Checked other resources

Example Code

from langchain_community.embeddings import FastEmbedEmbeddings
embeddings = FastEmbedEmbeddings()
document_embeddings = embeddings.embed_documents(
    ["This is a document", "This is some other document"]
)
query_embeddings = embeddings.embed_query("This is a query")

Error Message and Stack Trace (if applicable)

Fetching 5 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 137970.53it/s]
Traceback (most recent call last):
  File "/Users/cphulpag/Documents/fastembed_test/test.py", line 8, in <module>
    document_embeddings = embeddings.embed_documents(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cphulpag/Documents/fastembed_test/.venv/lib/python3.11/site-packages/langchain_community/embeddings/fastembed.py", line 117, in embed_documents
    embeddings = self._model.embed(
                 ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'embed'

Description

After upgrading to latest langchain and langchain-community version 0.3.0, basic usage example ofFastEmbedEmbeddings is failing.

System Info

python -m langchain_core.sys_info

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
> Python Version:  3.11.2 (v3.11.2:878ead1ac1, Feb  7 2023, 10:02:41) [Clang 13.0.0 (clang-1300.0.29.30)]

Package Information
-------------------
> langchain_core: 0.3.5
> langchain: 0.3.0
> langchain_community: 0.3.0
> langsmith: 0.1.125
> langchain_text_splitters: 0.3.0

Optional packages not installed
-------------------------------
> langgraph
> langserve

Other Dependencies
------------------
> aiohttp: 3.10.5
> async-timeout: Installed. No version info available.
> dataclasses-json: 0.6.7
> httpx: 0.27.2
> jsonpatch: 1.33
> numpy: 1.26.4
> orjson: 3.10.7
> packaging: 24.1
> pydantic: 2.9.2
> pydantic-settings: 2.5.2
> PyYAML: 6.0.2
> requests: 2.32.3
> SQLAlchemy: 2.0.35
> tenacity: 8.5.0
> typing-extensions: 4.12.2
chetanph commented 1 month ago

This is my workaround for now:

embeddings._model = embeddings.model_dump().get("_model")
ZhangShenao commented 1 month ago

Try to fix this in #26764

chetanph commented 1 month ago

Yes, the fix works as expected. Appreciate the quick response!!

EricZiola commented 1 month ago

Question: I am still experiencing this error (even though the workaround described above by chetanph is working for me).

I'm a little new to the development cycle but has the fix been deployed to production? I am still getting the exact error above having just installed the fastembed package today unless I use the workaround.

ZhangShenao commented 1 month ago

I am waiting for the fixed PR to be merged and released.