-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Description
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_openai import ChatOpenAI,OpenAIEmbeddings
embeddings_model = OpenAIEmbeddings(model="bge-embed-text-cpu",base_url="http://localhost:8000/openai/v1",api_key="thisIsIgnored",deployment="bge-embed-text-cpu")
Error Message and Stack Trace (if applicable)
Errors when using embeddings_model.embed_query
embeddings_model.embed_query("test")
Traceback (most recent call last):
File "", line 1, in
File "/lib/python3.11/site-packages/langchain_openai/embeddings/base.py", line 629, in embed_query
return self.embed_documents([text])[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/langchain_openai/embeddings/base.py", line 588, in embed_documents
return self._get_len_safe_embeddings(texts, engine=engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/langchain_openai/embeddings/base.py", line 483, in _get_len_safe_embeddings
response = self.client.create(
^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/openai/resources/embeddings.py", line 124, in create
return self._post(
^^^^^^^^^^^
File "/lib/python3.11/site-packages/openai/_base_client.py", line 1278, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/openai/_base_client.py", line 955, in request
return self._request(
^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/openai/_base_client.py", line 1059, in _request
raise self._make_status_error_from_response(err.response) from None
openai.UnprocessableEntityError: Error code: 422 - {'detail': [{'type': 'string_type', 'loc': ['body', 'text', 'input', 'list[constrained-str]', 0], 'msg': 'Input should be a valid string', 'input': [1985]}, {'type': 'string_type', 'loc': ['body', 'text', 'input', 'constrained-str'], 'msg': 'Input should be a valid string', 'input': [[1985]]}]}
Description
Unable to use OpenAIEmbeddings with a locally hosted embedding.
The following does work when using the client directly
embeddings_model.client.create(input="Your text goes here.",model="bge-embed-text-cpu")
CreateEmbeddingResponse(data=[Embedding(embedding=[-0.04428496211767197, -0.029685525223612785, 0.028833890333771706, -0.03357870876789093, -0.024697383865714073, -0.05158468335866928, 0.07737702131271362, 0.06959065794944763, 0.03966180980205536, -0.04136507585644722, -0.00024047252372838557, -0.028590567409992218, 0.016181044280529022, -0.011922874487936497, 0.02092586271464824.....
Also can confirm through openai directly.
from openai import OpenAI
Assumes port-forward of kubeai service to localhost:8000.
client = OpenAI(api_key="ignored", base_url="http://localhost:8000/openai/v1")
response = client.embeddings.create(
input="Your text goes here.",
model="bge-embed-text-cpu"
)
Any ideas?
System Info
langchain==0.3.11
langchain-community==0.3.11
langchain-core==0.3.24
langchain-google-community==2.0.2
langchain-google-vertexai==2.0.3
langchain-huggingface==0.1.2
langchain-openai==0.2.10
langchain-text-splitters==0.3.2
langgraph==0.2.53
langgraph-checkpoint==2.0.6
langgraph-sdk==0.1.36
langsmith==0.1.146