-
Notifications
You must be signed in to change notification settings - Fork 42
Description
There is incompatibility with OpenAIEmbeddings. If model is used from OpenRouter API instead OpenAI, it outputs embeddings, but embeddings.embed_documents expects response object to have field "data" (langchain_openai/embeddings/base.py, line 585: embeddings.extend(r["embedding"] for r in response["data"])But, OpenRouter model returns string object (does not have "data" field) and the code crushes.
from langchain_openai import OpenAIEmbeddings
Make sure your OpenRouter API key is set
os.environ["OPENAI_API_KEY"] = "your_openrouter_api_key_here"
os.environ["OPENAI_BASE_URL"] = "https://openrouter.ai/api/v1"
embeddings = OpenAIEmbeddings(
model="text-embedding-3-small", # OpenRouter-supported embedding model
api_key=os.environ["OPENAI_API_KEY"],
base_url=os.environ["OPENAI_BASE_URL"],
)
Embed all document chunks
mocked_input_texts = [doc.page_content for doc in texts]
vectors = embeddings.embed_documents(mocked_input_texts)
Hope this is OK place to put this issue. If not, please be free to move it elsewhere.