embeddings: default check_embedding_ctx_length=False for OpenAI-compa…#129
Open
kkampli-singlestore wants to merge 2 commits into
Open
embeddings: default check_embedding_ctx_length=False for OpenAI-compa…#129kkampli-singlestore wants to merge 2 commits into
kkampli-singlestore wants to merge 2 commits into
Conversation
…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>
kkampli-singlestore
requested review from
kesmit13,
mgiannakopoulos,
pmishchenko-ua and
volodymyr-memsql
as code owners
July 21, 2026 14:18
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>
volodymyr-memsql
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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.OpenAIEmbeddingsis now created withcheck_embedding_ctx_length=Falseby default (callers can still passcheck_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.