Skip to content

embeddings: default check_embedding_ctx_length=False for OpenAI-compa…#129

Open
kkampli-singlestore wants to merge 2 commits into
mainfrom
users/kaushik/embed-ctx-length-default
Open

embeddings: default check_embedding_ctx_length=False for OpenAI-compa…#129
kkampli-singlestore wants to merge 2 commits into
mainfrom
users/kaushik/embed-ctx-length-default

Conversation

@kkampli-singlestore

@kkampli-singlestore kkampli-singlestore commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

…tible endpoints

langchain OpenAIEmbeddings defaults to check_embedding_ctx_length=True, which tokenizes client-side with tiktoken and sends OpenAI token IDs. Non-OpenAI models behind an OpenAI-compatible endpoint (e.g. Qwen) can't interpret those IDs and return nonsensical embeddings. Default the flag to False so raw text is sent and the server tokenizes correctly. No-op for genuine OpenAI models; callers can opt back in with check_embedding_ctx_length=True. Scoped to the OpenAI path, so the Bedrock/Amazon branch is unaffected.


Note

Low Risk
Small, scoped default change on the OpenAI embeddings factory path; Bedrock is untouched and callers can restore the old behavior explicitly.

Overview
Fixes incorrect embeddings when using non-OpenAI models (e.g. Qwen) through SingleStore’s OpenAI-compatible inference URL via SingleStoreEmbeddingsFactory.

OpenAIEmbeddings is now created with check_embedding_ctx_length=False by default (callers can still pass check_embedding_ctx_length=True). That stops langchain’s client-side tiktoken path from sending OpenAI token IDs; the server receives raw text and tokenizes correctly. Genuine OpenAI models are unaffected. The change applies only to the OpenAI/Azure branch—Bedrock/Amazon construction is unchanged.

Reviewed by Cursor Bugbot for commit 799c99b. Bugbot is set up for automated code reviews on this repo. Configure here.

…tible endpoints

langchain OpenAIEmbeddings defaults to check_embedding_ctx_length=True, which
tokenizes client-side with tiktoken and sends OpenAI token IDs. Non-OpenAI models
behind an OpenAI-compatible endpoint (e.g. Qwen) can't interpret those IDs and
return nonsensical embeddings. Default the flag to False so raw text is sent and
the server tokenizes correctly. No-op for genuine OpenAI models; callers can opt
back in with check_embedding_ctx_length=True. Scoped to the OpenAI path, so the
Bedrock/Amazon branch is unaffected.

Co-authored-by: Cursor <cursoragent@cursor.com>
Only default check_embedding_ctx_length=False for self-hosted / non-OpenAI models
(e.g. Qwen on the 'Nova' platform). Genuine OpenAI/Azure models ('Azure'/'OpenAI')
keep langchain's default (True), preserving correct tiktoken tokenization and
client-side long-input chunking for them.

Co-authored-by: Cursor <cursoragent@cursor.com>

@mgiannakopoulos mgiannakopoulos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 Ship IT!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants